source: Jenkinsfile @ 0ef06b6

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

Jenkinsfile - moved build preparation in it's own branch

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