source: Jenkinsfile @ 89427de

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since 89427de was 89427de, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Typo lead to stupid unintelligeable exceptions

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