source: Jenkinsfile @ 35b1bf4

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 35b1bf4 was f97b614, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Jenkins no longer changes directory when not needed

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