source: Jenkinsfile@ 9beae23

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 9beae23 was 9beae23, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

Cleaned Jenkinsfile to highlight main logic

  • Property mode set to 100644
File size: 8.8 KB
Line 
1#!groovy
2
3//===========================================================================================================
4// Main loop of the compilation
5//===========================================================================================================
6node ('master'){
7
8 boolean bIsSandbox = env.BRANCH_NAME == "jenkins-sandbox"
9 boolean bIsFullBuild
10 def err = null
11 def log_needed = false
12 currentBuild.result = "SUCCESS"
13 status_prefix = ''
14
15 try {
16 //Prevent the build from exceeding 60 minutes
17 timeout(60) {
18
19 //Wrap build to add timestamp to command line
20 wrap([$class: 'TimestamperBuildWrapper']) {
21
22 collect_git_info()
23
24 properties ([ \
25 [$class: 'ParametersDefinitionProperty', \
26 parameterDefinitions: [ \
27 [$class: 'BooleanParameterDefinition', \
28 defaultValue: false, \
29 description: 'If true, the build will be promoted to the do-lang git repository (on successful builds only)', \
30 name: 'isFullBuild' \
31 ], \
32 [$class: 'ChoiceParameterDefinition', \
33 choices: '64-bit\n32-bit', \
34 defaultValue: '64-bit', \
35 description: 'The architecture to use for compilation', \
36 name: 'buildArchitecture' \
37 ]] \
38 ]])
39
40 bIsFullBuild = isFullBuild == 'true'
41 architectureFlag = ''
42 if (buildArchitecture == '64-bit') {
43 architectureFlag = '--host=x86_64 CXXFLAGS="-m64" CFAFLAGS="-m64"'
44 } else if (buildArchitecture == '32-bit'){
45 architectureFlag = '--host=i386 CXXFLAGS="-m32" CFAFLAGS="-m32"'
46 } else {
47 architectureFlag = 'ERROR'
48 }
49
50 echo "FULL BUILD = ${isFullBuild}\nArchitecture = ${buildArchitecture} (flag ${architectureFlag})"
51
52 //Compile using gcc-4.9
53 currentCC = new CC_Desc('gcc-4.9', 'g++-4.9', 'gcc-4.9')
54 cfa_build(bIsFullBuild, architectureFlag)
55
56 //Compile latex documentation
57 doc_build()
58
59 //Run benchmark and save result
60 benchmark()
61
62 if( bIsFullBuild ) {
63 //Compile using gcc-5
64 currentCC = new CC_Desc('gcc-5', 'g++-5', 'gcc-5')
65 cfa_build(true, architectureFlag)
66
67 //Compile using gcc-4.9
68 currentCC = new CC_Desc('gcc-6', 'g++-6', 'gcc-6')
69 cfa_build(true, architectureFlag)
70 }
71 }
72 }
73 }
74
75 //If an exception is caught we need to change the status and remember to
76 //attach the build log to the email
77 catch (Exception caughtError) {
78 //rethrow error later
79 err = caughtError
80
81 //An error has occured, the build log is relevent
82 log_needed = true
83
84 //Store the result of the build log
85 currentBuild.result = "${status_prefix} FAILURE".trim()
86 }
87
88 finally {
89 echo 'Build Completed'
90
91 //Send email with final results if this is not a full build
92 if( !bIsFullBuild && !bIsSandbox ) {
93 echo 'Notifying users of result'
94 email(currentBuild.result, log_needed)
95 }
96
97 /* Must re-throw exception to propagate error */
98 if (err) {
99 throw err
100 }
101 }
102}
103
104//===========================================================================================================
105// Helper classes/variables/routines to make the status and stage name easier to use
106//===========================================================================================================
107//Description of a compiler (Must be serializable since pipelines are persistent)
108class CC_Desc implements Serializable {
109 public String cc_name
110 public String cpp_cc
111 public String cfa_backend_cc
112
113 CC_Desc(String cc_name, String cpp_cc, String cfa_backend_cc) {
114 this.cc_name = cc_name
115 this.cpp_cc = cpp_cc
116 this.cfa_backend_cc = cfa_backend_cc
117 }
118}
119
120//Global Variables defining the compiler and at which point in the build we are
121// These variables are used but can't be declared before hand because of wierd scripting rules
122// @Field String currentCC
123// @Field String status_prefix
124
125//Wrapper to sync stage name and status name
126def build_stage(String name) {
127 def stage_name = "${currentCC.cc_name} ${name}".trim()
128 stage stage_name
129
130 status_prefix = stage_name
131}
132
133//Helper routine to collect information about the git history
134def collect_git_info() {
135
136 //create the temporary output directory in case it doesn't already exist
137 def out_dir = pwd tmp: true
138 sh "mkdir -p ${out_dir}"
139
140 //parse git logs to find what changed
141 gitRefName = env.BRANCH_NAME
142 dir("../${gitRefName}@script") {
143 sh "git reflog > ${out_dir}/GIT_COMMIT"
144 }
145 git_reflog = readFile("${out_dir}/GIT_COMMIT")
146 gitRefOldValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][1]
147 gitRefNewValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][2]
148}
149
150//===========================================================================================================
151// Main compilation routines
152//===========================================================================================================
153//Compilation script is done here but environnement set-up and error handling is done in main loop
154def cfa_build(boolean full_build, String flags) {
155 build_stage 'Checkout'
156 def install_dir = pwd tmp: true
157 //checkout the source code and clean the repo
158 checkout scm
159
160 //Clean all temporary files to make sure no artifacts of the previous build remain
161 sh 'git clean -fdqx'
162
163 //Reset the git repo so no local changes persist
164 sh 'git reset --hard'
165
166 build_stage 'Build'
167
168 //Configure the conpilation (Output is not relevant)
169 //Use the current directory as the installation target so nothing
170 //escapes the sandbox
171 //Also specify the compiler by hand
172 sh "./configure CXX=${currentCC.cpp_cc} ${flags} --with-backend-compiler=${currentCC.cfa_backend_cc} --prefix=${install_dir} --enable-silent-rules --quiet"
173
174 //Compile the project
175 sh 'make -j 8 --no-print-directory V=0 install'
176
177 build_stage 'Test'
178
179 //Run the tests from the tests directory
180 if (full_build) {
181 sh 'make -C src/tests all-tests debug=yes'
182 sh 'make -C src/tests all-tests debug=no'
183 }
184 else {
185 sh 'make -C src/tests'
186 }
187
188 build_stage 'Cleanup'
189
190 //do a maintainer-clean to make sure we need to remake from scratch
191 sh 'make maintainer-clean > /dev/null'
192}
193
194def make_doc() {
195 def err = null
196
197 try {
198 sh 'make clean > /dev/null'
199 sh 'make > /dev/null 2>&1'
200 }
201
202 catch (Exception caughtError) {
203 //rethrow error later
204 err = caughtError
205
206 sh 'cat *.log'
207 }
208
209 finally {
210 /* Must re-throw exception to propagate error */
211 if (err) {
212 throw err
213 }
214 }
215}
216
217def doc_build() {
218 stage 'Documentation'
219
220 status_prefix = 'Documentation'
221
222 dir ('doc/user') {
223 make_doc()
224 }
225
226 dir ('doc/refrat') {
227 make_doc()
228 }
229}
230
231def benchmark() {
232 stage 'Benchmark'
233
234 status_prefix = 'Documentation'
235
236 // //We can't just write to a file outside our repo
237 // //Copy the file locally using ssh
238 // sh 'scp plg2.cs.uwaterloo.ca:/u/cforall/public_html/perf-history/concurrency.csv bench.csv'
239
240 // //Then append to the local file
241 // sh 'make -C src/benchmark csv-data >> bench.csv'
242
243 // //Then publish the file again
244 // sh 'scp bench.csv plg2.cs.uwaterloo.ca:/u/cforall/public_html/perf-history/concurrency.csv'
245}
246
247//===========================================================================================================
248//Routine responsible of sending the email notification once the build is completed
249//===========================================================================================================
250//Standard build email notification
251def email(String status, boolean log) {
252 //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
253 //Configurations for email format
254 def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase()
255
256 def gitLog = 'Error retrieving git logs'
257 def gitDiff = 'Error retrieving git diff'
258
259 try {
260
261 sh "git rev-list --format=short ${gitRefOldValue}...${gitRefNewValue} > GIT_LOG"
262 gitLog = readFile('GIT_LOG')
263
264 sh "git diff --stat ${gitRefNewValue} ${gitRefOldValue} > GIT_DIFF"
265 gitDiff = readFile('GIT_DIFF')
266 }
267 catch (Exception error) {}
268
269 def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${status}] - branch ${env.BRANCH_NAME}"
270 def email_body = """This is an automated email from the Jenkins build machine. It was
271generated because of a git hooks/post-receive script following
272a ref change was pushed to the repository containing
273the project "UNNAMED PROJECT".
274
275The branch ${env.BRANCH_NAME} has been updated.
276 via ${gitRefOldValue} (commit)
277 from ${gitRefNewValue} (commit)
278
279Check console output at ${env.BUILD_URL} to view the results.
280
281- Status --------------------------------------------------------------
282
283BUILD# ${env.BUILD_NUMBER} - ${status}
284
285- Log -----------------------------------------------------------------
286${gitLog}
287-----------------------------------------------------------------------
288Summary of changes:
289${gitDiff}
290"""
291
292 def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com"
293
294 //send email notification
295 emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
296}
Note: See TracBrowser for help on using the repository browser.