Properly deploy OS-specific jars
authorMathieu Baudier <mbaudier@argeo.org>
Wed, 6 Mar 2024 10:26:18 +0000 (11:26 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Wed, 6 Mar 2024 10:26:18 +0000 (11:26 +0100)
common.mk
jni.mk
osgi.mk
repackage.mk
src/org/argeo/build/Make.java

index 95813d453d585a2350c22ed3bf9fd35137274577..c30d011faa8fc4750b69e07e29c33ce68cf83f68 100644 (file)
--- a/common.mk
+++ b/common.mk
@@ -32,13 +32,15 @@ KNOWN_ARCHS ?= x86_64 aarch64
 TARGET_OS ?= linux
 TARGET_ARCH ?= $(shell uname -m)
 
-TARGET_OS_CATEGORY_PREFIX=lib/linux
+TARGET_OS_CATEGORY_PREFIX=lib/$(TARGET_OS)
 TARGET_ARCH_CATEGORY_PREFIX=$(TARGET_OS_CATEGORY_PREFIX)/$(TARGET_ARCH)
 PORTABLE_CATEGORIES=$(filter-out lib/%, $(CATEGORIES))
 ARCH_CATEGORIES=$(filter $(TARGET_ARCH_CATEGORY_PREFIX)/%, $(CATEGORIES))
 OS_CATEGORIES=$(filter-out $(foreach arch, $(KNOWN_ARCHS), $(TARGET_OS_CATEGORY_PREFIX)/$(arch)/%), $(filter $(TARGET_OS_CATEGORY_PREFIX)/%, $(CATEGORIES)))
 
 # Utilities
+INSTALL=install -m644 -D --target-directory
+
 # Make variables used to replace spaces by a separator, typically in order to generate classpaths
 # for example: CLASSPATH = $(subst $(space),$(pathsep),$(strip $(JARS)))
 null  :=
diff --git a/jni.mk b/jni.mk
index 5e863d5e4a56a477cbd936646fb5f211f1edd720..98ad5c8b9c4c2631975d5acd1e654f09367cf78c 100644 (file)
--- a/jni.mk
+++ b/jni.mk
@@ -36,7 +36,7 @@ clean:
        $(RM) $(A2_NATIVE_CATEGORY)/$(TARGET_EXEC)
 
 install:
-       install -D -m644 $(A2_NATIVE_CATEGORY)/$(TARGET_EXEC) $(A2_NATIVE_INSTALL_TARGET)
+       $(INSTALL) $(A2_NATIVE_INSTALL_TARGET) $(A2_NATIVE_CATEGORY)/$(TARGET_EXEC)
 
 uninstall:
        $(RM) $(A2_NATIVE_INSTALL_TARGET)/$(TARGET_EXEC)
diff --git a/osgi.mk b/osgi.mk
index 5a1d3e8967004e8c6973c96feead2f09b1007a0a..334714bf6ad9f6d37ac2c39edfda1ede82e5389e 100644 (file)
--- a/osgi.mk
+++ b/osgi.mk
@@ -80,12 +80,14 @@ osgi-clean: jni-clean
 osgi-install: jni-install
        $(ARGEO_MAKE) \
         install --category $(A2_CATEGORY) --bundles $(BUNDLES) \
-        --target $(A2_INSTALL_TARGET)
+        --target $(A2_INSTALL_TARGET) \
+        --os $(TARGET_OS) --target-native $(A2_NATIVE_INSTALL_TARGET)
 
 osgi-uninstall: jni-uninstall
        $(ARGEO_MAKE) \
         uninstall --category $(A2_CATEGORY) --bundles $(BUNDLES) \
-        --target $(A2_INSTALL_TARGET)
+        --target $(A2_INSTALL_TARGET) \
+        --os $(TARGET_OS) --target-native $(A2_NATIVE_INSTALL_TARGET)
 
 jni-all: 
        $(foreach dir, $(JNIDIRS), $(MAKE) -C $(dir) all;)
index 01c099363930d1ac8f9c0484f51b20dbdd8f8122..6f2a97dc751b4d5a3f7bd29d2586db7f9bc1afac 100644 (file)
@@ -15,7 +15,6 @@ ARGEO_REPACKAGE = $(JVM) -cp $(LOGGER_JAR):$(BNDLIB_JAR) $(ARGEO_BUILD_BASE)src/
 TODOS_REPACKAGE = $(foreach category, $(CATEGORIES),$(BUILD_BASE)/$(category)/to-repackage) 
 BUILD_BASE = $(SDK_BUILD_BASE)/$(shell basename $(SDK_SRC_BASE))
 REPACKAGED_CATEGORIES = $(foreach category, $(CATEGORIES),$(A2_OUTPUT)/$(category))
-INSTALL=install -m644 -D --target-directory
 
 all: $(BUILD_BASE)/repackaged 
 
index 376a66db42e01abd4990bc515e1850d29f40be99..71976c00188d70cdff9125efb6912865fcf610f2 100644 (file)
@@ -314,23 +314,18 @@ public class Make {
 
        /** Install or uninstall bundles and native output. */
        void install(Map<String, List<String>> options, boolean uninstall) throws IOException {
+               final String LIB_ = "lib/";
+               final String NATIVE_ = "native/";
+
                // check arguments
-               List<String> bundles = options.get("--bundles");
-               Objects.requireNonNull(bundles, "--bundles argument must be set");
+               List<String> bundles = multiArg(options, "--bundles", true);
                if (bundles.isEmpty())
                        return;
-
-               List<String> categories = options.get("--category");
-               Objects.requireNonNull(categories, "--category argument must be set");
-               if (categories.size() != 1)
-                       throw new IllegalArgumentException("One and only one --category must be specified");
-               String category = categories.get(0);
-
-               List<String> targetDirs = options.get("--target");
-               Objects.requireNonNull(targetDirs, "--target argument must be set");
-               if (targetDirs.size() != 1)
-                       throw new IllegalArgumentException("Only one --target must be specified");
-               Path targetA2 = Paths.get(targetDirs.get(0));
+               String category = singleArg(options, "--category", true);
+               Path targetA2 = Paths.get(singleArg(options, "--target", true));
+               String nativeTargetArg = singleArg(options, "--target-native", false);
+               Path nativeTargetA2 = nativeTargetArg != null ? Paths.get(nativeTargetArg) : null;
+               String targetOs = singleArg(options, "--os", nativeTargetArg != null);
                logger.log(INFO, (uninstall ? "Uninstalling bundles from " : "Installing bundles to ") + targetA2);
 
                final String branch;
@@ -354,14 +349,28 @@ public class Make {
                Objects.requireNonNull(minor, "'minor' must be set");
 
                int count = 0;
-               for (String bundle : bundles) {
+               bundles: for (String bundle : bundles) {
                        Path bundlePath = Paths.get(bundle);
                        Path bundleParent = bundlePath.getParent();
                        Path a2JarDirectory = bundleParent != null ? a2Output.resolve(bundleParent).resolve(category)
                                        : a2Output.resolve(category);
                        Path jarP = a2JarDirectory.resolve(bundlePath.getFileName() + "." + major + "." + minor + ".jar");
 
-                       Path targetJarP = targetA2.resolve(a2Output.relativize(jarP));
+                       Path targetJarP;
+                       if (bundle.startsWith(LIB_)) {// OS-specific
+                               Objects.requireNonNull(nativeTargetA2);
+                               if (bundle.startsWith(LIB_ + NATIVE_) // portable native
+                                               || bundle.startsWith(LIB_ + targetOs + "/" + NATIVE_)) {// OS-specific native
+                                       targetJarP = nativeTargetA2.resolve(category).resolve(jarP.getFileName());
+                               } else if (bundle.startsWith(LIB_ + targetOs)) {// OS-specific portable
+                                       targetJarP = targetA2.resolve(category).resolve(jarP.getFileName());
+                               } else { // ignore other OS
+                                       continue bundles;
+                               }
+                       } else {
+                               targetJarP = targetA2.resolve(a2Output.relativize(jarP));
+                       }
+
                        if (uninstall) { // uninstall
                                if (Files.exists(targetJarP)) {
                                        Files.delete(targetJarP);
@@ -381,6 +390,27 @@ public class Make {
                logger.log(INFO, uninstall ? count + " bundles removed" : count + " bundles installed or updated");
        }
 
+       /** Extracts an argument which must be unique. */
+       String singleArg(Map<String, List<String>> options, String arg, boolean mandatory) {
+               List<String> values = options.get(arg);
+               if (values == null || values.size() == 0)
+                       if (mandatory)
+                               throw new IllegalArgumentException(arg + " argument must be set");
+                       else
+                               return null;
+               if (values.size() != 1)
+                       throw new IllegalArgumentException("One and only one " + arg + " arguments must be specified");
+               return values.get(0);
+       }
+
+       /** Extracts an argument which can have multiple values. */
+       List<String> multiArg(Map<String, List<String>> options, String arg, boolean mandatory) {
+               List<String> values = options.get(arg);
+               if (mandatory && values == null)
+                       throw new IllegalArgumentException(arg + " argument must be set");
+               return values != null ? values : new ArrayList<>();
+       }
+
        /** Delete empty parent directory up to the A2 target (included). */
        void deleteEmptyParents(Path targetA2, Path targetParent) throws IOException {
                if (!Files.isDirectory(targetParent))