From 4e2b7d01ec0bd26f83c24fa9ccb8c475e9755098 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Wed, 5 Apr 2023 00:49:02 +0200 Subject: [PATCH] [Build] Use Java script instead of JavaScript to collect native sources to replace ANT tasks with JavaScript in Jenkins pipeline. And stash native sources not-zipped to save the zip and unzip steps. Furthermore move all remaining ANT tasks to run a native build in a local Maven for the running platform completely to the maven-antrun-plugin configuration. Part of - https://github.com/eclipse-platform/eclipse.platform.swt/issues/513 - https://github.com/eclipse-platform/eclipse.platform.swt/issues/626 --- Jenkinsfile | 31 +++-- binaries/pom.xml | 54 +++++--- .../org.eclipse.swt/.classpath_cocoa_aarch64 | 1 + .../org.eclipse.swt/.classpath_cocoa_x86_64 | 1 + bundles/org.eclipse.swt/.classpath_gtk | 1 + bundles/org.eclipse.swt/.classpath_win32 | 1 + bundles/org.eclipse.swt/.gitignore | 1 + .../build-scripts/CollectSources.java | 87 +++++++++++++ bundles/org.eclipse.swt/buildSWT.xml | 117 ------------------ .../nativeSourceFolders.properties | 4 + 10 files changed, 148 insertions(+), 150 deletions(-) create mode 100644 bundles/org.eclipse.swt/build-scripts/CollectSources.java create mode 100644 bundles/org.eclipse.swt/nativeSourceFolders.properties diff --git a/Jenkinsfile b/Jenkinsfile index ac0d9df62ff..950bc0f5acd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -64,6 +64,7 @@ pipeline { agent { label 'centos-latest' } + // Define tools only in this stage to not interfere with default environemts of SWT-natives build-agents environment { MAVEN_OPTS = "-Xmx4G" PR_VALIDATION_BUILD = "true" @@ -128,17 +129,19 @@ pipeline { } stages { stage("Collect SWT-native's sources") { + tools { + jdk 'openjdk-jdk17-latest' + } steps { - dir('eclipse.platform.swt/binaries'){ - withAnt(installation: 'apache-ant-latest', jdk: 'openjdk-jdk11-latest') { // nashorn javascript-engine required in ant-scripts - sh ''' - pfSpec=(${PLATFORM//"."/ }) - ant -f binaries-parent/build.xml copy_library_src_and_create_zip -Dws=${pfSpec[0]} -Dos=${pfSpec[1]} -Darch=${pfSpec[2]} - ''' - } - dir("org.eclipse.swt.${PLATFORM}/tmpdir") { - stash name:"swt.binaries.sources.${PLATFORM}", includes: "org.eclipse.swt.${PLATFORM}.master.zip" - } + dir('eclipse.platform.swt/bundles/org.eclipse.swt') { + sh ''' + pfSpec=(${PLATFORM//"."/ }) + nativeBuildDir='${WORKSPACE}/eclipse.platform.swt/binaries/org.eclipse.swt.${PLATFORM}/target/natives-build-temp' + java -Dws=${pfSpec[0]} -Darch=${pfSpec[2]} build-scripts/CollectSources.java -nativeSources '${nativeBuildDir}' + ''' + } + dir("eclipse.platform.swt/binaries/org.eclipse.swt.${PLATFORM}/target/natives-build-temp") { + stash(name:"swt.binaries.sources.${PLATFORM}") } } } @@ -167,20 +170,15 @@ pipeline { withEnv(['MODEL=' + arch, "OUTPUT_DIR=${WORKSPACE}/libs", "SWT_JAVA_HOME=${WORKSPACE}/jdk.resources"]) { if (isUnix()){ sh ''' - unzip -aa org.eclipse.swt.${PLATFORM}.master.zip - rm org.eclipse.swt.${PLATFORM}.master.zip mkdir libs - sh build.sh install ls -1R libs ''' } else { + //TODO: check if we can use sh here as well? or at least remove the env? withEnv(['PATH=C:\\tools\\cygwin\\bin;' + env.PATH]) { bat ''' - unzip org.eclipse.swt.%PLATFORM%.master.zip - rm org.eclipse.swt.%PLATFORM%.master.zip mkdir libs - cmd /c build.bat x86_64 all install ls -1R libs ''' @@ -278,7 +276,6 @@ pipeline { } stage('Build') { tools { - // Define tools only in this stage to not interfere with default environemts of SWT-natives build-agents jdk 'openjdk-jdk17-latest' maven 'apache-maven-latest' } diff --git a/binaries/pom.xml b/binaries/pom.xml index 25976485e6d..9df83152355 100644 --- a/binaries/pom.xml +++ b/binaries/pom.xml @@ -48,6 +48,9 @@ META-INF/MANIFEST.MF + + ${project.basedir}/../../bundles/org.eclipse.swt + @@ -104,7 +107,7 @@ - + true @@ -123,7 +126,7 @@ - natives + build-native-binaries process-resources run @@ -131,11 +134,40 @@ - - - + + - + + + + + + + + + Compile SWT natives against headers and libraries from JDK: ${SWT_JAVA_HOME} + + + + + + + + + + + + + + + + + + + + + + @@ -156,21 +188,11 @@ - - org.mozilla - rhino-runtime - 1.7.14 - org.apache.ant ant 1.10.14 - - org.apache.ant - ant-apache-bsf - 1.10.14 - ant-contrib ant-contrib diff --git a/bundles/org.eclipse.swt/.classpath_cocoa_aarch64 b/bundles/org.eclipse.swt/.classpath_cocoa_aarch64 index 7c7600d7a27..07440032859 100644 --- a/bundles/org.eclipse.swt/.classpath_cocoa_aarch64 +++ b/bundles/org.eclipse.swt/.classpath_cocoa_aarch64 @@ -29,5 +29,6 @@ + diff --git a/bundles/org.eclipse.swt/.classpath_cocoa_x86_64 b/bundles/org.eclipse.swt/.classpath_cocoa_x86_64 index c8f0d514f52..b323077f02b 100644 --- a/bundles/org.eclipse.swt/.classpath_cocoa_x86_64 +++ b/bundles/org.eclipse.swt/.classpath_cocoa_x86_64 @@ -29,5 +29,6 @@ + diff --git a/bundles/org.eclipse.swt/.classpath_gtk b/bundles/org.eclipse.swt/.classpath_gtk index e03c73d099c..b83802978e0 100644 --- a/bundles/org.eclipse.swt/.classpath_gtk +++ b/bundles/org.eclipse.swt/.classpath_gtk @@ -31,5 +31,6 @@ + diff --git a/bundles/org.eclipse.swt/.classpath_win32 b/bundles/org.eclipse.swt/.classpath_win32 index 2edde625d7f..4cf3f176dbc 100644 --- a/bundles/org.eclipse.swt/.classpath_win32 +++ b/bundles/org.eclipse.swt/.classpath_win32 @@ -25,5 +25,6 @@ + diff --git a/bundles/org.eclipse.swt/.gitignore b/bundles/org.eclipse.swt/.gitignore index 8623d47ef51..867253bf3c8 100644 --- a/bundles/org.eclipse.swt/.gitignore +++ b/bundles/org.eclipse.swt/.gitignore @@ -2,3 +2,4 @@ ws/ .build64/ .buildas/ +/bin_build/ diff --git a/bundles/org.eclipse.swt/build-scripts/CollectSources.java b/bundles/org.eclipse.swt/build-scripts/CollectSources.java new file mode 100644 index 00000000000..33c78b5049d --- /dev/null +++ b/bundles/org.eclipse.swt/build-scripts/CollectSources.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2024, 2024 Hannes Wellmann and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Hannes Wellmann - initial API and implementation + *******************************************************************************/ +import java.io.*; +import java.nio.file.*; +import java.util.*; + +/** + * Script to collect the SWT native sources for the specified native fragment. + *

+ * In order to be able to launch this directly as source script only + * reference standard java classes! + *

+ */ +public class CollectSources { + + private record ScriptEnvironment(Path swtProjectRoot, Path targetDirectory, String ws, String arch) { + private static ScriptEnvironment read(String[] args) { + if (args.length != 2) { + throw new IllegalArgumentException("task and target directory must be defined as only argument"); + } + Path swtProjectRoot = Path.of("").toAbsolutePath(); + if (!swtProjectRoot.endsWith(Path.of("bundles/org.eclipse.swt"))) { // Consistency check + throw new IllegalStateException("Sript must be excuted from org.eclipse.swt project"); + } + Path targetDirectory = Path.of(args[1]); + String ws = System.getProperty("ws"); + String arch = System.getProperty("arch"); + return new ScriptEnvironment(swtProjectRoot, targetDirectory, ws, arch); + } + } + + public static void main(String[] args) throws Exception { + ScriptEnvironment env = ScriptEnvironment.read(args); + switch (args[0]) { + case "-nativeSources": + collectNativeSources(env); + break; + default: + throw new IllegalArgumentException("Unexpected value: " + args[0]); + } + } + + private static void collectNativeSources(ScriptEnvironment env) throws IOException { + Path props = env.swtProjectRoot.resolve("nativeSourceFolders.properties"); + Map sources = loadProperty(props); + + String commonSources = sources.get("src_common"); + String nativeSources = sources.get("src_" + env.ws); + List allSources = Arrays.asList((commonSources + "," + nativeSources).split(",")); + System.out.println("Copy " + allSources.size() + " java source folders for " + env.ws + "." + env.arch); + copySubDirectories(env.swtProjectRoot, allSources, env.targetDirectory); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + private static Map loadProperty(Path path) throws IOException { + try (InputStream in = Files.newInputStream(path)) { + Properties props = new Properties(); + props.load(in); + return (Map) props; + } + } + + private static void copySubDirectories(Path root, Collection allSources, Path target) throws IOException { + System.out.println("from " + root + "\nto " + target); + for (String srcPath : allSources) { + Path srcFolder = root.resolve(srcPath); + try (var files = Files.walk(srcFolder).filter(Files::isRegularFile)) { + for (Path sourceFile : (Iterable) files::iterator) { + Path targetFile = target.resolve(srcFolder.relativize(sourceFile)); + Files.createDirectories(targetFile.getParent()); + Files.copy(sourceFile, targetFile, StandardCopyOption.REPLACE_EXISTING); + } + } + } + } +} diff --git a/bundles/org.eclipse.swt/buildSWT.xml b/bundles/org.eclipse.swt/buildSWT.xml index 4042af73fdf..9ddced45955 100644 --- a/bundles/org.eclipse.swt/buildSWT.xml +++ b/bundles/org.eclipse.swt/buildSWT.xml @@ -25,8 +25,6 @@ revision in the swp.map. for Example: ant -f buildSWT.xml increment_version -Dnatives_changed=true - To build the libraries of a fragment, run - ant -f /build.xml build_libraries --> @@ -213,25 +211,6 @@ - - - - - - - - - - - - - - - @@ -297,87 +276,6 @@ - - - - - - - refreshing ${fragment} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Compile SWT natives against headers and libraries from JDK: ${SWT_JAVA_HOME} - - - - - - - - - - - - - - - - - Compile SWT natives against headers and libraries from JDK: ${SWT_JAVA_HOME} - - - - - - - - @@ -401,20 +299,5 @@ "Creating file ${fileName}" true - - - - - - - - - - - - - - - diff --git a/bundles/org.eclipse.swt/nativeSourceFolders.properties b/bundles/org.eclipse.swt/nativeSourceFolders.properties new file mode 100644 index 00000000000..6a93bdb27bd --- /dev/null +++ b/bundles/org.eclipse.swt/nativeSourceFolders.properties @@ -0,0 +1,4 @@ +src_common=Eclipse SWT/common/library,Eclipse SWT PI/common/library +src_win32=Eclipse SWT PI/win32/library,Eclipse SWT AWT/win32/library,Eclipse SWT OpenGL/win32/library +src_gtk=Eclipse SWT PI/gtk/library,Eclipse SWT AWT/gtk/library,Eclipse SWT OpenGL/glx/library,Eclipse SWT PI/cairo/library,Eclipse SWT WebKit/gtk/library +src_cocoa=Eclipse SWT PI/cocoa/library,Eclipse SWT AWT/cocoa/library