source: Jenkinsfile@ 8e27665d

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 no_list persistent-indexer pthread-emulation qualifiedEnum
Last change on this file since 8e27665d was 8e27665d, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Moved up git collect info

  • Property mode set to 100644
File size: 11.7 KB
RevLine 
[a63ad80]1#!groovy
2
[29f4fe62]3//===========================================================================================================
[9beae23]4// Main loop of the compilation
[29f4fe62]5//===========================================================================================================
[9beae23]6node ('master'){
[56a9ce6]7
[9beae23]8 boolean bIsSandbox = env.BRANCH_NAME == "jenkins-sandbox"
9 def err = null
10 def log_needed = false
[0ef06b6]11
[deb6185]12 stage_name = ''
13
14 gitRefOldValue = ''
15 gitRefNewValue = ''
[734891d]16
[e93572a]17 builddir = pwd tmp: true
18 srcdir = pwd tmp: false
[73787a9]19
[0ef06b6]20 currentBuild.result = "SUCCESS"
21
[9beae23]22 try {
[95fdb0a]23 //Wrap build to add timestamp to command line
24 wrap([$class: 'TimestamperBuildWrapper']) {
[23a14d86]25
[8c700c1]26 notify_server(0)
[95fdb0a]27
[f408e1a]28 prepare_build()
[7aebc62]29
[0dc3ac3]30 clean()
31
[f408e1a]32 checkout()
[fde808df]33
[8c700c1]34 notify_server(0)
35
[f408e1a]36 build()
[95fdb0a]37
[f408e1a]38 test()
[95fdb0a]39
[f408e1a]40 benchmark()
[95fdb0a]41
[f408e1a]42 build_doc()
[7359098]43
[f408e1a]44 publish()
[9beae23]45
[65f9dec]46 notify_server(45)
[9beae23]47 }
[738cf8f]48 }
49
[9beae23]50 //If an exception is caught we need to change the status and remember to
51 //attach the build log to the email
[738cf8f]52 catch (Exception caughtError) {
53 //rethrow error later
54 err = caughtError
55
[9beae23]56 //An error has occured, the build log is relevent
57 log_needed = true
58
59 //Store the result of the build log
[734891d]60 currentBuild.result = "${stage_name} FAILURE".trim()
[738cf8f]61 }
62
63 finally {
[9beae23]64 //Send email with final results if this is not a full build
[7e288c4]65 if( !params.Silent ) {
[9beae23]66 echo 'Notifying users of result'
[094a42c]67 email(currentBuild.result, log_needed, bIsSandbox)
[9beae23]68 }
69
[734891d]70 echo 'Build Completed'
71
[738cf8f]72 /* Must re-throw exception to propagate error */
73 if (err) {
74 throw err
75 }
76 }
77}
78
[29f4fe62]79//===========================================================================================================
[95fdb0a]80// Helper classes/variables/routines
[29f4fe62]81//===========================================================================================================
[ab60d6d]82//Helper routine to collect information about the git history
83def collect_git_info() {
84
[b2fcb72f]85 final scmVars = checkout scm
86 echo "----------------------------------------"
87 echo "scmVars: ${scmVars}"
[805c167]88
[abc26975]89 //create the temporary output directory in case it doesn't already exist
[ab60d6d]90 def out_dir = pwd tmp: true
[abc26975]91 sh "mkdir -p ${out_dir}"
92
93 //parse git logs to find what changed
[ab60d6d]94 gitRefName = env.BRANCH_NAME
[7c0ef42]95 sh "git reflog > ${out_dir}/GIT_COMMIT"
[ab60d6d]96 git_reflog = readFile("${out_dir}/GIT_COMMIT")
97 gitRefOldValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][1]
98 gitRefNewValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][2]
99}
100
[0ef06b6]101def prepare_build() {
[8e27665d]102 collect_git_info()
103
[95fdb0a]104 properties ([ \
105 [$class: 'ParametersDefinitionProperty', \
106 parameterDefinitions: [ \
107 [$class: 'ChoiceParameterDefinition', \
108 description: 'Which compiler to use', \
[0c1d240]109 name: 'Compiler', \
[95fdb0a]110 choices: 'gcc-6\ngcc-5\ngcc-4.9\nclang', \
111 defaultValue: 'gcc-6', \
112 ], \
113 [$class: 'ChoiceParameterDefinition', \
114 description: 'The target architecture', \
[0c1d240]115 name: 'Architecture', \
[8fa3c7e6]116 choices: 'x64\nx86', \
117 defaultValue: 'x64', \
[95fdb0a]118 ], \
119 [$class: 'BooleanParameterDefinition', \
120 description: 'If false, only the quick test suite is ran', \
[0c1d240]121 name: 'RunAllTests', \
[95fdb0a]122 defaultValue: false, \
123 ], \
124 [$class: 'BooleanParameterDefinition', \
125 description: 'If true, jenkins also runs benchmarks', \
[0c1d240]126 name: 'RunBenchmark', \
[7caea53]127 defaultValue: false, \
[95fdb0a]128 ], \
129 [$class: 'BooleanParameterDefinition', \
130 description: 'If true, jenkins also builds documentation', \
[0c1d240]131 name: 'BuildDocumentation', \
[26a63f0]132 defaultValue: true, \
[95fdb0a]133 ], \
134 [$class: 'BooleanParameterDefinition', \
135 description: 'If true, jenkins also publishes results', \
[0c1d240]136 name: 'Publish', \
[3831b58]137 defaultValue: false, \
[fd6d74e]138 ], \
139 [$class: 'BooleanParameterDefinition', \
140 description: 'If true, jenkins will not send emails', \
[0c1d240]141 name: 'Silent', \
[95fdb0a]142 defaultValue: false, \
143 ], \
144 ],
[0ef06b6]145 ]])
146
[7e288c4]147 params.Compiler = compiler_from_params( params.Compiler )
148 params.Architecture = architecture_from_params( params.Architecture )
[ab5cd196]149
[7e288c4]150 def full = params.RunAllTests ? " (Full)" : ""
151 currentBuild.description = "${ params.Compiler.cc_name }:${ params.Architecture.name }${full}"
[e6ab994]152
[7e288c4]153 echo """Compiler : ${ params.Compiler.cc_name } (${ params.Compiler.cpp_cc }/${ params.Compiler.cfa_cc })
154Architecture : ${ params.Architecture.name }
155Arc Flags : ${ params.Architecture.flags }
[2112663f]156Run All Tests : ${ params.RunAllTests.toString() }
157Run Benchmark : ${ params.RunBenchmark.toString() }
158Build Documentation : ${ params.BuildDocumentation.toString() }
159Publish : ${ params.Publish.toString() }
160Silent : ${ params.Silent.toString() }
[6802a5f]161"""
[95fdb0a]162}
[0ef06b6]163
[620dd2b]164def build_stage(String name, Closure block ) {
[734891d]165 stage_name = name
[620dd2b]166 stage(name, block)
[734891d]167}
168
[65f9dec]169def notify_server(int wait) {
[50f2cfc]170 sh """curl --silent --show-error --data "wait=${wait}" -X POST https://cforall.uwaterloo.ca:8082/jenkins/notify > /dev/null || true"""
[ed50f0ba]171 return
[95fdb0a]172}
173
174def make_doc() {
175 def err = null
176 try {
177 sh 'make clean > /dev/null'
178 sh 'make > /dev/null 2>&1'
[a5b7905]179 }
[95fdb0a]180 catch (Exception caughtError) {
181 err = caughtError //rethrow error later
182 sh 'cat *.log'
183 }
184 finally {
185 if (err) throw err // Must re-throw exception to propagate error
[bd34bcf5]186 }
187}
188
189//Description of a compiler (Must be serializable since pipelines are persistent)
190class CC_Desc implements Serializable {
191 public String cc_name
192 public String cpp_cc
[6802a5f]193 public String cfa_cc
[bd34bcf5]194
[6802a5f]195 CC_Desc(String cc_name, String cpp_cc, String cfa_cc) {
[bd34bcf5]196 this.cc_name = cc_name
197 this.cpp_cc = cpp_cc
[6802a5f]198 this.cfa_cc = cfa_cc
[bd34bcf5]199 }
200}
201
202def compiler_from_params(cc) {
203 switch( cc ) {
204 case 'gcc-6':
205 return new CC_Desc('gcc-6', 'g++-6', 'gcc-6')
206 break
207 case 'gcc-5':
208 return new CC_Desc('gcc-5', 'g++-5', 'gcc-5')
209 break
210 case 'gcc-4.9':
211 return new CC_Desc('gcc-4.9', 'g++-4.9', 'gcc-4.9')
212 break
213 case 'clang':
[6802a5f]214 return new CC_Desc('clang', 'clang++', 'gcc-6')
[bd34bcf5]215 break
[1e6a463]216 default :
[201d77a]217 error "Unhandled compiler : ${cc}"
[bd34bcf5]218 }
219}
220
[7e288c4]221//Description of an architecture (Must be serializable since pipelines are persistent)
[eb0938ca]222class Arch_Desc implements Serializable {
[7e288c4]223 public String name
224 public String flags
225
[c2cec21d]226 Arch_Desc(String name, String flags) {
[7e288c4]227 this.name = name
228 this.flags = flags
229 }
230}
231
[bd34bcf5]232def architecture_from_params( arch ) {
233 switch( arch ) {
[8fa3c7e6]234 case 'x64':
[eb0938ca]235 return new Arch_Desc('x64', '--host=x86_64')
[bd34bcf5]236 break
[8fa3c7e6]237 case 'x86':
[eb0938ca]238 return new Arch_Desc('x86', '--host=i386')
[bd34bcf5]239 break
[1e6a463]240 default :
[201d77a]241 error "Unhandled architecture : ${arch}"
[95fdb0a]242 }
[0ef06b6]243}
244
[29f4fe62]245//===========================================================================================================
[9beae23]246// Main compilation routines
[29f4fe62]247//===========================================================================================================
[0dc3ac3]248def clean() {
249 build_stage('Cleanup') {
250 // clean the build by wipping the build directory
[ece8a80]251 dir(builddir) {
[d4cd491]252 deleteDir()
[ece8a80]253 }
254
[9beae23]255 //Clean all temporary files to make sure no artifacts of the previous build remain
256 sh 'git clean -fdqx'
[40b1df9]257
[9beae23]258 //Reset the git repo so no local changes persist
259 sh 'git reset --hard'
[620dd2b]260 }
[95fdb0a]261}
[29f4fe62]262
[0dc3ac3]263//Compilation script is done here but environnement set-up and error handling is done in main loop
264def checkout() {
265 build_stage('Checkout') {
266 //checkout the source code and clean the repo
267 checkout scm
268 }
269}
270
[95fdb0a]271def build() {
[620dd2b]272 build_stage('Build') {
[50f2cfc]273 // Build outside of the src tree to ease cleaning
[0dc3ac3]274 dir (builddir) {
[50f2cfc]275 //Configure the conpilation (Output is not relevant)
276 //Use the current directory as the installation target so nothing escapes the sandbox
277 //Also specify the compiler by hand
[3fc5f010]278 targets=""
[7e288c4]279 if( params.RunAllTests ) {
[6bde81d]280 targets="--with-target-hosts='host:debug,host:nodebug'"
[3fc5f010]281 } else {
[6bde81d]282 targets="--with-target-hosts='host:debug'"
[3fc5f010]283 }
284
[7e288c4]285 sh "${srcdir}/configure CXX=${params.Compiler.cpp_cc} ${params.Architecture.flags} ${targets} --with-backend-compiler=${params.Compiler.cfa_cc} --quiet"
[1752d0e]286
[50f2cfc]287 //Compile the project
288 sh 'make -j 8 --no-print-directory'
289 }
[620dd2b]290 }
[95fdb0a]291}
[24eecab]292
[95fdb0a]293def test() {
[620dd2b]294 build_stage('Test') {
[9e5f409]295
[0dc3ac3]296 dir (builddir) {
297 //Run the tests from the tests directory
[7e288c4]298 if ( params.RunAllTests ) {
[ea5b7d6]299 sh 'make --no-print-directory -C tests all-tests debug=yes'
300 sh 'make --no-print-directory -C tests all-tests debug=no '
[0dc3ac3]301 }
302 else {
[ea5b7d6]303 sh 'make --no-print-directory -C tests'
[0dc3ac3]304 }
[9beae23]305 }
[620dd2b]306 }
[95fdb0a]307}
308
309def benchmark() {
[620dd2b]310 build_stage('Benchmark') {
[29f4fe62]311
[7e288c4]312 if( !params.RunBenchmark ) return
[ae28ee2]313
[0dc3ac3]314 dir (builddir) {
315 //Append bench results
[7e288c4]316 sh "make --no-print-directory -C benchmark jenkins githash=${gitRefNewValue} arch=${params.Architecture} | tee ${srcdir}/bench.json"
[0dc3ac3]317 }
[620dd2b]318 }
[9beae23]319}
[efd60d67]320
[95fdb0a]321def build_doc() {
[620dd2b]322 build_stage('Documentation') {
[9beae23]323
[7e288c4]324 if( !params.BuildDocumentation ) return
[9beae23]325
326 dir ('doc/user') {
327 make_doc()
328 }
329
330 dir ('doc/refrat') {
331 make_doc()
332 }
[620dd2b]333 }
[9beae23]334}
335
[95fdb0a]336def publish() {
[620dd2b]337 build_stage('Publish') {
[95fdb0a]338
[7e288c4]339 if( !params.Publish ) return
[95fdb0a]340
341 //Then publish the results
[50f2cfc]342 sh 'curl --silent --show-error -H \'Content-Type: application/json\' --data @bench.json https://cforall.uwaterloo.ca:8082/jenkins/publish > /dev/null || true'
[620dd2b]343 }
[95fdb0a]344}
345
[29f4fe62]346//===========================================================================================================
347//Routine responsible of sending the email notification once the build is completed
348//===========================================================================================================
[3f9876e]349def gitBranchUpdate(String gitRefOldValue, String gitRefNewValue) {
350 def update = ""
[db583df]351 sh "git rev-list ${gitRefOldValue}..${gitRefNewValue} > GIT_LOG";
[3f9876e]352 readFile('GIT_LOG').eachLine { rev ->
353 sh "git cat-file -t ${rev} > GIT_TYPE"
354 def type = readFile('GIT_TYPE')
355
356 update += " via ${rev} (${type})\n"
357 }
358 def rev = gitRefOldValue
359 sh "git cat-file -t ${rev} > GIT_TYPE"
360 def type = readFile('GIT_TYPE')
361
362 update += " from ${rev} (${type})\n"
363 return update
364
365def output=readFile('result').trim()
366echo "output=$output";
367}
368
[a235d09]369//Standard build email notification
[094a42c]370def email(String status, boolean log, boolean bIsSandbox) {
[e8a22a7]371 //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
372 //Configurations for email format
373 def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase()
374
[0a346e5]375 def gitLog = 'Error retrieving git logs'
376 def gitDiff = 'Error retrieving git diff'
[3f9876e]377 def gitUpdate = 'Error retrieving update'
[7b1a604]378
[0a346e5]379 try {
[3f9876e]380 gitUpdate = gitBranchUpdate(gitRefOldValue, gitRefNewValue)
[0a346e5]381
382 sh "git rev-list --format=short ${gitRefOldValue}...${gitRefNewValue} > GIT_LOG"
383 gitLog = readFile('GIT_LOG')
384
385 sh "git diff --stat ${gitRefNewValue} ${gitRefOldValue} > GIT_DIFF"
386 gitDiff = readFile('GIT_DIFF')
387 }
[fb975a50]388 catch (Exception error) {
389 echo error.toString()
390 echo error.getMessage()
391 }
[7b1a604]392
[992c26d]393 def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${status}] - branch ${env.BRANCH_NAME}"
[848fb00]394 def email_body = """This is an automated email from the Jenkins build machine. It was
395generated because of a git hooks/post-receive script following
396a ref change was pushed to the repository containing
397the project "UNNAMED PROJECT".
[e8a22a7]398
[848fb00]399The branch ${env.BRANCH_NAME} has been updated.
[3f9876e]400${gitUpdate}
[7b1a604]401
402Check console output at ${env.BUILD_URL} to view the results.
403
404- Status --------------------------------------------------------------
405
406BUILD# ${env.BUILD_NUMBER} - ${status}
[e8a22a7]407
[7b1a604]408- Log -----------------------------------------------------------------
409${gitLog}
410-----------------------------------------------------------------------
411Summary of changes:
412${gitDiff}
413"""
[e8a22a7]414
[e39647e]415 def email_to = "cforall@lists.uwaterloo.ca"
[e8a22a7]416
[094a42c]417 if( !bIsSandbox ) {
418 //send email notification
419 emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
420 } else {
421 echo "Would send email to: ${email_to}"
422 echo "With title: ${email_subject}"
423 echo "Content: \n${email_body}"
424 }
[e8a22a7]425}
Note: See TracBrowser for help on using the repository browser.