source: Jenkinsfile@ 155c2a28

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 155c2a28 was 155c2a28, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Evaluating types before moving to a settings global type

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