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