source: Jenkinsfile @ 57f408e

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

Jenkins now properly uses automake cross compilation flag --host=...

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