[a63ad80] | 1 | #!groovy |
---|
| 2 | |
---|
[29f4fe62] | 3 | //=========================================================================================================== |
---|
| 4 | // Main compilation routine |
---|
| 5 | //=========================================================================================================== |
---|
| 6 | //Compilation script is done here but environnement set-up and error handling is done in main loop |
---|
[7ef1555e] | 7 | def cfa_build(boolean full_build) { |
---|
[77f347d] | 8 | build_stage 'Checkout' |
---|
[992c26d] | 9 | def install_dir = pwd tmp: true |
---|
[77f347d] | 10 | //checkout the source code and clean the repo |
---|
| 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 |
---|
[fd61a4f] | 25 | sh "./configure CXX=${currentCC.cpp_cc} --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 | |
---|
[29f4fe62] | 32 | //Run the tests from the example directory |
---|
[fd61a4f] | 33 | dir ('src/tests') { |
---|
[7ef1555e] | 34 | if (full_build) { |
---|
| 35 | sh 'python test.py --all' |
---|
| 36 | } |
---|
| 37 | else { |
---|
| 38 | sh './runTests.sh' |
---|
| 39 | } |
---|
[77f347d] | 40 | } |
---|
[fde808df] | 41 | |
---|
[77f347d] | 42 | build_stage 'Cleanup' |
---|
[7359098] | 43 | |
---|
[86f641b] | 44 | //do a maintainer-clean to make sure we need to remake from scratch |
---|
| 45 | sh 'make maintainer-clean > /dev/null' |
---|
[77f347d] | 46 | } |
---|
[7359098] | 47 | |
---|
[a235d09] | 48 | def push_build() { |
---|
[1a66280] | 49 | //Don't use the build_stage function which outputs the compiler |
---|
| 50 | stage 'Push' |
---|
| 51 | |
---|
| 52 | status_prefix = 'Push' |
---|
[a235d09] | 53 | |
---|
[e034675] | 54 | def out_dir = pwd tmp: true |
---|
| 55 | sh "mkdir -p ${out_dir}" |
---|
| 56 | |
---|
| 57 | //parse git logs to find what changed |
---|
| 58 | sh "git remote > ${out_dir}/GIT_REMOTE" |
---|
| 59 | git_remote = readFile("${out_dir}/GIT_REMOTE") |
---|
| 60 | remoteDoLangExists = git_remote.contains("DoLang") |
---|
| 61 | |
---|
| 62 | if( !remoteDoLangExists ) { |
---|
| 63 | sh 'git remote add DoLang git@gitlab.do-lang.org:internal/cfa-cc.git' |
---|
| 64 | } |
---|
| 65 | |
---|
[afab6dc] | 66 | sh "git push DoLang ${gitRefNewValue}:master" |
---|
[a235d09] | 67 | } |
---|
| 68 | |
---|
[29f4fe62] | 69 | //=========================================================================================================== |
---|
| 70 | // Helper classes/variables/routines to make the status and stage name easier to use |
---|
| 71 | //=========================================================================================================== |
---|
[e730560] | 72 | //Description of a compiler (Must be serializable since pipelines are persistent) |
---|
| 73 | class CC_Desc implements Serializable { |
---|
[8f6b229] | 74 | public String cc_name |
---|
| 75 | public String cpp_cc |
---|
| 76 | public String cfa_backend_cc |
---|
[f25bcb6] | 77 | |
---|
| 78 | CC_Desc(String cc_name, String cpp_cc, String cfa_backend_cc) { |
---|
| 79 | this.cc_name = cc_name |
---|
| 80 | this.cpp_cc = cpp_cc |
---|
| 81 | this.cfa_backend_cc = cfa_backend_cc |
---|
| 82 | } |
---|
[992c26d] | 83 | } |
---|
| 84 | |
---|
[29f4fe62] | 85 | //Global Variables defining the compiler and at which point in the build we are |
---|
[aec9a67] | 86 | // These variables are used but can't be declared before hand because of wierd scripting rules |
---|
| 87 | // @Field String currentCC |
---|
| 88 | // @Field String status_prefix |
---|
[fde808df] | 89 | |
---|
[29f4fe62] | 90 | //Wrapper to sync stage name and status name |
---|
[77f347d] | 91 | def build_stage(String name) { |
---|
[8f6b229] | 92 | def stage_name = "${currentCC.cc_name} ${name}".trim() |
---|
[77f347d] | 93 | stage stage_name |
---|
[fde808df] | 94 | |
---|
[77f347d] | 95 | status_prefix = stage_name |
---|
| 96 | } |
---|
[fde808df] | 97 | |
---|
[ab60d6d] | 98 | //Helper routine to collect information about the git history |
---|
| 99 | def collect_git_info() { |
---|
| 100 | |
---|
[abc26975] | 101 | //create the temporary output directory in case it doesn't already exist |
---|
[ab60d6d] | 102 | def out_dir = pwd tmp: true |
---|
[abc26975] | 103 | sh "mkdir -p ${out_dir}" |
---|
| 104 | |
---|
| 105 | //parse git logs to find what changed |
---|
[ab60d6d] | 106 | gitRefName = env.BRANCH_NAME |
---|
| 107 | dir("../${gitRefName}@script") { |
---|
| 108 | sh "git reflog > ${out_dir}/GIT_COMMIT" |
---|
| 109 | } |
---|
| 110 | git_reflog = readFile("${out_dir}/GIT_COMMIT") |
---|
| 111 | gitRefOldValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][1] |
---|
| 112 | gitRefNewValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][2] |
---|
| 113 | } |
---|
| 114 | |
---|
[29f4fe62] | 115 | //=========================================================================================================== |
---|
| 116 | // Main loop of the compilation |
---|
| 117 | //=========================================================================================================== |
---|
[77f347d] | 118 | node ('master'){ |
---|
[fde808df] | 119 | |
---|
[b8f8696] | 120 | boolean doPromoteBuild2DoLang |
---|
[77f347d] | 121 | def err = null |
---|
| 122 | def log_needed = false |
---|
[ab60d6d] | 123 | currentBuild.result = "SUCCESS" |
---|
[c7449ce2] | 124 | status_prefix = '' |
---|
[77f347d] | 125 | |
---|
| 126 | try { |
---|
[0207e71] | 127 | //Prevent the build from exceeding 30 minutes |
---|
| 128 | timeout(30) { |
---|
[40b1df9] | 129 | |
---|
[37bf576] | 130 | //Wrap build to add timestamp to command line |
---|
| 131 | wrap([$class: 'TimestamperBuildWrapper']) { |
---|
[29f4fe62] | 132 | |
---|
[7b1a604] | 133 | collect_git_info() |
---|
| 134 | |
---|
[9e5f409] | 135 | properties ([ \ |
---|
| 136 | [$class: 'ParametersDefinitionProperty', \ |
---|
| 137 | parameterDefinitions: [ \ |
---|
| 138 | [$class: 'BooleanParameterDefinition', \ |
---|
| 139 | defaultValue: false, \ |
---|
| 140 | description: 'If true, the build will be promoted to the do-lang git repository (on successful builds only)', \ |
---|
[32f17dc] | 141 | name: 'promoteBuild2DoLang' \ |
---|
[9e5f409] | 142 | ]] \ |
---|
| 143 | ]]) |
---|
| 144 | |
---|
[b8f8696] | 145 | doPromoteBuild2DoLang = promoteBuild2DoLang == 'true' |
---|
[ef77d9c] | 146 | |
---|
| 147 | echo "FULL BUILD = ${doPromoteBuild2DoLang}" |
---|
[9e5f409] | 148 | |
---|
[29f4fe62] | 149 | //Compile using gcc-4.9 |
---|
[f979c4a] | 150 | currentCC = new CC_Desc('gcc-4.9', 'g++-4.9', 'gcc-4.9') |
---|
[371fd1b] | 151 | cfa_build() |
---|
[29f4fe62] | 152 | |
---|
[40b1df9] | 153 | //Compile using gcc-5 |
---|
| 154 | currentCC = new CC_Desc('gcc-5', 'g++-5', 'gcc-5') |
---|
| 155 | cfa_build() |
---|
| 156 | |
---|
| 157 | //Compile using gcc-4.9 |
---|
| 158 | currentCC = new CC_Desc('gcc-6', 'g++-6', 'gcc-6') |
---|
| 159 | cfa_build() |
---|
| 160 | |
---|
[ef77d9c] | 161 | if( doPromoteBuild2DoLang ) { |
---|
[a235d09] | 162 | push_build() |
---|
| 163 | } |
---|
[37bf576] | 164 | } |
---|
[0207e71] | 165 | } |
---|
[f43a200] | 166 | } |
---|
| 167 | |
---|
[29f4fe62] | 168 | //If an exception is caught we need to change the status and remember to |
---|
| 169 | //attach the build log to the email |
---|
[fde808df] | 170 | catch (Exception caughtError) { |
---|
[29f4fe62] | 171 | //rethrow error later |
---|
[fde808df] | 172 | err = caughtError |
---|
[29f4fe62] | 173 | |
---|
| 174 | //An error has occured, the build log is relevent |
---|
[b287f67] | 175 | log_needed = true |
---|
[29f4fe62] | 176 | |
---|
| 177 | //Store the result of the build log |
---|
[992c26d] | 178 | currentBuild.result = "${status_prefix} FAILURE".trim() |
---|
[fde808df] | 179 | } |
---|
| 180 | |
---|
| 181 | finally { |
---|
| 182 | //Send email with final results |
---|
[1a66280] | 183 | notify_result(doPromoteBuild2DoLang, err, currentBuild.result, log_needed) |
---|
[fde808df] | 184 | |
---|
| 185 | /* Must re-throw exception to propagate error */ |
---|
| 186 | if (err) { |
---|
| 187 | throw err |
---|
| 188 | } |
---|
[d3d0069] | 189 | } |
---|
[7aebc62] | 190 | } |
---|
[f2b977a] | 191 | |
---|
[29f4fe62] | 192 | //=========================================================================================================== |
---|
| 193 | //Routine responsible of sending the email notification once the build is completed |
---|
| 194 | //=========================================================================================================== |
---|
[1a66280] | 195 | def notify_result(boolean promote, Exception err, String status, boolean log) { |
---|
[a235d09] | 196 | if(promote) { |
---|
[1a66280] | 197 | if( err ) { |
---|
[a235d09] | 198 | promote_email(status) |
---|
| 199 | } |
---|
| 200 | } |
---|
| 201 | else { |
---|
| 202 | email(status, log) |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | //Email notification on a full build failure |
---|
| 207 | def promote_email(String status) { |
---|
| 208 | //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line |
---|
| 209 | //Configurations for email format |
---|
| 210 | def email_subject = "[cforall git][PROMOTE - FAILURE]" |
---|
| 211 | def email_body = """This is an automated email from the Jenkins build machine. It was |
---|
| 212 | generated because of a git hooks/post-receive script following |
---|
| 213 | a ref change was pushed to the repository containing |
---|
| 214 | the project "UNNAMED PROJECT". |
---|
| 215 | |
---|
| 216 | Check console output at ${env.BUILD_URL} to view the results. |
---|
| 217 | |
---|
| 218 | - Status -------------------------------------------------------------- |
---|
| 219 | |
---|
| 220 | PROMOTE FAILURE - ${status} |
---|
| 221 | """ |
---|
| 222 | |
---|
| 223 | def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com" |
---|
| 224 | |
---|
| 225 | //send email notification |
---|
| 226 | emailext body: email_body, subject: email_subject, to: email_to, attachLog: true |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | //Standard build email notification |
---|
[19ad15b] | 230 | def email(String status, boolean log) { |
---|
[e8a22a7] | 231 | //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line |
---|
| 232 | //Configurations for email format |
---|
| 233 | def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase() |
---|
| 234 | |
---|
[a235d09] | 235 | sh "git rev-list --format=short ${gitRefOldValue}...${gitRefNewValue} > GIT_LOG" |
---|
[7b1a604] | 236 | def gitLog = readFile('GIT_LOG') |
---|
| 237 | |
---|
| 238 | sh "git diff --stat ${gitRefNewValue} ${gitRefOldValue} > GIT_DIFF" |
---|
| 239 | def gitDiff = readFile('GIT_DIFF') |
---|
| 240 | |
---|
[992c26d] | 241 | def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${status}] - branch ${env.BRANCH_NAME}" |
---|
[848fb00] | 242 | def email_body = """This is an automated email from the Jenkins build machine. It was |
---|
| 243 | generated because of a git hooks/post-receive script following |
---|
| 244 | a ref change was pushed to the repository containing |
---|
| 245 | the project "UNNAMED PROJECT". |
---|
[e8a22a7] | 246 | |
---|
[848fb00] | 247 | The branch ${env.BRANCH_NAME} has been updated. |
---|
[a235d09] | 248 | via ${gitRefOldValue} (commit) |
---|
| 249 | from ${gitRefNewValue} (commit) |
---|
[7b1a604] | 250 | |
---|
| 251 | Check console output at ${env.BUILD_URL} to view the results. |
---|
| 252 | |
---|
| 253 | - Status -------------------------------------------------------------- |
---|
| 254 | |
---|
| 255 | BUILD# ${env.BUILD_NUMBER} - ${status} |
---|
[e8a22a7] | 256 | |
---|
[7b1a604] | 257 | - Log ----------------------------------------------------------------- |
---|
| 258 | ${gitLog} |
---|
| 259 | ----------------------------------------------------------------------- |
---|
| 260 | Summary of changes: |
---|
| 261 | ${gitDiff} |
---|
| 262 | """ |
---|
[e8a22a7] | 263 | |
---|
[a6b7480] | 264 | def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com" |
---|
[e8a22a7] | 265 | |
---|
| 266 | //send email notification |
---|
[1e34653] | 267 | emailext body: email_body, subject: email_subject, to: email_to, attachLog: log |
---|
[e8a22a7] | 268 | } |
---|