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