Argeo Build can build itself
authorMathieu Baudier <mbaudier@argeo.org>
Sat, 18 Mar 2023 05:50:41 +0000 (06:50 +0100)
committerMathieu Baudier <mbaudier@argeo.org>
Sat, 18 Mar 2023 05:50:41 +0000 (06:50 +0100)
META-INF/MANIFEST.MF [deleted file]
Makefile [new file with mode: 0644]
branch.mk [new file with mode: 0644]
configure
osgi.mk
sdk/branches/unstable.bnd [new file with mode: 0644]
src/org/argeo/build/Make.java
src/org/argeo/build/Repackage.java

diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF
deleted file mode 100644 (file)
index f7026fe..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Automatic-Module-Name: argeo-build
-Bundle-Name: argeo-build
-Bundle-RequiredExecutionEnvironment: JavaSE-17
-Bundle-SymbolicName: argeo-build
-Bundle-Version: 2.3.4.next
-Import-Package: aQute.bnd.osgi,
- org.eclipse.jdt.core.compiler
-Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=17))"
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..5656b36
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,22 @@
+# WARNING: this Makefile is for Argeo Build to build itself
+# and is not meant to be included or used in regular builds
+include sdk.mk
+
+# Tells Make.java that we are our own Argeo Build
+export ARGEO_BUILD_CONFIG := .
+
+A2_CATEGORY = org.argeo.build
+
+BUNDLES = \
+org.argeo.build \
+
+DEP_CATEGORIES = \
+org.argeo.tp \
+org.argeo.tp.sdk \
+
+all: osgi
+# copy generated MANIFEST
+       cp org.argeo.build/META-INF/MANIFEST.MF META-INF/MANIFEST.MF
+       rm -rf org.argeo.build 
+
+include osgi.mk
\ No newline at end of file
diff --git a/branch.mk b/branch.mk
new file mode 100644 (file)
index 0000000..c040e63
--- /dev/null
+++ b/branch.mk
@@ -0,0 +1,3 @@
+# WARNING: this Makefile is for Argeo Build to build itself
+# and is not meant to be included or used in regular builds
+BRANCH=unstable
\ No newline at end of file
index e5031d7616aec131166349effffd5062559376c4..c92b6706c8cbc1755dd786c653bcc336a5745d71 100755 (executable)
--- a/configure
+++ b/configure
@@ -5,8 +5,12 @@ SDK_BUILD_BASE=$(pwd -P)/output
 
 if [ -z "$SDK_SRC_BASE" ]
 then
-SDK_SRC_BASE=$(pwd -P)
-echo "Script variable SDK_SRC_BASE not set, assuming Argeo Build is building itself and using the local directory"
+echo Script variable SDK_SRC_BASE must be set in the calling \'configure\' script,
+echo to the root location of the sources, typically with such a pattern:
+echo 'SDK_SRC_BASE="$(cd "$(dirname "$0")"; pwd -P)"' 
+echo "(see 'configure.template' from the argeo-build directory)"
+echo In order to build Argeo Build itself, explicitly set SDK_SRC_BASE as an environment variable
+exit 1
 fi
 
 SDK_MK=$SDK_SRC_BASE/sdk.mk
diff --git a/osgi.mk b/osgi.mk
index 2d06f566f7f03c258e3bf9a5bd7f3b41a96c0c99..85ad3c40e9935264da4acb8f02e9ead797d2dd56 100644 (file)
--- a/osgi.mk
+++ b/osgi.mk
@@ -73,6 +73,9 @@ ifneq ($(NO_MANIFEST_COPY),true)
        @cp $< $@
 endif
 
+clean:
+       rm -rf $(BUILD_BASE)
+
 clean-manifests :
        @rm -rf $(foreach bundle, $(BUNDLES), $(bundle)/META-INF/MANIFEST.MF);
 
diff --git a/sdk/branches/unstable.bnd b/sdk/branches/unstable.bnd
new file mode 100644 (file)
index 0000000..c0d2c5f
--- /dev/null
@@ -0,0 +1,6 @@
+major=2
+minor=3
+micro=5
+qualifier=.next
+
+SPDX-License-Identifier=CC0-1.0
\ No newline at end of file
index b2fb7d24807de1081cbe463baddb6adf0a2abe3f..78310597c15a4982f03dccbaa2b2ecf35965adb2 100644 (file)
@@ -3,6 +3,7 @@ package org.argeo.build;
 import static java.lang.System.Logger.Level.DEBUG;
 import static java.lang.System.Logger.Level.ERROR;
 import static java.lang.System.Logger.Level.INFO;
+import static java.lang.System.Logger.Level.WARNING;
 
 import java.io.File;
 import java.io.IOException;
@@ -55,11 +56,18 @@ public class Make {
        private final static Logger logger = System.getLogger(Make.class.getName());
 
        /**
-        * Environment properties on whether sources should be packaged separately or
+        * Environment variable on whether sources should be packaged separately or
         * integrated in the bundles.
         */
        private final static String ENV_SOURCE_BUNDLES = "SOURCE_BUNDLES";
 
+       /**
+        * Environment variable to override the default location for the Argeo Build
+        * configuration files. Typically used if Argeo Build has been compiled and
+        * packaged separately.
+        */
+       private final static String ENV_ARGEO_BUILD_CONFIG = "ARGEO_BUILD_CONFIG";
+
        /** Name of the local-specific Makefile (sdk.mk). */
        final static String SDK_MK = "sdk.mk";
        /** Name of the branch definition Makefile (branch.mk). */
@@ -100,7 +108,19 @@ public class Make {
                sdkSrcBase = Paths.get(context.computeIfAbsent("SDK_SRC_BASE", (key) -> {
                        throw new IllegalStateException(key + " not found");
                })).toAbsolutePath();
-               argeoBuildBase = sdkSrcBase.resolve("sdk/argeo-build");
+
+               Path argeoBuildBaseT = sdkSrcBase.resolve("sdk/argeo-build");
+               if (!Files.exists(argeoBuildBaseT)) {
+                       String fromEnv = System.getenv(ENV_ARGEO_BUILD_CONFIG);
+                       if (fromEnv != null)
+                               argeoBuildBaseT = Paths.get(fromEnv);
+                       if (fromEnv == null || !Files.exists(argeoBuildBaseT)) {
+                               throw new IllegalStateException(
+                                               "Argeo Build not found. Did you initialise the git submodules or set the "
+                                                               + ENV_ARGEO_BUILD_CONFIG + " environment variable?");
+                       }
+               }
+               argeoBuildBase = argeoBuildBaseT;
 
                sdkBuildBase = Paths.get(context.computeIfAbsent("SDK_BUILD_BASE", (key) -> {
                        throw new IllegalStateException(key + " not found");
@@ -183,8 +203,14 @@ public class Make {
                for (String bundle : bundles) {
                        StringBuilder sb = new StringBuilder();
                        Path bundlePath = execDirectory.resolve(bundle);
-                       if (!Files.exists(bundlePath))
-                               throw new IllegalArgumentException("Bundle " + bundle + " not found in " + execDirectory);
+                       if (!Files.exists(bundlePath)) {
+                               if (bundles.size() == 1) {
+                                       logger.log(WARNING, "Bundle " + bundle + " not found in " + execDirectory
+                                                       + ", assuming this is this directory, as only one bundle was requested.");
+                                       bundlePath = execDirectory;
+                               } else
+                                       throw new IllegalArgumentException("Bundle " + bundle + " not found in " + execDirectory);
+                       }
                        sb.append(bundlePath.resolve("src"));
                        sb.append("[-d");
                        compilerArgs.add(sb.toString());
@@ -250,12 +276,17 @@ public class Make {
                logger.log(INFO, "Packaging took " + duration + " ms");
        }
 
-       /*
-        * UTILITIES
-        */
        /** Package a single bundle. */
        void createBundle(String branch, String bundle, String category) throws IOException {
-               Path source = execDirectory.resolve(bundle);
+               final Path source;
+               if (!Files.exists(execDirectory.resolve(bundle))) {
+                       logger.log(WARNING,
+                                       "Bundle " + bundle + " not found in " + execDirectory + ", assuming this is this directory.");
+                       source = execDirectory;
+               } else {
+                       source = execDirectory.resolve(bundle);
+               }
+
                Path compiled = buildBase.resolve(bundle);
                String bundleSymbolicName = source.getFileName().toString();
 
@@ -402,6 +433,10 @@ public class Make {
                }
        }
 
+       /*
+        * UTILITIES
+        */
+       /** Add sources to a jar file */
        void copySourcesToJar(Path srcP, JarOutputStream srcJarOut, String prefix) throws IOException {
                Files.walkFileTree(srcP, new SimpleFileVisitor<Path>() {
                        @Override
index 1d280e6984e032a008b5e263f39e1306e22075bc..05ff7b177616cd4e01118d3c32e15aea9a717b4a 100644 (file)
@@ -59,7 +59,7 @@ public class Repackage {
        private final static Logger logger = System.getLogger(Repackage.class.getName());
 
        /**
-        * Environment properties on whether sources should be packaged separately or
+        * Environment variable on whether sources should be packaged separately or
         * integrated in the bundles.
         */
        private final static String ENV_SOURCE_BUNDLES = "SOURCE_BUNDLES";
@@ -1045,7 +1045,7 @@ public class Repackage {
                // JAVA
                AUTOMATIC_MODULE_NAME("Automatic-Module-Name"), //
                // SLC
-               SLC_CATEGORY("SLC-Category"), //
+//             SLC_CATEGORY("SLC-Category"), //
                SLC_ORIGIN_M2("SLC-Origin-M2"), //
                SLC_ORIGIN_M2_MERGE("SLC-Origin-M2-Merge"), //
                SLC_ORIGIN_M2_REPO("SLC-Origin-M2-Repo"), //