From 822c389ec76d0be72ef0fc59d53a3d23737f2102 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Wed, 6 Mar 2024 11:26:18 +0100 Subject: [PATCH] Properly deploy OS-specific jars --- common.mk | 4 ++- jni.mk | 2 +- osgi.mk | 6 ++-- repackage.mk | 1 - src/org/argeo/build/Make.java | 62 ++++++++++++++++++++++++++--------- 5 files changed, 54 insertions(+), 21 deletions(-) diff --git a/common.mk b/common.mk index 95813d4..c30d011 100644 --- 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 5e863d5..98ad5c8 100644 --- 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 5a1d3e8..334714b 100644 --- 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;) diff --git a/repackage.mk b/repackage.mk index 01c0993..6f2a97d 100644 --- a/repackage.mk +++ b/repackage.mk @@ -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 diff --git a/src/org/argeo/build/Make.java b/src/org/argeo/build/Make.java index 376a66d..71976c0 100644 --- a/src/org/argeo/build/Make.java +++ b/src/org/argeo/build/Make.java @@ -314,23 +314,18 @@ public class Make { /** Install or uninstall bundles and native output. */ void install(Map> options, boolean uninstall) throws IOException { + final String LIB_ = "lib/"; + final String NATIVE_ = "native/"; + // check arguments - List bundles = options.get("--bundles"); - Objects.requireNonNull(bundles, "--bundles argument must be set"); + List bundles = multiArg(options, "--bundles", true); if (bundles.isEmpty()) return; - - List 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 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> options, String arg, boolean mandatory) { + List 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 multiArg(Map> options, String arg, boolean mandatory) { + List 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)) -- 2.30.2