source: Jenkinsfile@ cc640aad

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since cc640aad was cc640aad, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

Jenkins now builds both debug and release tests during full build

  • Property mode set to 100644
File size: 8.2 KB
RevLine 
[a63ad80]1#!groovy
2
[29f4fe62]3//===========================================================================================================
[6003581]4// Main compilation routines
[29f4fe62]5//===========================================================================================================
6//Compilation script is done here but environnement set-up and error handling is done in main loop
[c0588909]7def cfa_build(boolean full_build, String flags) {
[77f347d]8 build_stage 'Checkout'
[992c26d]9 def install_dir = pwd tmp: true
[77f347d]10 //checkout the source code and clean the repo
[3151e3b]11 checkout scm
[56a9ce6]12
13 //Clean all temporary files to make sure no artifacts of the previous build remain
[01b8088d]14 sh 'git clean -fdqx'
[56a9ce6]15
16 //Reset the git repo so no local changes persist
[01b8088d]17 sh 'git reset --hard'
[23a14d86]18
[77f347d]19 build_stage 'Build'
[7aebc62]20
[77f347d]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
[fa66f4e]25 sh "./configure CXX=${currentCC.cpp_cc} ${flags} --with-backend-compiler=${currentCC.cfa_backend_cc} --prefix=${install_dir} --enable-silent-rules --quiet"
[fde808df]26
[77f347d]27 //Compile the project
[245510f]28 sh 'make -j 8 --no-print-directory V=0 install'
[fde808df]29
[77f347d]30 build_stage 'Test'
[fde808df]31
[cb64fd6]32 //Run the tests from the tests directory
[fd61a4f]33 dir ('src/tests') {
[7ef1555e]34 if (full_build) {
[cc640aad]35 sh 'make all-tests debug=yes'
36 sh 'make all-tests debug=no'
[7ef1555e]37 }
38 else {
[b015035]39 sh 'make'
[7ef1555e]40 }
[77f347d]41 }
[fde808df]42
[77f347d]43 build_stage 'Cleanup'
[7359098]44
[86f641b]45 //do a maintainer-clean to make sure we need to remake from scratch
46 sh 'make maintainer-clean > /dev/null'
[77f347d]47}
[7359098]48
[738cf8f]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
[18e2758]72def doc_build() {
[fa234ef]73 stage 'Documentation'
74
75 status_prefix = 'Documentation'
[18e2758]76
77 dir ('doc/user') {
[738cf8f]78 make_doc()
[18e2758]79 }
80
81 dir ('doc/refrat') {
[738cf8f]82 make_doc()
[18e2758]83 }
84}
85
[29f4fe62]86//===========================================================================================================
87// Helper classes/variables/routines to make the status and stage name easier to use
88//===========================================================================================================
[e730560]89//Description of a compiler (Must be serializable since pipelines are persistent)
90class CC_Desc implements Serializable {
[8f6b229]91 public String cc_name
92 public String cpp_cc
93 public String cfa_backend_cc
[f25bcb6]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 }
[992c26d]100}
101
[29f4fe62]102//Global Variables defining the compiler and at which point in the build we are
[aec9a67]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
[fde808df]106
[29f4fe62]107//Wrapper to sync stage name and status name
[77f347d]108def build_stage(String name) {
[8f6b229]109 def stage_name = "${currentCC.cc_name} ${name}".trim()
[77f347d]110 stage stage_name
[fde808df]111
[77f347d]112 status_prefix = stage_name
113}
[fde808df]114
[ab60d6d]115//Helper routine to collect information about the git history
116def collect_git_info() {
117
[abc26975]118 //create the temporary output directory in case it doesn't already exist
[ab60d6d]119 def out_dir = pwd tmp: true
[abc26975]120 sh "mkdir -p ${out_dir}"
121
122 //parse git logs to find what changed
[ab60d6d]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
[29f4fe62]132//===========================================================================================================
133// Main loop of the compilation
134//===========================================================================================================
[77f347d]135node ('master'){
[fde808df]136
[a3e1f8f]137 boolean bIsFullBuild
[77f347d]138 def err = null
139 def log_needed = false
[ab60d6d]140 currentBuild.result = "SUCCESS"
[c7449ce2]141 status_prefix = ''
[77f347d]142
143 try {
[0207e71]144 //Prevent the build from exceeding 30 minutes
[18e2758]145 timeout(60) {
[40b1df9]146
[37bf576]147 //Wrap build to add timestamp to command line
148 wrap([$class: 'TimestamperBuildWrapper']) {
[29f4fe62]149
[7b1a604]150 collect_git_info()
151
[9e5f409]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)', \
[6003581]158 name: 'isFullBuild' \
[c617272]159 ], \
[e66ef08]160 [$class: 'ChoiceParameterDefinition', \
[1e94036a]161 choices: '64-bit\n32-bit', \
[24eecab]162 defaultValue: '64-bit', \
[1b6a23e]163 description: 'The architecture to use for compilation', \
164 name: 'buildArchitecture' \
[c13d970]165 ]] \
[9e5f409]166 ]])
167
[a3e1f8f]168 bIsFullBuild = isFullBuild == 'true'
[2ee5426]169 architectureFlag = ''
[fa66f4e]170 if (buildArchitecture == '64-bit') {
[2ee5426]171 architectureFlag = '--host=x86_64 CXXFLAGS="-m64" CFAFLAGS="-m64"'
[fa66f4e]172 } else if (buildArchitecture == '32-bit'){
[2ee5426]173 architectureFlag = '--host=i386 CXXFLAGS="-m32" CFAFLAGS="-m32"'
[fa66f4e]174 } else {
175 architectureFlag = 'ERROR'
176 }
[24eecab]177
[ccd5b12]178 echo "FULL BUILD = ${isFullBuild}\nArchitecture = ${buildArchitecture} (flag ${architectureFlag})"
[9e5f409]179
[29f4fe62]180 //Compile using gcc-4.9
[f979c4ab]181 currentCC = new CC_Desc('gcc-4.9', 'g++-4.9', 'gcc-4.9')
[a3e1f8f]182 cfa_build(bIsFullBuild, architectureFlag)
[29f4fe62]183
[d56c05d0]184 //Compile latex documentation
185 doc_build()
186
[a3e1f8f]187 if( bIsFullBuild ) {
[b015035]188 //Compile using gcc-5
189 currentCC = new CC_Desc('gcc-5', 'g++-5', 'gcc-5')
[c0588909]190 cfa_build(true, architectureFlag)
[40b1df9]191
[b015035]192 //Compile using gcc-4.9
193 currentCC = new CC_Desc('gcc-6', 'g++-6', 'gcc-6')
[c0588909]194 cfa_build(true, architectureFlag)
[a235d09]195 }
[37bf576]196 }
[0207e71]197 }
[f43a200]198 }
199
[29f4fe62]200 //If an exception is caught we need to change the status and remember to
201 //attach the build log to the email
[fde808df]202 catch (Exception caughtError) {
[29f4fe62]203 //rethrow error later
[fde808df]204 err = caughtError
[29f4fe62]205
206 //An error has occured, the build log is relevent
[b287f67]207 log_needed = true
[29f4fe62]208
209 //Store the result of the build log
[992c26d]210 currentBuild.result = "${status_prefix} FAILURE".trim()
[fde808df]211 }
212
213 finally {
[b94206b]214 echo 'Build Completed'
215
[a3e1f8f]216 //Send email with final results if this is not a full build
217 if( !bIsFullBuild ) {
[b94206b]218 echo 'Notifying users of result'
[a3e1f8f]219 email(currentBuild.result, log_needed)
220 }
[fde808df]221
222 /* Must re-throw exception to propagate error */
223 if (err) {
224 throw err
225 }
[d3d0069]226 }
[7aebc62]227}
[f2b977a]228
[29f4fe62]229//===========================================================================================================
230//Routine responsible of sending the email notification once the build is completed
231//===========================================================================================================
[a235d09]232//Standard build email notification
[19ad15b]233def email(String status, boolean log) {
[e8a22a7]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
[0a346e5]238 def gitLog = 'Error retrieving git logs'
239 def gitDiff = 'Error retrieving git diff'
[7b1a604]240
[0a346e5]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) {}
[7b1a604]250
[992c26d]251 def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${status}] - branch ${env.BRANCH_NAME}"
[848fb00]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".
[e8a22a7]256
[848fb00]257The branch ${env.BRANCH_NAME} has been updated.
[a235d09]258 via ${gitRefOldValue} (commit)
259 from ${gitRefNewValue} (commit)
[7b1a604]260
261Check console output at ${env.BUILD_URL} to view the results.
262
263- Status --------------------------------------------------------------
264
265BUILD# ${env.BUILD_NUMBER} - ${status}
[e8a22a7]266
[7b1a604]267- Log -----------------------------------------------------------------
268${gitLog}
269-----------------------------------------------------------------------
270Summary of changes:
271${gitDiff}
272"""
[e8a22a7]273
[a6b7480]274 def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com"
[e8a22a7]275
276 //send email notification
[1e34653]277 emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
[e8a22a7]278}
Note: See TracBrowser for help on using the repository browser.