1 | #!groovy
|
---|
2 |
|
---|
3 | //===========================================================================================================
|
---|
4 | // Main compilation routine
|
---|
5 | //===========================================================================================================
|
---|
6 | //Compilation script is done here but environnement set-up and error handling is done in main loop
|
---|
7 | def cfa_build(boolean full_build) {
|
---|
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} --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 'python test.py --all'
|
---|
36 | }
|
---|
37 | else {
|
---|
38 | sh './runTests.sh'
|
---|
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 |
|
---|
48 | def 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 |
|
---|
71 | def doc_build() {
|
---|
72 | build_stage 'Documentation'
|
---|
73 |
|
---|
74 | dir ('doc/user') {
|
---|
75 | make_doc()
|
---|
76 | }
|
---|
77 |
|
---|
78 | dir ('doc/refrat') {
|
---|
79 | make_doc()
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | def push_build() {
|
---|
84 | //Don't use the build_stage function which outputs the compiler
|
---|
85 | stage 'Push'
|
---|
86 |
|
---|
87 | status_prefix = 'Push'
|
---|
88 |
|
---|
89 | def out_dir = pwd tmp: true
|
---|
90 | sh "mkdir -p ${out_dir}"
|
---|
91 |
|
---|
92 | //parse git logs to find what changed
|
---|
93 | sh "git remote > ${out_dir}/GIT_REMOTE"
|
---|
94 | git_remote = readFile("${out_dir}/GIT_REMOTE")
|
---|
95 | remoteDoLangExists = git_remote.contains("DoLang")
|
---|
96 |
|
---|
97 | if( !remoteDoLangExists ) {
|
---|
98 | sh 'git remote add DoLang git@gitlab.do-lang.org:internal/cfa-cc.git'
|
---|
99 | }
|
---|
100 |
|
---|
101 | sh "git push DoLang ${gitRefNewValue}:master"
|
---|
102 | }
|
---|
103 |
|
---|
104 | //===========================================================================================================
|
---|
105 | // Helper classes/variables/routines to make the status and stage name easier to use
|
---|
106 | //===========================================================================================================
|
---|
107 | //Description of a compiler (Must be serializable since pipelines are persistent)
|
---|
108 | class CC_Desc implements Serializable {
|
---|
109 | public String cc_name
|
---|
110 | public String cpp_cc
|
---|
111 | public String cfa_backend_cc
|
---|
112 |
|
---|
113 | CC_Desc(String cc_name, String cpp_cc, String cfa_backend_cc) {
|
---|
114 | this.cc_name = cc_name
|
---|
115 | this.cpp_cc = cpp_cc
|
---|
116 | this.cfa_backend_cc = cfa_backend_cc
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | //Global Variables defining the compiler and at which point in the build we are
|
---|
121 | // These variables are used but can't be declared before hand because of wierd scripting rules
|
---|
122 | // @Field String currentCC
|
---|
123 | // @Field String status_prefix
|
---|
124 |
|
---|
125 | //Wrapper to sync stage name and status name
|
---|
126 | def build_stage(String name) {
|
---|
127 | def stage_name = "${currentCC.cc_name} ${name}".trim()
|
---|
128 | stage stage_name
|
---|
129 |
|
---|
130 | status_prefix = stage_name
|
---|
131 | }
|
---|
132 |
|
---|
133 | //Helper routine to collect information about the git history
|
---|
134 | def collect_git_info() {
|
---|
135 |
|
---|
136 | //create the temporary output directory in case it doesn't already exist
|
---|
137 | def out_dir = pwd tmp: true
|
---|
138 | sh "mkdir -p ${out_dir}"
|
---|
139 |
|
---|
140 | //parse git logs to find what changed
|
---|
141 | gitRefName = env.BRANCH_NAME
|
---|
142 | dir("../${gitRefName}@script") {
|
---|
143 | sh "git reflog > ${out_dir}/GIT_COMMIT"
|
---|
144 | }
|
---|
145 | git_reflog = readFile("${out_dir}/GIT_COMMIT")
|
---|
146 | gitRefOldValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][1]
|
---|
147 | gitRefNewValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][2]
|
---|
148 | }
|
---|
149 |
|
---|
150 | //===========================================================================================================
|
---|
151 | // Main loop of the compilation
|
---|
152 | //===========================================================================================================
|
---|
153 | node ('master'){
|
---|
154 |
|
---|
155 | boolean doPromoteBuild2DoLang
|
---|
156 | def err = null
|
---|
157 | def log_needed = false
|
---|
158 | currentBuild.result = "SUCCESS"
|
---|
159 | status_prefix = ''
|
---|
160 |
|
---|
161 | try {
|
---|
162 | //Prevent the build from exceeding 30 minutes
|
---|
163 | timeout(60) {
|
---|
164 |
|
---|
165 | //Wrap build to add timestamp to command line
|
---|
166 | wrap([$class: 'TimestamperBuildWrapper']) {
|
---|
167 |
|
---|
168 | collect_git_info()
|
---|
169 |
|
---|
170 | properties ([ \
|
---|
171 | [$class: 'ParametersDefinitionProperty', \
|
---|
172 | parameterDefinitions: [ \
|
---|
173 | [$class: 'BooleanParameterDefinition', \
|
---|
174 | defaultValue: false, \
|
---|
175 | description: 'If true, the build will be promoted to the do-lang git repository (on successful builds only)', \
|
---|
176 | name: 'promoteBuild2DoLang' \
|
---|
177 | ]] \
|
---|
178 | ]])
|
---|
179 |
|
---|
180 | doPromoteBuild2DoLang = promoteBuild2DoLang == 'true'
|
---|
181 |
|
---|
182 | echo "FULL BUILD = ${doPromoteBuild2DoLang}"
|
---|
183 |
|
---|
184 | //Compile using gcc-4.9
|
---|
185 | currentCC = new CC_Desc('gcc-4.9', 'g++-4.9', 'gcc-4.9')
|
---|
186 | cfa_build(doPromoteBuild2DoLang)
|
---|
187 |
|
---|
188 | //Compile using gcc-5
|
---|
189 | currentCC = new CC_Desc('gcc-5', 'g++-5', 'gcc-5')
|
---|
190 | cfa_build(doPromoteBuild2DoLang)
|
---|
191 |
|
---|
192 | //Compile using gcc-4.9
|
---|
193 | currentCC = new CC_Desc('gcc-6', 'g++-6', 'gcc-6')
|
---|
194 | cfa_build(doPromoteBuild2DoLang)
|
---|
195 |
|
---|
196 | //Compile latex documentation
|
---|
197 | doc_build()
|
---|
198 |
|
---|
199 | if( doPromoteBuild2DoLang ) {
|
---|
200 | push_build()
|
---|
201 | }
|
---|
202 | }
|
---|
203 | }
|
---|
204 | }
|
---|
205 |
|
---|
206 | //If an exception is caught we need to change the status and remember to
|
---|
207 | //attach the build log to the email
|
---|
208 | catch (Exception caughtError) {
|
---|
209 | //rethrow error later
|
---|
210 | err = caughtError
|
---|
211 |
|
---|
212 | //An error has occured, the build log is relevent
|
---|
213 | log_needed = true
|
---|
214 |
|
---|
215 | //Store the result of the build log
|
---|
216 | currentBuild.result = "${status_prefix} FAILURE".trim()
|
---|
217 | }
|
---|
218 |
|
---|
219 | finally {
|
---|
220 | //Send email with final results
|
---|
221 | notify_result(doPromoteBuild2DoLang, err, currentBuild.result, log_needed)
|
---|
222 |
|
---|
223 | /* Must re-throw exception to propagate error */
|
---|
224 | if (err) {
|
---|
225 | throw err
|
---|
226 | }
|
---|
227 | }
|
---|
228 | }
|
---|
229 |
|
---|
230 | //===========================================================================================================
|
---|
231 | //Routine responsible of sending the email notification once the build is completed
|
---|
232 | //===========================================================================================================
|
---|
233 | def notify_result(boolean promote, Exception err, String status, boolean log) {
|
---|
234 | echo 'Build completed, sending result notification'
|
---|
235 | if(promote) {
|
---|
236 | if( err ) {
|
---|
237 | promote_email(status)
|
---|
238 | }
|
---|
239 | }
|
---|
240 | else {
|
---|
241 | email(status, log)
|
---|
242 | }
|
---|
243 | }
|
---|
244 |
|
---|
245 | //Email notification on a full build failure
|
---|
246 | def promote_email(String status) {
|
---|
247 | //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
|
---|
248 | //Configurations for email format
|
---|
249 | def email_subject = "[cforall git][PROMOTE - FAILURE]"
|
---|
250 | def email_body = """This is an automated email from the Jenkins build machine. It was
|
---|
251 | generated because of a git hooks/post-receive script following
|
---|
252 | a ref change was pushed to the repository containing
|
---|
253 | the project "UNNAMED PROJECT".
|
---|
254 |
|
---|
255 | Check console output at ${env.BUILD_URL} to view the results.
|
---|
256 |
|
---|
257 | - Status --------------------------------------------------------------
|
---|
258 |
|
---|
259 | PROMOTE FAILURE - ${status}
|
---|
260 | """
|
---|
261 |
|
---|
262 | def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com"
|
---|
263 |
|
---|
264 | //send email notification
|
---|
265 | emailext body: email_body, subject: email_subject, to: email_to, attachLog: true
|
---|
266 | }
|
---|
267 |
|
---|
268 | //Standard build email notification
|
---|
269 | def email(String status, boolean log) {
|
---|
270 | //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
|
---|
271 | //Configurations for email format
|
---|
272 | def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase()
|
---|
273 |
|
---|
274 | def gitLog = 'Error retrieving git logs'
|
---|
275 | def gitDiff = 'Error retrieving git diff'
|
---|
276 |
|
---|
277 | try {
|
---|
278 |
|
---|
279 | sh "git rev-list --format=short ${gitRefOldValue}...${gitRefNewValue} > GIT_LOG"
|
---|
280 | gitLog = readFile('GIT_LOG')
|
---|
281 |
|
---|
282 | sh "git diff --stat ${gitRefNewValue} ${gitRefOldValue} > GIT_DIFF"
|
---|
283 | gitDiff = readFile('GIT_DIFF')
|
---|
284 | }
|
---|
285 | catch (Exception error) {}
|
---|
286 |
|
---|
287 | def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${status}] - branch ${env.BRANCH_NAME}"
|
---|
288 | def email_body = """This is an automated email from the Jenkins build machine. It was
|
---|
289 | generated because of a git hooks/post-receive script following
|
---|
290 | a ref change was pushed to the repository containing
|
---|
291 | the project "UNNAMED PROJECT".
|
---|
292 |
|
---|
293 | The branch ${env.BRANCH_NAME} has been updated.
|
---|
294 | via ${gitRefOldValue} (commit)
|
---|
295 | from ${gitRefNewValue} (commit)
|
---|
296 |
|
---|
297 | Check console output at ${env.BUILD_URL} to view the results.
|
---|
298 |
|
---|
299 | - Status --------------------------------------------------------------
|
---|
300 |
|
---|
301 | BUILD# ${env.BUILD_NUMBER} - ${status}
|
---|
302 |
|
---|
303 | - Log -----------------------------------------------------------------
|
---|
304 | ${gitLog}
|
---|
305 | -----------------------------------------------------------------------
|
---|
306 | Summary of changes:
|
---|
307 | ${gitDiff}
|
---|
308 | """
|
---|
309 |
|
---|
310 | def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com"
|
---|
311 |
|
---|
312 | //send email notification
|
---|
313 | emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
|
---|
314 | }
|
---|