Skip to content

Commit 61666fd

Browse files
committed
[Build] Rename library files if native sources of platform are unchanged
Build only the SWT binaries whose native sources are really changed and just rename the binaries for all other platforms that are not 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 build-nodes in Jenkins - increased stability of the build because if the native build-nodes for the skipped platforms are unavailable the build isn't blocked anymore. - 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 536fea8 commit 61666fd

File tree

1 file changed

+44
-33
lines changed

1 file changed

+44
-33
lines changed

Jenkinsfile

Lines changed: 44 additions & 33 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+
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,34 +157,41 @@ 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
163-
def swtVersions = getSWTVersions()
164-
withEnv(['swt_version='+swtVersions['swt_version'], 'new_version='+swtVersions['new_version'], 'rev='+swtVersions['rev'], 'new_rev='+swtVersions['new_rev'],
165-
'comma_ver='+swtVersions['comma_ver'], "new_comma_ver=${swtVersions['maj_ver']},${swtVersions['min_ver']},${swtVersions['new_rev']},0" ]) {
166-
sh '''
168+
NATIVES_CHANGED += allWS.findAll{ ws -> params[ 'forceNativeBuilds-' + ws] }
169+
if (!NATIVES_CHANGED.isEmpty()) {
170+
def versions = getSWTVersions()
171+
for(ws in allWS) {
172+
if (NATIVES_CHANGED.contains(ws)) {
173+
sh """
167174
# Delete native binaries to be replaced by subsequent binaries build
168-
rm binaries/org.eclipse.swt.gtk.*/libswt-*.so
169-
rm binaries/org.eclipse.swt.win32.*/swt-*.dll
170-
rm binaries/org.eclipse.swt.cocoa.*/libswt-*.jnilib
171-
172-
echo "Incrementing version from ${swt_version} to ${new_version}; new comma_ver=${new_comma_ver}"
175+
rm binaries/org.eclipse.swt.${ws}.*/*swt-*.${libraryFilePattern[ws]}
173176
174-
libraryFile='bundles/org.eclipse.swt/Eclipse SWT PI/common/org/eclipse/swt/internal/Library.java'
175-
sed -i -e "s/REVISION = ${rev}/REVISION = ${new_rev}/g" "$libraryFile"
176-
177-
commonMakeFile='bundles/org.eclipse.swt/Eclipse SWT/common/library/make_common.mak'
178-
sed -i -e "s/rev=${rev}/rev=${new_rev}/g" "$commonMakeFile"
179-
sed -i -e "s/comma_ver=${comma_ver}/comma_ver=${new_comma_ver}/g" "$commonMakeFile"
180-
'''
177+
echo "Incrementing version from ${versions.swt_version} to ${versions.new_version}"
178+
sed -i -e "s/REVISION = ${versions.rev}/REVISION = ${versions.new_rev}/g" \
179+
'bundles/org.eclipse.swt/Eclipse SWT PI/common/org/eclipse/swt/internal/Library.java'
180+
sed -i -e "s/rev=${versions.rev}/rev=${versions.new_rev}/g" \
181+
'bundles/org.eclipse.swt/Eclipse SWT/common/library/make_common.mak'
182+
"""
183+
} else {
184+
// Just rename existing native library files to new revision instead of rebuilding them
185+
sh """
186+
for f in binaries/org.eclipse.swt.${ws}.*/*swt-*.${libraryFilePattern[ws]}; do
187+
mv "\$f" "\$(echo \$f | sed 's/-${ws}-${versions.swt_version}/-${ws}-${versions.new_version}/g')"
188+
done
189+
"""
190+
}
181191
}
182192
// Collect SWT-native's sources
183193
dir('bundles/org.eclipse.swt') {
184-
for (ws in ['cocoa', 'gtk', 'win32']) {
194+
for (ws in NATIVES_CHANGED) {
185195
sh "java -Dws=${ws} build-scripts/CollectSources.java -nativeSources 'target/natives-build-temp/${ws}'"
186196
dir("target/natives-build-temp/${ws}") {
187197
stash(name:"swt.binaries.sources.${ws}")
@@ -214,13 +224,17 @@ pipeline {
214224
}
215225
}
216226
stages {
217-
stage('Build SWT-natives') {
227+
stage('Prepare and post-process native build') {
218228
options {
219229
timeout(time: 120, unit: 'MINUTES') // Some build agents are rare and it might take awhile until they are available.
220230
}
221231
steps {
222232
script {
223233
def (ws, os, arch) = env.PLATFORM.split('\\.')
234+
if (!NATIVES_CHANGED.contains(ws)) {
235+
echo "Skip native build for unchanged platform ${PLATFORM}"
236+
return;
237+
}
224238
dir("jdk-download-${os}.${arch}") {
225239
// Fetch the JDK, which provides the C header-files and shared native libraries, against which the natives are build.
226240
sh "curl ${getNativeJdkUrl(os, arch)} | tar -xzf - include/ lib/"
@@ -235,7 +249,7 @@ pipeline {
235249
unstash "jdk.resources.${os}.${arch}"
236250
}
237251
withEnv(['MODEL=' + arch, "OUTPUT_DIR=${WORKSPACE}/libs", "SWT_JAVA_HOME=${WORKSPACE}/jdk.resources"]) {
238-
if (isUnix()){
252+
if (isUnix()) {
239253
sh '''#!/bin/bash -x
240254
mkdir libs
241255
if [[ ${PLATFORM} == gtk.linux.* ]]; then
@@ -269,10 +283,7 @@ pipeline {
269283
cleanWs() // workspace not cleaned by default
270284
}
271285
}
272-
}
273-
}
274-
stage('Collect and sign binaries') {
275-
steps {
286+
// Collect and sign binaries
276287
dir("libs/${PLATFORM}") {
277288
unstash "swt.binaries.${PLATFORM}"
278289
sh '''#!/bin/bash -x

0 commit comments

Comments
 (0)