Debian Codegraph @

build/jenkins/pipelines/linux.Jenkinsfile

raw
1 /* Copyright (C) 2025 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 // This pipeline builds the game on Linux (with minimum supported versions of GCC and clang) and runs tests.
19
20 def tc_getCC(String tc) {
21 def map = ['gcc12': 'gcc-12', 'clang14': 'clang-14']
22 return map[tc]
23 }
24 def tc_getCXX(String tc) {
25 def map = ['gcc12': 'g++-12', 'clang14': 'clang++-14']
26 return map[tc]
27 }
28 def tc_getLDFLAGS(String tc) {
29 def map = ['gcc12': '', 'clang14': '-fuse-ld=lld-14']
30 return map[tc]
31 }
32
33 def getParserConfig(String tc, String buildType) {
34 def config
35 if (tc.startsWith('gcc')) {
36 config = [ 'tool': 'gcc', 'name': 'GCC', 'id': 'gcc-' + buildType]
37 } else {
38 config = [ 'tool': 'clang', 'name': 'Clang', 'id': 'clang-' + buildType ]
39 }
40 if (buildType.matches('debug')) {
41 config['name'] += ' Debug Build'
42 } else {
43 config['name'] += ' Release Build'
44 }
45 return config
46 }
47
48 pipeline {
49 // Stop previous build in pull requests, but not in branches
50 options { disableConcurrentBuilds(abortPrevious: env.CHANGE_ID != null) }
51
52 parameters {
53 booleanParam description: 'Non-incremental build', name: 'CLEANBUILD'
54 }
55
56 agent none
57
58 stages {
59 stage('Linux Build') {
60 failFast true
61
62 matrix {
63 axes {
64 axis {
65 name 'JENKINS_COMPILER'
66 values 'gcc12', 'clang14'
67 }
68 axis {
69 name 'BUILD_TYPE'
70 values 'debug', 'release'
71 }
72 }
73
74 environment {
75 CC = tc_getCC(env.JENKINS_COMPILER)
76 CXX = tc_getCXX(env.JENKINS_COMPILER)
77 LDFLAGS = tc_getLDFLAGS(env.JENKINS_COMPILER)
78 }
79
80 stages {
81 stage('Checkout') {
82 agent {
83 node {
84 label 'LinuxAgent'
85 customWorkspace "workspace/${JENKINS_COMPILER}-pch-${BUILD_TYPE}"
86 }
87 }
88
89 steps {
90 sh 'git lfs fetch -I binaries/data/tests'
91 sh 'git lfs checkout binaries/data/tests'
92 sh 'git lfs fetch -I "binaries/data/mods/_test.*"'
93 sh 'git lfs checkout binaries/data/mods/_test.*'
94 }
95 }
96
97 stage('Container') {
98 agent {
99 dockerfile {
100 label 'LinuxAgent'
101 customWorkspace "workspace/${JENKINS_COMPILER}-pch-${BUILD_TYPE}"
102 dir 'build/jenkins/dockerfiles'
103 filename 'debian-12.Dockerfile'
104 // Prevent Jenkins from running commands with the UID of the host's jenkins user
105 // https://stackoverflow.com/a/42822143
106 args '-u root'
107 }
108 }
109
110 stages {
111 stage('Pre-build') {
112 steps {
113 sh "libraries/build-source-libs.sh ${JOBS} 2> ${JENKINS_COMPILER}-prebuild-errors.log"
114
115 sh "build/workspaces/update-workspaces.sh 2>> ${JENKINS_COMPILER}-prebuild-errors.log"
116
117 script {
118 if (params.CLEANBUILD) {
119 sh "make -C build/workspaces/gcc/ clean config=${BUILD_TYPE}"
120 }
121 }
122 }
123 post {
124 failure {
125 echo(message: readFile(file: "${JENKINS_COMPILER}-prebuild-errors.log"))
126 }
127 }
128 }
129
130 stage('Build') {
131 steps {
132 sh '''
133 rm -f thepipe
134 mkfifo thepipe
135 tee build.log < thepipe &
136 make -C build/workspaces/gcc/ ${JOBS} config=${BUILD_TYPE} > thepipe 2>&1
137 status=$?
138 rm thepipe
139 exit ${status}
140 '''
141 }
142 post {
143 failure {
144 script {
145 if (!params.CLEANBUILD) {
146 build wait: false, job: "$JOB_NAME", parameters: [booleanParam(name: 'CLEANBUILD', value: true)]
147 }
148 }
149 }
150 always {
151 script {
152 def config = getParserConfig(env.JENKINS_COMPILER, env.BUILD_TYPE)
153 recordIssues(
154 tool: analysisParser(
155 analysisModelId: config['tool'],
156 name: config['name'],
157 id : config['id'],
158 pattern: 'build.log'
159 ),
160 skipPublishingChecks: true,
161 enabledForFailure: true,
162 qualityGates: [[threshold: 1, type: 'TOTAL', criticality: 'FAILURE']]
163 )
164 }
165 }
166 }
167 }
168
169 stage('Test') {
170 steps {
171 timeout(time: 15) {
172 script {
173 def bin = env.BUILD_TYPE == 'debug' ? 'test_dbg' : 'test'
174 sh "binaries/system/${bin} --format junit --output cxxtest.xml"
175 }
176 }
177 }
178 post {
179 always {
180 junit(skipPublishingChecks: true, testResults: 'cxxtest.xml')
181 }
182 }
183 }
184 }
185 }
186 }
187 }
188 }
189 }
190 }