source: Jenkinsfile @ 0a1a680

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

Jenkins now builds both debug and release tests during full build

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