| [a63ad80] | 1 | #!groovy
|
|---|
| 2 |
|
|---|
| [29f4fe62] | 3 | //===========================================================================================================
|
|---|
| [9beae23] | 4 | // Main loop of the compilation
|
|---|
| [29f4fe62] | 5 | //===========================================================================================================
|
|---|
| [9beae23] | 6 | node ('master'){
|
|---|
| [56a9ce6] | 7 |
|
|---|
| [9beae23] | 8 | boolean bIsSandbox = env.BRANCH_NAME == "jenkins-sandbox"
|
|---|
| 9 | def err = null
|
|---|
| 10 | def log_needed = false
|
|---|
| [0ef06b6] | 11 |
|
|---|
| 12 | bIsFullBuild = false
|
|---|
| 13 | architectureFlag = ''
|
|---|
| [9beae23] | 14 | status_prefix = ''
|
|---|
| [56a9ce6] | 15 |
|
|---|
| [0ef06b6] | 16 | currentBuild.result = "SUCCESS"
|
|---|
| 17 |
|
|---|
| [9beae23] | 18 | try {
|
|---|
| 19 | //Prevent the build from exceeding 60 minutes
|
|---|
| 20 | timeout(60) {
|
|---|
| [23a14d86] | 21 |
|
|---|
| [9beae23] | 22 | //Wrap build to add timestamp to command line
|
|---|
| 23 | wrap([$class: 'TimestamperBuildWrapper']) {
|
|---|
| [7aebc62] | 24 |
|
|---|
| [0ef06b6] | 25 | prepare_build()
|
|---|
| [fde808df] | 26 |
|
|---|
| [9beae23] | 27 | //Compile using gcc-4.9
|
|---|
| 28 | currentCC = new CC_Desc('gcc-4.9', 'g++-4.9', 'gcc-4.9')
|
|---|
| 29 | cfa_build(bIsFullBuild, architectureFlag)
|
|---|
| [7359098] | 30 |
|
|---|
| [9beae23] | 31 | //Compile latex documentation
|
|---|
| 32 | doc_build()
|
|---|
| [7359098] | 33 |
|
|---|
| [9beae23] | 34 | //Run benchmark and save result
|
|---|
| 35 | benchmark()
|
|---|
| [738cf8f] | 36 |
|
|---|
| [9beae23] | 37 | if( bIsFullBuild ) {
|
|---|
| 38 | //Compile using gcc-5
|
|---|
| 39 | currentCC = new CC_Desc('gcc-5', 'g++-5', 'gcc-5')
|
|---|
| 40 | cfa_build(true, architectureFlag)
|
|---|
| 41 |
|
|---|
| 42 | //Compile using gcc-4.9
|
|---|
| 43 | currentCC = new CC_Desc('gcc-6', 'g++-6', 'gcc-6')
|
|---|
| 44 | cfa_build(true, architectureFlag)
|
|---|
| 45 | }
|
|---|
| 46 | }
|
|---|
| 47 | }
|
|---|
| [738cf8f] | 48 | }
|
|---|
| 49 |
|
|---|
| [9beae23] | 50 | //If an exception is caught we need to change the status and remember to
|
|---|
| 51 | //attach the build log to the email
|
|---|
| [738cf8f] | 52 | catch (Exception caughtError) {
|
|---|
| 53 | //rethrow error later
|
|---|
| 54 | err = caughtError
|
|---|
| 55 |
|
|---|
| [9beae23] | 56 | //An error has occured, the build log is relevent
|
|---|
| 57 | log_needed = true
|
|---|
| 58 |
|
|---|
| 59 | //Store the result of the build log
|
|---|
| 60 | currentBuild.result = "${status_prefix} FAILURE".trim()
|
|---|
| [738cf8f] | 61 | }
|
|---|
| 62 |
|
|---|
| 63 | finally {
|
|---|
| [9beae23] | 64 | echo 'Build Completed'
|
|---|
| 65 |
|
|---|
| 66 | //Send email with final results if this is not a full build
|
|---|
| 67 | if( !bIsFullBuild && !bIsSandbox ) {
|
|---|
| 68 | echo 'Notifying users of result'
|
|---|
| 69 | email(currentBuild.result, log_needed)
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| [738cf8f] | 72 | /* Must re-throw exception to propagate error */
|
|---|
| 73 | if (err) {
|
|---|
| 74 | throw err
|
|---|
| 75 | }
|
|---|
| 76 | }
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| [29f4fe62] | 79 | //===========================================================================================================
|
|---|
| 80 | // Helper classes/variables/routines to make the status and stage name easier to use
|
|---|
| 81 | //===========================================================================================================
|
|---|
| [e730560] | 82 | //Description of a compiler (Must be serializable since pipelines are persistent)
|
|---|
| 83 | class CC_Desc implements Serializable {
|
|---|
| [8f6b229] | 84 | public String cc_name
|
|---|
| 85 | public String cpp_cc
|
|---|
| 86 | public String cfa_backend_cc
|
|---|
| [f25bcb6] | 87 |
|
|---|
| 88 | CC_Desc(String cc_name, String cpp_cc, String cfa_backend_cc) {
|
|---|
| 89 | this.cc_name = cc_name
|
|---|
| 90 | this.cpp_cc = cpp_cc
|
|---|
| 91 | this.cfa_backend_cc = cfa_backend_cc
|
|---|
| 92 | }
|
|---|
| [992c26d] | 93 | }
|
|---|
| 94 |
|
|---|
| [29f4fe62] | 95 | //Global Variables defining the compiler and at which point in the build we are
|
|---|
| [aec9a67] | 96 | // These variables are used but can't be declared before hand because of wierd scripting rules
|
|---|
| 97 | // @Field String currentCC
|
|---|
| 98 | // @Field String status_prefix
|
|---|
| [fde808df] | 99 |
|
|---|
| [29f4fe62] | 100 | //Wrapper to sync stage name and status name
|
|---|
| [77f347d] | 101 | def build_stage(String name) {
|
|---|
| [8f6b229] | 102 | def stage_name = "${currentCC.cc_name} ${name}".trim()
|
|---|
| [77f347d] | 103 | stage stage_name
|
|---|
| [fde808df] | 104 |
|
|---|
| [77f347d] | 105 | status_prefix = stage_name
|
|---|
| 106 | }
|
|---|
| [fde808df] | 107 |
|
|---|
| [ab60d6d] | 108 | //Helper routine to collect information about the git history
|
|---|
| 109 | def collect_git_info() {
|
|---|
| 110 |
|
|---|
| [abc26975] | 111 | //create the temporary output directory in case it doesn't already exist
|
|---|
| [ab60d6d] | 112 | def out_dir = pwd tmp: true
|
|---|
| [abc26975] | 113 | sh "mkdir -p ${out_dir}"
|
|---|
| 114 |
|
|---|
| 115 | //parse git logs to find what changed
|
|---|
| [ab60d6d] | 116 | gitRefName = env.BRANCH_NAME
|
|---|
| 117 | dir("../${gitRefName}@script") {
|
|---|
| 118 | sh "git reflog > ${out_dir}/GIT_COMMIT"
|
|---|
| 119 | }
|
|---|
| 120 | git_reflog = readFile("${out_dir}/GIT_COMMIT")
|
|---|
| 121 | gitRefOldValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][1]
|
|---|
| 122 | gitRefNewValue = (git_reflog =~ /moving from (.+) to (.+)/)[0][2]
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| [0ef06b6] | 125 | def prepare_build() {
|
|---|
| 126 | properties ([ \
|
|---|
| 127 | [$class: 'ParametersDefinitionProperty', \
|
|---|
| 128 | parameterDefinitions: [ \
|
|---|
| 129 | [$class: 'BooleanParameterDefinition', \
|
|---|
| 130 | defaultValue: false, \
|
|---|
| 131 | description: 'If true, the build will be promoted to the do-lang git repository (on successful builds only)', \
|
|---|
| 132 | name: 'isFullBuild' \
|
|---|
| 133 | ], \
|
|---|
| 134 | [$class: 'ChoiceParameterDefinition', \
|
|---|
| 135 | choices: '64-bit\n32-bit', \
|
|---|
| 136 | defaultValue: '64-bit', \
|
|---|
| 137 | description: 'The architecture to use for compilation', \
|
|---|
| 138 | name: 'buildArchitecture' \
|
|---|
| 139 | ]] \
|
|---|
| 140 | ]])
|
|---|
| 141 |
|
|---|
| 142 | bIsFullBuild = isFullBuild == 'true'
|
|---|
| 143 | architectureFlag = ''
|
|---|
| 144 | if (buildArchitecture == '64-bit') {
|
|---|
| 145 | architectureFlag = '--host=x86_64 CXXFLAGS="-m64" CFAFLAGS="-m64"'
|
|---|
| 146 | } else if (buildArchitecture == '32-bit'){
|
|---|
| 147 | architectureFlag = '--host=i386 CXXFLAGS="-m32" CFAFLAGS="-m32"'
|
|---|
| 148 | } else {
|
|---|
| 149 | architectureFlag = 'ERROR'
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | echo "FULL BUILD = ${isFullBuild}\nArchitecture = ${buildArchitecture} (flag ${architectureFlag})"
|
|---|
| 153 |
|
|---|
| 154 | collect_git_info()
|
|---|
| 155 |
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| [29f4fe62] | 158 | //===========================================================================================================
|
|---|
| [9beae23] | 159 | // Main compilation routines
|
|---|
| [29f4fe62] | 160 | //===========================================================================================================
|
|---|
| [9beae23] | 161 | //Compilation script is done here but environnement set-up and error handling is done in main loop
|
|---|
| 162 | def cfa_build(boolean full_build, String flags) {
|
|---|
| 163 | build_stage 'Checkout'
|
|---|
| 164 | def install_dir = pwd tmp: true
|
|---|
| 165 | //checkout the source code and clean the repo
|
|---|
| 166 | checkout scm
|
|---|
| [77f347d] | 167 |
|
|---|
| [9beae23] | 168 | //Clean all temporary files to make sure no artifacts of the previous build remain
|
|---|
| 169 | sh 'git clean -fdqx'
|
|---|
| [40b1df9] | 170 |
|
|---|
| [9beae23] | 171 | //Reset the git repo so no local changes persist
|
|---|
| 172 | sh 'git reset --hard'
|
|---|
| [29f4fe62] | 173 |
|
|---|
| [9beae23] | 174 | build_stage 'Build'
|
|---|
| [7b1a604] | 175 |
|
|---|
| [9beae23] | 176 | //Configure the conpilation (Output is not relevant)
|
|---|
| 177 | //Use the current directory as the installation target so nothing
|
|---|
| 178 | //escapes the sandbox
|
|---|
| 179 | //Also specify the compiler by hand
|
|---|
| 180 | sh "./configure CXX=${currentCC.cpp_cc} ${flags} --with-backend-compiler=${currentCC.cfa_backend_cc} --prefix=${install_dir} --enable-silent-rules --quiet"
|
|---|
| [9e5f409] | 181 |
|
|---|
| [9beae23] | 182 | //Compile the project
|
|---|
| 183 | sh 'make -j 8 --no-print-directory V=0 install'
|
|---|
| [24eecab] | 184 |
|
|---|
| [9beae23] | 185 | build_stage 'Test'
|
|---|
| [9e5f409] | 186 |
|
|---|
| [9beae23] | 187 | //Run the tests from the tests directory
|
|---|
| 188 | if (full_build) {
|
|---|
| 189 | sh 'make -C src/tests all-tests debug=yes'
|
|---|
| 190 | sh 'make -C src/tests all-tests debug=no'
|
|---|
| 191 | }
|
|---|
| 192 | else {
|
|---|
| 193 | sh 'make -C src/tests'
|
|---|
| 194 | }
|
|---|
| [29f4fe62] | 195 |
|
|---|
| [9beae23] | 196 | build_stage 'Cleanup'
|
|---|
| [d56c05d0] | 197 |
|
|---|
| [9beae23] | 198 | //do a maintainer-clean to make sure we need to remake from scratch
|
|---|
| 199 | sh 'make maintainer-clean > /dev/null'
|
|---|
| 200 | }
|
|---|
| [efd60d67] | 201 |
|
|---|
| [9beae23] | 202 | def make_doc() {
|
|---|
| 203 | def err = null
|
|---|
| [40b1df9] | 204 |
|
|---|
| [9beae23] | 205 | try {
|
|---|
| 206 | sh 'make clean > /dev/null'
|
|---|
| 207 | sh 'make > /dev/null 2>&1'
|
|---|
| [f43a200] | 208 | }
|
|---|
| 209 |
|
|---|
| [fde808df] | 210 | catch (Exception caughtError) {
|
|---|
| [29f4fe62] | 211 | //rethrow error later
|
|---|
| [fde808df] | 212 | err = caughtError
|
|---|
| [29f4fe62] | 213 |
|
|---|
| [9beae23] | 214 | sh 'cat *.log'
|
|---|
| [fde808df] | 215 | }
|
|---|
| 216 |
|
|---|
| 217 | finally {
|
|---|
| 218 | /* Must re-throw exception to propagate error */
|
|---|
| 219 | if (err) {
|
|---|
| 220 | throw err
|
|---|
| 221 | }
|
|---|
| [d3d0069] | 222 | }
|
|---|
| [7aebc62] | 223 | }
|
|---|
| [f2b977a] | 224 |
|
|---|
| [9beae23] | 225 | def doc_build() {
|
|---|
| 226 | stage 'Documentation'
|
|---|
| 227 |
|
|---|
| 228 | status_prefix = 'Documentation'
|
|---|
| 229 |
|
|---|
| 230 | dir ('doc/user') {
|
|---|
| 231 | make_doc()
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | dir ('doc/refrat') {
|
|---|
| 235 | make_doc()
|
|---|
| 236 | }
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | def benchmark() {
|
|---|
| 240 | stage 'Benchmark'
|
|---|
| 241 |
|
|---|
| 242 | status_prefix = 'Documentation'
|
|---|
| 243 |
|
|---|
| 244 | // //We can't just write to a file outside our repo
|
|---|
| 245 | // //Copy the file locally using ssh
|
|---|
| 246 | // sh 'scp plg2.cs.uwaterloo.ca:/u/cforall/public_html/perf-history/concurrency.csv bench.csv'
|
|---|
| 247 |
|
|---|
| 248 | // //Then append to the local file
|
|---|
| 249 | // sh 'make -C src/benchmark csv-data >> bench.csv'
|
|---|
| 250 |
|
|---|
| 251 | // //Then publish the file again
|
|---|
| 252 | // sh 'scp bench.csv plg2.cs.uwaterloo.ca:/u/cforall/public_html/perf-history/concurrency.csv'
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| [29f4fe62] | 255 | //===========================================================================================================
|
|---|
| 256 | //Routine responsible of sending the email notification once the build is completed
|
|---|
| 257 | //===========================================================================================================
|
|---|
| [a235d09] | 258 | //Standard build email notification
|
|---|
| [19ad15b] | 259 | def email(String status, boolean log) {
|
|---|
| [e8a22a7] | 260 | //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
|
|---|
| 261 | //Configurations for email format
|
|---|
| 262 | def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase()
|
|---|
| 263 |
|
|---|
| [0a346e5] | 264 | def gitLog = 'Error retrieving git logs'
|
|---|
| 265 | def gitDiff = 'Error retrieving git diff'
|
|---|
| [7b1a604] | 266 |
|
|---|
| [0a346e5] | 267 | try {
|
|---|
| 268 |
|
|---|
| 269 | sh "git rev-list --format=short ${gitRefOldValue}...${gitRefNewValue} > GIT_LOG"
|
|---|
| 270 | gitLog = readFile('GIT_LOG')
|
|---|
| 271 |
|
|---|
| 272 | sh "git diff --stat ${gitRefNewValue} ${gitRefOldValue} > GIT_DIFF"
|
|---|
| 273 | gitDiff = readFile('GIT_DIFF')
|
|---|
| 274 | }
|
|---|
| 275 | catch (Exception error) {}
|
|---|
| [7b1a604] | 276 |
|
|---|
| [992c26d] | 277 | def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${status}] - branch ${env.BRANCH_NAME}"
|
|---|
| [848fb00] | 278 | def email_body = """This is an automated email from the Jenkins build machine. It was
|
|---|
| 279 | generated because of a git hooks/post-receive script following
|
|---|
| 280 | a ref change was pushed to the repository containing
|
|---|
| 281 | the project "UNNAMED PROJECT".
|
|---|
| [e8a22a7] | 282 |
|
|---|
| [848fb00] | 283 | The branch ${env.BRANCH_NAME} has been updated.
|
|---|
| [a235d09] | 284 | via ${gitRefOldValue} (commit)
|
|---|
| 285 | from ${gitRefNewValue} (commit)
|
|---|
| [7b1a604] | 286 |
|
|---|
| 287 | Check console output at ${env.BUILD_URL} to view the results.
|
|---|
| 288 |
|
|---|
| 289 | - Status --------------------------------------------------------------
|
|---|
| 290 |
|
|---|
| 291 | BUILD# ${env.BUILD_NUMBER} - ${status}
|
|---|
| [e8a22a7] | 292 |
|
|---|
| [7b1a604] | 293 | - Log -----------------------------------------------------------------
|
|---|
| 294 | ${gitLog}
|
|---|
| 295 | -----------------------------------------------------------------------
|
|---|
| 296 | Summary of changes:
|
|---|
| 297 | ${gitDiff}
|
|---|
| 298 | """
|
|---|
| [e8a22a7] | 299 |
|
|---|
| [a6b7480] | 300 | def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com"
|
|---|
| [e8a22a7] | 301 |
|
|---|
| 302 | //send email notification
|
|---|
| [1e34653] | 303 | emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
|
|---|
| [e8a22a7] | 304 | }
|
|---|