Skip to content

Commit 89291e3

Browse files
committed
[Build] Rename library files if native sources of platform are unchanged
Rust rename the SWT native binary files for unchanged platforms to the new version and only build those whose native sources really changed. Avoiding a rebuild of effectively unchanged binaries has multiple advantages, if only a sub-set of all supported platforms is build: - reduced build times - reduced occupation of precious native agents in Jenkins - increased stability of the build because if a native build-agent for a skipped platforms is unavailable the build isn't blocked. - reduced future growth of the git large-file storage occupation as renaming a binary file has basically zero-cost, while a modified binary (even if just slightly) will add the entire file again.
1 parent 1989d41 commit 89291e3

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

Jenkinsfile

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def runOnNativeBuildAgent(String platform, Closure body) {
4242
}
4343
}
4444

45-
/** Returns the download URL of the JDK against whoose C headers (in the 'include/' folder) and native libraries the SWT natives are compiled.*/
46-
def getNativeJdkUrl(String os, String arch){ // To update the used JDK version update the URL template below
45+
/** Returns the download URL of the JDK against whose C headers (in the 'include/' folder) and native libraries the SWT natives are compiled.*/
46+
def getNativeJdkUrl(String os, String arch) { // To update the used JDK version update the URL template below
4747
if('win32'.equals(os) && 'aarch64'.equals(arch)) {
4848
// Temporary workaround until there are official Temurin GA releases for Windows on ARM that can be consumed through JustJ
4949
dir("${WORKSPACE}/repackage-win32.aarch64-jdk") {
@@ -82,7 +82,7 @@ def getSWTVersions() { // must be called from the repository root
8282
return props
8383
}
8484

85-
boolean NATIVES_CHANGED = false
85+
def Set NATIVES_CHANGED = []
8686

8787
pipeline {
8888
options {
@@ -103,7 +103,9 @@ pipeline {
103103
PR_VALIDATION_BUILD = "true"
104104
}
105105
parameters {
106-
booleanParam(name: 'forceNativeBuilds', defaultValue: false, description: 'Forces to run the native builds of swt\'s binaries. Will push the built binaries to the master branch, unless \'skipCommit\' is set. Useful in debugging.')
106+
booleanParam(name: 'forceNativeBuilds-cocoa', defaultValue: false, description: 'Enforce a re-build of SWT\'s native binaries for Mac OS X. Will push the built binaries to the master branch, unless \'skipCommit\' is set.')
107+
booleanParam(name: 'forceNativeBuilds-gtk', defaultValue: false, description: 'Enforce a re-build of SWT\'s native binaries for Linux. Will push the built binaries to the master branch, unless \'skipCommit\' is set.')
108+
booleanParam(name: 'forceNativeBuilds-win32', defaultValue: false, description: 'Enforce a re-build of SWT\'s native binaries for Windows. Will push the built binaries to the master branch, unless \'skipCommit\' is set.')
107109
booleanParam(name: 'skipCommit', defaultValue: false, description: 'Stops committing to swt and swt binaries repo at the end. Useful in debugging.')
108110
}
109111
stages {
@@ -141,9 +143,10 @@ pipeline {
141143
git config --global user.name 'Eclipse Releng Bot'
142144
'''
143145
script {
146+
def allWS = ['cocoa', 'gtk', 'win32']
147+
def libraryFilePattern = [ 'cocoa' : 'libswt-*.jnilib', 'gtk' : 'libswt-*.so', 'win32' : 'swt-*.dll' ]
144148
def swtTag = getLatestGitTag()
145149
echo "Current tag=${swtTag}."
146-
boolean nativesChanged = false
147150
dir('bundles/org.eclipse.swt') {
148151
// Verify preprocessing is completed
149152
sh '''
@@ -154,28 +157,42 @@ pipeline {
154157
'''
155158
def sourceFoldersProps = readProperties(file: 'nativeSourceFolders.properties')
156159
def sources = sourceFoldersProps.collectEntries{ k, src -> [ k, src.split(',').collect{ f -> '\'' + f + '\''}.join(' ') ] }
157-
def diff = sh(script: "git diff HEAD ${swtTag} ${sources.values().join(' ')}", returnStdout: true)
158-
nativesChanged = !diff.strip().isEmpty()
159-
echo "Natives changed since ${swtTag}: ${nativesChanged}"
160+
for(ws in allWS) {
161+
def diff = sh(script: "git diff HEAD ${swtTag} ${sources.src_common} ${sources['src_' + ws]}", returnStdout: true)
162+
if (!diff.strip().isEmpty()) {
163+
NATIVES_CHANGED += ws
164+
}
165+
}
166+
echo "Natives changed since ${swtTag}: ${NATIVES_CHANGED.isEmpty() ? 'None': NATIVES_CHANGED}"
160167
}
161-
if (nativesChanged || params.forceNativeBuilds) {
162-
NATIVES_CHANGED = true
168+
NATIVES_CHANGED += allWS.findAll{ ws -> params[ 'forceNativeBuilds-' + ws] }
169+
if (!NATIVES_CHANGED.isEmpty()) {
163170
def versions = getSWTVersions()
164171
sh """
165-
# Delete native binaries to be replaced by subsequent binaries build
166-
rm binaries/org.eclipse.swt.gtk.*/libswt-*.so
167-
rm binaries/org.eclipse.swt.win32.*/swt-*.dll
168-
rm binaries/org.eclipse.swt.cocoa.*/libswt-*.jnilib
169-
170172
echo "Incrementing version from ${versions.swt_version} to ${versions.new_version}"
171173
sed -i -e "s/REVISION = ${versions.rev}/REVISION = ${versions.new_rev}/g" \
172174
'bundles/org.eclipse.swt/Eclipse SWT PI/common/org/eclipse/swt/internal/Library.java'
173175
sed -i -e "s/rev=${versions.rev}/rev=${versions.new_rev}/g" \
174176
'bundles/org.eclipse.swt/Eclipse SWT/common/library/make_common.mak'
175177
"""
178+
for(ws in allWS) {
179+
if (NATIVES_CHANGED.contains(ws)) {
180+
sh """
181+
# Delete native binaries to be replaced by subsequent binaries build
182+
rm binaries/org.eclipse.swt.${ws}.*/${libraryFilePattern[ws]}
183+
"""
184+
} else {
185+
// Just rename existing native library files to new revision instead of rebuilding them
186+
sh """
187+
for f in binaries/org.eclipse.swt.${ws}.*/${libraryFilePattern[ws]}; do
188+
mv "\$f" "\$(echo \$f | sed 's/-${ws}-${versions.swt_version}/-${ws}-${versions.new_version}/g')"
189+
done
190+
"""
191+
}
192+
}
176193
// Collect SWT-native's sources
177194
dir('bundles/org.eclipse.swt') {
178-
for (ws in ['cocoa', 'gtk', 'win32']) {
195+
for (ws in NATIVES_CHANGED) {
179196
sh "java -Dws=${ws} build-scripts/CollectSources.java -nativeSources 'target/natives-build-temp/${ws}'"
180197
dir("target/natives-build-temp/${ws}") {
181198
stash(name:"swt.binaries.sources.${ws}")
@@ -207,8 +224,14 @@ pipeline {
207224
'win32.win32.x86_64'
208225
}
209226
}
227+
when {
228+
expression {
229+
def (ws, os, arch) = env.PLATFORM.split('\\.')
230+
return NATIVES_CHANGED.any{ w -> ws.startsWith(w)} // handle also dedicated gtk4 build
231+
}
232+
}
210233
stages {
211-
stage('Build SWT-natives') {
234+
stage('Initiate native build') {
212235
options {
213236
timeout(time: 120, unit: 'MINUTES') // Some build agents are rare and it might take awhile until they are available.
214237
}
@@ -229,7 +252,7 @@ pipeline {
229252
unstash "jdk.resources.${os}.${arch}"
230253
}
231254
withEnv(['MODEL=' + arch, "OUTPUT_DIR=${WORKSPACE}/libs", "SWT_JAVA_HOME=${WORKSPACE}/jdk.resources"]) {
232-
if (isUnix()){
255+
if (isUnix()) {
233256
sh '''#!/bin/bash -x
234257
mkdir libs
235258
if [[ ${PLATFORM} == gtk.linux.* ]]; then

0 commit comments

Comments
 (0)