forked from eclipse-platform/eclipse.platform.swt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
347 lines (334 loc) · 12.9 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
/*******************************************************************************
* Copyright (c) 2021, 2024 Red Hat Inc. 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:
* Mickael Istria (Red Hat Inc.) - initial API and implementation
* Hannes Wellmann - Build SWT-natives as part of master- and verification-builds
* Hannes Wellmann - Move SWT native binaries in this repository using Git-LFS
* Hannes Wellmann - Streamline entire SWT build and replace ANT-scripts by Maven, Jenkins-Pipeline and single-source Java scripts
*******************************************************************************/
def nativeBuildAgent(String platform, Closure body) {
def final nativeBuildStageName = 'Build SWT-native binaries'
if (platform == 'gtk.linux.x86_64') {
return podTemplate(yaml: '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: "swtbuild"
image: "eclipse/platformreleng-centos-swt-build:8"
imagePullPolicy: "Always"
resources:
limits:
memory: "4096Mi"
cpu: "2000m"
requests:
memory: "512Mi"
cpu: "1000m"
command:
- cat
tty: true
volumeMounts:
- name: tools
mountPath: /opt/tools
volumes:
- name: tools
persistentVolumeClaim:
claimName: tools-claim-jiro-releng
''') { node(POD_LABEL) { stage(nativeBuildStageName) { container('swtbuild') { body() } } } }
} else {
return node('swt.natives-' + platform) { stage(nativeBuildStageName) { body() } }
}
}
/** Returns the download URL of the JDK against whoose C headers (in the 'include/' folder) and native libaries the SWT natives are compiled.*/
def getNativeJdkUrl(String os, String arch){ // To update the used JDK version update the URL template below
return "https://download.eclipse.org/justj/jres/17/downloads/20230428_1804/org.eclipse.justj.openjdk.hotspot.jre.minimal.stripped-17.0.7-${os}-${arch}.tar.gz"
}
def getLatestGitTag() {
return sh(script: 'git describe --abbrev=0 --tags --match v[0-9][0-9][0-9][0-9]*', returnStdout: true).strip()
}
def getSWTVersions() { // must be called from the repository root
def props = readProperties(file: 'bundles/org.eclipse.swt/Eclipse SWT/common/library/make_common.mak')
props['new_rev'] = props['rev'].toInteger() + 1
props['swt_version'] = props['maj_ver'] + props['min_ver'] + 'r' + props['rev']
props['new_version'] = props['maj_ver'] + props['min_ver'] + 'r' + props['new_rev']
return props
}
boolean NATIVES_CHANGED = false
pipeline {
options {
skipDefaultCheckout() // Specialiced checkout is performed below
timestamps()
timeout(time: 180, unit: 'MINUTES')
buildDiscarder(logRotator(numToKeepStr:'5'))
disableConcurrentBuilds(abortPrevious: true)
}
agent {
label 'centos-latest'
}
tools {
jdk 'openjdk-jdk17-latest'
maven 'apache-maven-latest'
}
environment {
MAVEN_OPTS = "-Xmx4G"
PR_VALIDATION_BUILD = "true"
}
parameters {
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.')
booleanParam(name: 'skipCommit', defaultValue: false, description: 'Stops committing to swt and swt binaries repo at the end. Useful in debugging.')
}
stages {
stage('Checkout swt git repos') {
steps {
dir('eclipse.platform.swt') {
checkout scm
script {
def authorMail = sh(script: 'git log -1 --pretty=format:"%ce" HEAD', returnStdout: true)
echo 'HEAD commit author: ' + authorMail
if ('[email protected]'.equals(authorMail) && !params.forceNativeBuilds) {
// Prevent endless build-loops due to self triggering because of a previous automated build of SWT-natives and the associated updates.
currentBuild.result = 'ABORTED'
error('Abort build only triggered by automated SWT-natives update.')
}
}
sh '''
git version
git lfs version
git config --unset core.hooksPath # Jenkins disables hooks by default as security feature, but we need the hooks for LFS
git lfs update # Install Git LFS hooks in repository, which has been skipped due to the initially nulled hookspath
git lfs pull
git fetch --all --tags --quiet
git remote set-url --push origin [email protected]:eclipse-platform/eclipse.platform.swt.git
'''
}
}
}
stage('Check if SWT-binaries build is needed') {
steps {
dir('eclipse.platform.swt') {
sh'''
java -version
git config --global user.email '[email protected]'
git config --global user.name 'Eclipse Releng Bot'
'''
script {
def swtTag = getLatestGitTag()
echo "Current tag=${swtTag}."
boolean nativesChanged = false
dir('bundles/org.eclipse.swt') {
// Verify preprocessing is completed
sh '''
if grep -R --include='*.java' --line-number --fixed-strings -e 'int /*long*/' -e 'float /*double*/' -e 'int[] /*long[]*/' -e 'float[] /*double[]*/' .; then
echo There are files with the wrong long /*int*/ preprocessing.
exit 1
fi
'''
def sourceFoldersProps = readProperties(file: 'nativeSourceFolders.properties')
def sources = sourceFoldersProps.collectEntries{ k, src -> [ k, src.split(',').collect{ f -> '\'' + f + '\''}.join(' ') ] }
def diff = sh(script: "git diff HEAD ${swtTag} ${sources.values().join(' ')}", returnStdout: true)
nativesChanged = !diff.strip().isEmpty()
echo "Natives changed since ${swtTag}: ${nativesChanged}"
}
if (nativesChanged || params.forceNativeBuilds) {
NATIVES_CHANGED = true
def swtVersions = getSWTVersions()
withEnv(['swt_version='+swtVersions['swt_version'], 'new_version='+swtVersions['new_version'], 'rev='+swtVersions['rev'], 'new_rev='+swtVersions['new_rev'],
'comma_ver='+swtVersions['comma_ver'], "new_comma_ver=${swtVersions['maj_ver']},${swtVersions['min_ver']},${swtVersions['new_rev']},0" ]) {
sh '''
# Delete native binaries to be replaced by subsequent binaries build
rm binaries/org.eclipse.swt.gtk.*/libswt-*.so
rm binaries/org.eclipse.swt.win32.*/swt-*.dll
rm binaries/org.eclipse.swt.cocoa.*/libswt-*.jnilib
echo "Incrementing version from ${swt_version} to ${new_version}; new comma_ver=${new_comma_ver}"
libraryFile='bundles/org.eclipse.swt/Eclipse SWT PI/common/org/eclipse/swt/internal/Library.java'
sed -i -e "s/REVISION = ${rev}/REVISION = ${new_rev}/g" "$libraryFile"
commonMakeFile='bundles/org.eclipse.swt/Eclipse SWT/common/library/make_common.mak'
sed -i -e "s/rev=${rev}/rev=${new_rev}/g" "$commonMakeFile"
sed -i -e "s/comma_ver=${comma_ver}/comma_ver=${new_comma_ver}/g" "$commonMakeFile"
'''
}
}
}
}
}
}
stage('Build SWT-binaries, if needed') {
when {
expression { NATIVES_CHANGED }
}
matrix {
axes {
axis {
name 'PLATFORM'
values 'cocoa.macosx.aarch64' , 'cocoa.macosx.x86_64', 'gtk.linux.aarch64', 'gtk.linux.ppc64le', 'gtk.linux.x86_64', 'win32.win32.x86_64'
}
}
stages {
stage("Collect SWT-native's sources") {
steps {
dir('eclipse.platform.swt/bundles/org.eclipse.swt') {
sh '''
pfSpec=(${PLATFORM//"."/ })
java -Dws=${pfSpec[0]} -Darch=${pfSpec[2]} build-scripts/CollectSources.java -nativeSources \
"${WORKSPACE}/eclipse.platform.swt/binaries/org.eclipse.swt.${PLATFORM}/target/natives-build-temp"
'''
}
dir("eclipse.platform.swt/binaries/org.eclipse.swt.${PLATFORM}/target/natives-build-temp") {
stash(name:"swt.binaries.sources.${PLATFORM}")
}
}
}
stage('Build SWT-natives') {
options {
timeout(time: 120, unit: 'MINUTES') // Some build agents are rare and it might take awhile until they are available.
}
steps {
script {
def (ws, os, arch) = env.PLATFORM.split('\\.')
dir("jdk-download-${os}.${arch}") {
// Fetch the JDK, which provides the C header-files and shared native libaries, against which the natives are build.
sh "curl ${getNativeJdkUrl(os, arch)} | tar -xzf - include/ lib/"
stash name:"jdk.resources.${os}.${arch}", includes: "include/,lib/"
deleteDir()
}
nativeBuildAgent("${PLATFORM}") {
cleanWs() // Workspace is not cleaned up by default, so we do it explicitly
echo "OS: ${os}, ARCH: ${arch}"
unstash "swt.binaries.sources.${PLATFORM}"
dir('jdk.resources') {
unstash "jdk.resources.${os}.${arch}"
}
withEnv(['MODEL=' + arch, "OUTPUT_DIR=${WORKSPACE}/libs", "SWT_JAVA_HOME=${WORKSPACE}/jdk.resources"]) {
if (isUnix()){
sh '''
mkdir libs
sh build.sh install
ls -1R libs
'''
} else {
bat '''
mkdir libs
cmd /c build.bat install
'''
}
}
dir('libs') {
stash "swt.binaries.${PLATFORM}"
}
}
}
}
}
stage('Collect and sign binaries') {
steps {
dir("libs/${PLATFORM}") {
unstash "swt.binaries.${PLATFORM}"
sh '''
if [[ ${PLATFORM} == cocoa.macosx.* ]]; then
binariesExtension='jnilib'
signerUrl='https://cbi.eclipse.org/macos/codesign/sign'
elif [[ ${PLATFORM} == gtk.linux.* ]]; then
binariesExtension='so'
elif [[ ${PLATFORM} == win32.win32.* ]]; then
binariesExtension='dll'
signerUrl='https://cbi.eclipse.org/authenticode/sign'
fi
if [[ -n "$signerUrl" ]]; then
echo "Sign ${PLATFORM} libraries"
if [[ "${BRANCH_NAME}" == master ]] || [[ "${BRANCH_NAME}" =~ R[0-9]+_[0-9]+(_[0-9]+)?_maintenance ]]; then
for file in *.${binariesExtension}; do
mv $file unsigned-$file
curl --fail --form "file=@unsigned-$file" --output "$file" "$signerUrl"
rm unsigned-$file
done
fi
fi
cp *.$binariesExtension "${WORKSPACE}/eclipse.platform.swt/binaries/org.eclipse.swt.${PLATFORM}/"
'''
}
}
}
}
}
}
stage('Commit SWT-native binaries, if build') {
when {
expression { NATIVES_CHANGED }
}
steps {
dir('eclipse.platform.swt') {
withEnv(["swt_version=${getSWTVersions()['swt_version']}"]) { // versions are read from updated file
sh '''
find binaries -name "*${swt_version}*" -type f -exec chmod 755 {} +
git add --all *
git status
git commit -m "v${swt_version}"
git tag "v${swt_version}"
git status
git log --patch -2
'''
}
}
}
}
stage('Build') {
steps {
xvnc(useXauthority: true) {
dir('eclipse.platform.swt') {
sh '''
mvn clean verify \
--batch-mode --threads 1C -V -U -e -DforkCount=0 \
-Papi-check \
-Dcompare-version-with-baselines.skip=false \
-Dorg.eclipse.swt.tests.junit.disable.test_isLocal=true \
-Dmaven.test.failure.ignore=true -Dmaven.test.error.ignore=true
'''
}
}
}
post {
always {
junit 'eclipse.platform.swt/tests/*.test*/target/surefire-reports/*.xml'
archiveArtifacts artifacts: '**/*.log,**/*.html,**/target/*.jar,**/target/*.zip'
discoverGitReferenceBuild referenceJob: 'eclipse.platform.swt/master'
recordIssues publishAllIssues: true, tools: [eclipse(name: 'Compiler and API Tools', pattern: '**/target/compilelogs/*.xml'), javaDoc()], qualityGates: [[threshold: 1, type: 'DELTA', unstable: true]]
recordIssues publishAllIssues: true, tool: mavenConsole(), qualityGates: [[threshold: 1, type: 'DELTA_ERROR', unstable: true]]
}
}
}
stage('Push SWT-native binaries, if build') {
when {
expression { NATIVES_CHANGED }
}
steps {
sshagent(['github-bot-ssh']) {
dir('eclipse.platform.swt') {
sh """
# Check for the master-branch as late as possible to have as much of the same behaviour as possible
if [[ '${BRANCH_NAME}' == master ]] || [[ '${BRANCH_NAME}' =~ R[0-9]+_[0-9]+(_[0-9]+)?_maintenance ]]; then
if [[ ${params.skipCommit} != true ]]; then
# Don't rebase and just fail in case another commit has been pushed to the master/maintanance branch in the meantime
git push origin HEAD:refs/heads/${BRANCH_NAME}
git push origin refs/tags/${getLatestGitTag()}
exit 0
else
echo Committing is skipped
fi
else
echo Skip pushing changes of native-binaries for branch '${BRANCH_NAME}'
fi
"""
}
}
}
}
}
}