Skip to content

Commit 082c102

Browse files
committed
[Build] Use Java script instead of JavaScript to collect native sources
in order to replace ANT tasks with JavaScript (which require Java-11) in Jenkins pipeline. Stash native sources not-zipped to save the zip and unzip steps. Additionally 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. Furthermore move declaration of tools to the common Jenkins pipeline section to make them usable in all stages. Since #633 the JDK on the native-build-agent's PATH is not used anymore when building the native binaries and thus it is not required anymore to keep the PATH untouched. Part of - #513 - #626
1 parent 968c813 commit 082c102

File tree

10 files changed

+144
-155
lines changed

10 files changed

+144
-155
lines changed

Jenkinsfile

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ pipeline {
6464
agent {
6565
label 'centos-latest'
6666
}
67+
tools {
68+
jdk 'openjdk-jdk17-latest'
69+
maven 'apache-maven-latest'
70+
}
6771
environment {
6872
MAVEN_OPTS = "-Xmx4G"
6973
PR_VALIDATION_BUILD = "true"
@@ -129,16 +133,15 @@ pipeline {
129133
stages {
130134
stage("Collect SWT-native's sources") {
131135
steps {
132-
dir('eclipse.platform.swt/binaries'){
133-
withAnt(installation: 'apache-ant-latest', jdk: 'openjdk-jdk11-latest') { // nashorn javascript-engine required in ant-scripts
134-
sh '''
135-
pfSpec=(${PLATFORM//"."/ })
136-
ant -f binaries-parent/build.xml copy_library_src_and_create_zip -Dws=${pfSpec[0]} -Dos=${pfSpec[1]} -Darch=${pfSpec[2]}
137-
'''
138-
}
139-
dir("org.eclipse.swt.${PLATFORM}/tmpdir") {
140-
stash name:"swt.binaries.sources.${PLATFORM}", includes: "org.eclipse.swt.${PLATFORM}.master.zip"
141-
}
136+
dir('eclipse.platform.swt/bundles/org.eclipse.swt') {
137+
sh '''
138+
pfSpec=(${PLATFORM//"."/ })
139+
java -Dws=${pfSpec[0]} -Darch=${pfSpec[2]} build-scripts/CollectSources.java -nativeSources \
140+
"${WORKSPACE}/eclipse.platform.swt/binaries/org.eclipse.swt.${PLATFORM}/target/natives-build-temp"
141+
'''
142+
}
143+
dir("eclipse.platform.swt/binaries/org.eclipse.swt.${PLATFORM}/target/natives-build-temp") {
144+
stash(name:"swt.binaries.sources.${PLATFORM}")
142145
}
143146
}
144147
}
@@ -163,24 +166,17 @@ pipeline {
163166
dir('jdk.resources') {
164167
unstash "jdk.resources.${os}.${arch}"
165168
}
166-
// TODO: don't zip the sources and just (un)stash them unzipped! That safes the unzipping and removal of the the zip
167169
withEnv(['MODEL=' + arch, "OUTPUT_DIR=${WORKSPACE}/libs", "SWT_JAVA_HOME=${WORKSPACE}/jdk.resources"]) {
168170
if (isUnix()){
169171
sh '''
170-
unzip -aa org.eclipse.swt.${PLATFORM}.master.zip
171-
rm org.eclipse.swt.${PLATFORM}.master.zip
172172
mkdir libs
173-
174173
sh build.sh install
175174
ls -1R libs
176175
'''
177176
} else {
178177
withEnv(['PATH=C:\\tools\\cygwin\\bin;' + env.PATH]) {
179178
bat '''
180-
unzip org.eclipse.swt.%PLATFORM%.master.zip
181-
rm org.eclipse.swt.%PLATFORM%.master.zip
182179
mkdir libs
183-
184180
cmd /c build.bat x86_64 all install
185181
ls -1R libs
186182
'''
@@ -277,11 +273,6 @@ pipeline {
277273
}
278274
}
279275
stage('Build') {
280-
tools {
281-
// Define tools only in this stage to not interfere with default environemts of SWT-natives build-agents
282-
jdk 'openjdk-jdk17-latest'
283-
maven 'apache-maven-latest'
284-
}
285276
steps {
286277
xvnc(useXauthority: true) {
287278
dir('eclipse.platform.swt') {

binaries/pom.xml

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
<exists>META-INF/MANIFEST.MF</exists>
4949
</file>
5050
</activation>
51+
<properties>
52+
<swtMainProject>${project.basedir}/../../bundles/org.eclipse.swt</swtMainProject>
53+
</properties>
5154
<build>
5255
<plugins>
5356
<plugin>
@@ -104,7 +107,7 @@
104107
</goals>
105108
<configuration>
106109
<target> <!-- Read git qualifier of 'org.eclipse.swt' project. -->
107-
<loadfile property="swtBuildQualifier" srcFile="../../bundles/org.eclipse.swt/target/swtBuildQualifier.txt"/>
110+
<loadfile property="swtBuildQualifier" srcFile="${swtMainProject}/target/swtBuildQualifier.txt"/>
108111
</target>
109112
<exportAntProperties>true</exportAntProperties>
110113
</configuration>
@@ -123,19 +126,45 @@
123126
</configuration>
124127
</execution>
125128
<execution>
126-
<id>natives</id>
129+
<id>build-native-binaries</id>
127130
<phase>process-resources</phase>
128131
<goals>
129132
<goal>run</goal>
130133
</goals>
131134
<configuration>
132135
<target>
133136
<!-- See https://stackoverflow.com/a/53227117 and http://ant-contrib.sourceforge.net/tasks/tasks/index.html -->
134-
<taskdef resource="net/sf/antcontrib/antlib.xml" />
135-
<if>
136-
<equals arg1="${native}" arg2="${ws}.${os}.${arch}" />
137+
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
138+
<if><equals arg1="${native}" arg2="${ws}.${os}.${arch}"/>
137139
<then>
138-
<ant antfile="../binaries-parent/build.xml" target="build_libraries" />
140+
<property name="build_dir" value="${project.build.directory}/natives-build-temp"/>
141+
<exec executable="java" dir="${swtMainProject}" failonerror="true">
142+
<arg line="-Dws=${ws} build-scripts/CollectSources.java -nativeSources '${build_dir}'"/>
143+
</exec>
144+
<property name="SWT_JAVA_HOME" value="${java.home}"/><!-- Not overwritten if already set, e.g. as CLI argument -->
145+
<echo>Compile SWT natives against headers and libraries from JDK: ${SWT_JAVA_HOME}</echo>
146+
<if><equals arg1="${ws}" arg2="win32" />
147+
<then>
148+
<exec dir="${build_dir}" executable="${build_dir}/build.bat" failonerror="true">
149+
<env key="SWT_JAVA_HOME" value="${SWT_JAVA_HOME}"/>
150+
<env key="OUTPUT_DIR" value="${project.basedir}"/>
151+
<arg line="${targets}"/>
152+
<arg line="clean"/>
153+
</exec>
154+
</then>
155+
<else>
156+
<property name="gtk_version" value="3.0" />
157+
<exec dir="${build_dir}" executable="sh" failonerror="true">
158+
<arg line="build.sh"/>
159+
<env key="SWT_JAVA_HOME" value="${SWT_JAVA_HOME}"/>
160+
<env key="OUTPUT_DIR" value="${project.basedir}"/>
161+
<env key="GTK_VERSION" value="${gtk_version}"/>
162+
<env key="MODEL" value="${arch}"/>
163+
<arg line="${targets}"/>
164+
<arg line="clean"/>
165+
</exec>
166+
</else>
167+
</if>
139168
</then>
140169
</if>
141170
</target>
@@ -156,21 +185,11 @@
156185
</execution>
157186
</executions>
158187
<dependencies>
159-
<dependency>
160-
<groupId>org.mozilla</groupId>
161-
<artifactId>rhino-runtime</artifactId>
162-
<version>1.7.14</version>
163-
</dependency>
164188
<dependency>
165189
<groupId>org.apache.ant</groupId>
166190
<artifactId>ant</artifactId>
167191
<version>1.10.14</version>
168192
</dependency>
169-
<dependency>
170-
<groupId>org.apache.ant</groupId>
171-
<artifactId>ant-apache-bsf</artifactId>
172-
<version>1.10.14</version>
173-
</dependency>
174193
<dependency>
175194
<groupId>ant-contrib</groupId>
176195
<artifactId>ant-contrib</artifactId>

bundles/org.eclipse.swt/.classpath_cocoa_aarch64

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@
2929
<classpathentry kind="src" path="Eclipse SWT WebKit/cocoa"/>
3030
<classpathentry kind="src" path="Eclipse SWT OpenGL/cocoa"/>
3131
<classpathentry kind="src" path="Eclipse SWT OpenGL/common"/>
32+
<classpathentry kind="src" output="bin_build" path="build-scripts"/>
3233
<classpathentry kind="output" path="bin"/>
3334
</classpath>

bundles/org.eclipse.swt/.classpath_cocoa_x86_64

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@
2929
<classpathentry kind="src" path="Eclipse SWT WebKit/cocoa"/>
3030
<classpathentry kind="src" path="Eclipse SWT OpenGL/cocoa"/>
3131
<classpathentry kind="src" path="Eclipse SWT OpenGL/common"/>
32+
<classpathentry kind="src" output="bin_build" path="build-scripts"/>
3233
<classpathentry kind="output" path="bin"/>
3334
</classpath>

bundles/org.eclipse.swt/.classpath_gtk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
<classpathentry kind="src" path="Eclipse SWT OpenGL/glx"/>
3232
<classpathentry kind="src" path="Eclipse SWT OpenGL/common"/>
3333
<classpathentry kind="src" path="Eclipse SWT WebKit/gtk"/>
34+
<classpathentry kind="src" output="bin_build" path="build-scripts"/>
3435
<classpathentry kind="output" path="bin"/>
3536
</classpath>

bundles/org.eclipse.swt/.classpath_win32

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
<classpathentry kind="src" path="Eclipse SWT Browser/win32"/>
2626
<classpathentry kind="src" path="Eclipse SWT OpenGL/win32"/>
2727
<classpathentry kind="src" path="Eclipse SWT OpenGL/common"/>
28+
<classpathentry kind="src" output="bin_build" path="build-scripts"/>
2829
<classpathentry kind="output" path="bin"/>
2930
</classpath>

bundles/org.eclipse.swt/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
ws/
33
.build64/
44
.buildas/
5+
/bin_build/
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024, 2024 Hannes Wellmann and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Hannes Wellmann - initial API and implementation
13+
*******************************************************************************/
14+
import java.io.*;
15+
import java.nio.file.*;
16+
import java.util.*;
17+
18+
/**
19+
* Script to collect the SWT native sources for the specified native fragment.
20+
* <p>
21+
* In order to be able to launch this directly as source script <b>only
22+
* reference standard java classes!</b>
23+
* </p>
24+
*/
25+
public class CollectSources {
26+
27+
private record ScriptEnvironment(Path swtProjectRoot, Path targetDirectory, String ws, String arch) {
28+
private static ScriptEnvironment read(String[] args) {
29+
if (args.length != 2) {
30+
throw new IllegalArgumentException("task and target directory must be defined as only argument");
31+
}
32+
Path swtProjectRoot = Path.of("").toAbsolutePath();
33+
if (!swtProjectRoot.endsWith(Path.of("bundles/org.eclipse.swt"))) { // Consistency check
34+
throw new IllegalStateException("Sript must be excuted from org.eclipse.swt project");
35+
}
36+
Path targetDirectory = Path.of(args[1]);
37+
String ws = System.getProperty("ws");
38+
String arch = System.getProperty("arch");
39+
return new ScriptEnvironment(swtProjectRoot, targetDirectory, ws, arch);
40+
}
41+
}
42+
43+
public static void main(String[] args) throws Exception {
44+
ScriptEnvironment env = ScriptEnvironment.read(args);
45+
switch (args[0]) {
46+
case "-nativeSources":
47+
collectNativeSources(env);
48+
break;
49+
default:
50+
throw new IllegalArgumentException("Unexpected value: " + args[0]);
51+
}
52+
}
53+
54+
private static void collectNativeSources(ScriptEnvironment env) throws IOException {
55+
Path props = env.swtProjectRoot.resolve("nativeSourceFolders.properties");
56+
Map<String, String> sources = loadProperty(props);
57+
58+
String commonSources = sources.get("src_common");
59+
String nativeSources = sources.get("src_" + env.ws);
60+
List<String> allSources = Arrays.asList((commonSources + "," + nativeSources).split(","));
61+
System.out.println("Copy " + allSources.size() + " java source folders for " + env.ws + "." + env.arch);
62+
copySubDirectories(env.swtProjectRoot, allSources, env.targetDirectory);
63+
}
64+
65+
@SuppressWarnings({ "unchecked", "rawtypes" })
66+
private static Map<String, String> loadProperty(Path path) throws IOException {
67+
try (InputStream in = Files.newInputStream(path)) {
68+
Properties props = new Properties();
69+
props.load(in);
70+
return (Map) props;
71+
}
72+
}
73+
74+
private static void copySubDirectories(Path root, Collection<String> allSources, Path target) throws IOException {
75+
System.out.println("from " + root + "\nto " + target);
76+
for (String srcPath : allSources) {
77+
Path srcFolder = root.resolve(srcPath);
78+
try (var files = Files.walk(srcFolder).filter(Files::isRegularFile)) {
79+
for (Path sourceFile : (Iterable<Path>) files::iterator) {
80+
Path targetFile = target.resolve(srcFolder.relativize(sourceFile));
81+
Files.createDirectories(targetFile.getParent());
82+
Files.copy(sourceFile, targetFile, StandardCopyOption.REPLACE_EXISTING);
83+
}
84+
}
85+
}
86+
}
87+
}

0 commit comments

Comments
 (0)