source: Jenkinsfile @ 5beb6cd

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

Jenkins now adds benchmark information to public file

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