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