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