| [4011b98] | 1 | #!groovy | 
|---|
|  | 2 |  | 
|---|
|  | 3 | import groovy.transform.Field | 
|---|
|  | 4 |  | 
|---|
|  | 5 | //=========================================================================================================== | 
|---|
|  | 6 | // Main loop of the compilation | 
|---|
|  | 7 | //=========================================================================================================== | 
|---|
|  | 8 |  | 
|---|
| [e018546] | 9 | // Globals | 
|---|
|  | 10 | BuildDir  = null | 
|---|
|  | 11 | SrcDir    = null | 
|---|
|  | 12 | Settings  = null | 
|---|
|  | 13 | Version   = '' | 
|---|
| [4011b98] | 14 |  | 
|---|
| [e018546] | 15 | // Local variables | 
|---|
|  | 16 | def err = null | 
|---|
|  | 17 | def log_needed = false | 
|---|
| [4011b98] | 18 |  | 
|---|
| [e018546] | 19 | currentBuild.result = "SUCCESS" | 
|---|
|  | 20 |  | 
|---|
|  | 21 | final commit, build | 
|---|
|  | 22 | node { | 
|---|
| [4011b98] | 23 |  | 
|---|
| [8e58264] | 24 | //Wrap build to add timestamp to command line | 
|---|
|  | 25 | wrap([$class: 'TimestamperBuildWrapper']) { | 
|---|
|  | 26 | (commit, build) = prepare_build() | 
|---|
| [e018546] | 27 | } | 
|---|
|  | 28 | } | 
|---|
| [4011b98] | 29 |  | 
|---|
| [e018546] | 30 | node('x64') { | 
|---|
|  | 31 | //Wrap build to add timestamp to command line | 
|---|
|  | 32 | wrap([$class: 'TimestamperBuildWrapper']) { | 
|---|
|  | 33 | BuildDir  = pwd tmp: true | 
|---|
|  | 34 | SrcDir    = pwd tmp: false | 
|---|
| [8e58264] | 35 |  | 
|---|
| [e018546] | 36 | Tools.Clean() | 
|---|
| [4011b98] | 37 |  | 
|---|
| [e018546] | 38 | Tools.Checkout( commit ) | 
|---|
| [4011b98] | 39 |  | 
|---|
| [e018546] | 40 | Version = GetVersion( build ) | 
|---|
| [4011b98] | 41 |  | 
|---|
| [e018546] | 42 | Configure() | 
|---|
| [4011b98] | 43 |  | 
|---|
| [e018546] | 44 | Package() | 
|---|
| [4011b98] | 45 |  | 
|---|
| [e018546] | 46 | Test() | 
|---|
| [4011b98] | 47 |  | 
|---|
| [e018546] | 48 | Archive() | 
|---|
| [4011b98] | 49 | } | 
|---|
|  | 50 | } | 
|---|
|  | 51 |  | 
|---|
|  | 52 | //=========================================================================================================== | 
|---|
|  | 53 | // Main compilation routines | 
|---|
|  | 54 | //=========================================================================================================== | 
|---|
| [8fe6040] | 55 | def GetVersion(build) { | 
|---|
| [7e366bd] | 56 | final pver = sh( | 
|---|
|  | 57 | returnStdout: true, | 
|---|
| [ad915e0] | 58 | script: "sed 's/AC_INIT(\\[cfa-cc\\],\\[\\(.*\\)\\],\\[cforall@plg.uwaterloo.ca\\])/\\1/;t;d' ${SrcDir}/configure.ac" | 
|---|
| [7e366bd] | 59 | ).trim() | 
|---|
|  | 60 |  | 
|---|
| [8fe6040] | 61 | final version = "${pver}.${build}" | 
|---|
| [f78ead5] | 62 |  | 
|---|
| [8fe6040] | 63 | echo "Package Version: ${pver}" | 
|---|
|  | 64 | echo "Build   Version: ${build}" | 
|---|
|  | 65 | echo "Long    Version: ${version}" | 
|---|
| [4011b98] | 66 |  | 
|---|
| [8fe6040] | 67 | return version | 
|---|
|  | 68 | } | 
|---|
| [4011b98] | 69 |  | 
|---|
| [8e58264] | 70 | def Configure() { | 
|---|
|  | 71 | Tools.BuildStage('Configure', true) { | 
|---|
|  | 72 | // Configure must be run inside the tree | 
|---|
|  | 73 | dir (SrcDir) { | 
|---|
|  | 74 | // Generate the necessary build files | 
|---|
|  | 75 | sh './autogen.sh' | 
|---|
|  | 76 | } | 
|---|
|  | 77 |  | 
|---|
|  | 78 | // Build outside of the src tree to ease cleaning | 
|---|
|  | 79 | dir (BuildDir) { | 
|---|
|  | 80 | // Configure the compilation (Output is not relevant) | 
|---|
|  | 81 | // Use the current directory as the installation target so nothing escapes the sandbox | 
|---|
|  | 82 | // Also specify the compiler by hand | 
|---|
|  | 83 | sh "${SrcDir}/configure CXX=g++-9 CC=gcc-9 AR=gcc-ar RANLIB=gcc-ranlib --quiet" | 
|---|
|  | 84 |  | 
|---|
|  | 85 | // Configure libcfa | 
|---|
|  | 86 | sh 'make -j 8 --no-print-directory configure-libcfa' | 
|---|
|  | 87 | } | 
|---|
|  | 88 | } | 
|---|
|  | 89 | } | 
|---|
|  | 90 |  | 
|---|
|  | 91 | def Package() { | 
|---|
|  | 92 | Tools.BuildStage('Package', true) { | 
|---|
|  | 93 | dir (BuildDir) { | 
|---|
|  | 94 | sh "make VERSION=${Version} dist" | 
|---|
|  | 95 | } | 
|---|
|  | 96 | } | 
|---|
|  | 97 | } | 
|---|
|  | 98 |  | 
|---|
|  | 99 | def Test() { | 
|---|
| [8089fde] | 100 | Tools.BuildStage('Test', true) { | 
|---|
| [8e58264] | 101 | dir (BuildDir) { | 
|---|
|  | 102 | sh "make VERSION=${Version} distcheck -j 8" | 
|---|
|  | 103 | } | 
|---|
|  | 104 | } | 
|---|
|  | 105 | } | 
|---|
|  | 106 |  | 
|---|
|  | 107 | def Archive() { | 
|---|
| [8089fde] | 108 | Tools.BuildStage('Archive', true) { | 
|---|
|  | 109 | dir (BuildDir) { | 
|---|
|  | 110 | archiveArtifacts artifacts: "cfa-cc-*.tar.gz", fingerprint: true | 
|---|
|  | 111 | } | 
|---|
| [8e58264] | 112 | } | 
|---|
|  | 113 | } | 
|---|
|  | 114 |  | 
|---|
| [4011b98] | 115 |  | 
|---|
|  | 116 | //=========================================================================================================== | 
|---|
|  | 117 | // Helper classes/variables/routines | 
|---|
|  | 118 | //=========================================================================================================== | 
|---|
|  | 119 | def prepare_build() { | 
|---|
|  | 120 | // prepare the properties | 
|---|
|  | 121 | properties ([                                                                                                   \ | 
|---|
|  | 122 | buildDiscarder(logRotator(                                                                              \ | 
|---|
|  | 123 | artifactDaysToKeepStr: '',                                                                      \ | 
|---|
|  | 124 | artifactNumToKeepStr: '',                                                                       \ | 
|---|
|  | 125 | daysToKeepStr: '730',                                                                           \ | 
|---|
|  | 126 | numToKeepStr: '1000'                                                                            \ | 
|---|
|  | 127 | )),                                                                                                             \ | 
|---|
|  | 128 | [$class: 'ParametersDefinitionProperty',                                                                \ | 
|---|
|  | 129 | parameterDefinitions: [                                                                         \ | 
|---|
| [782d479] | 130 | [$class: 'StringParameterDefinition',                                           \ | 
|---|
| [c3d3c22] | 131 | description: 'The git commit to checkout',                              \ | 
|---|
|  | 132 | name: 'GitRef',                                                                 \ | 
|---|
| [782d479] | 133 | defaultValue: '',                                                               \ | 
|---|
| [4011b98] | 134 | ],                                                                                              \ | 
|---|
| [8fe6040] | 135 | [$class: 'StringParameterDefinition',                                           \ | 
|---|
|  | 136 | description: 'Build Number to put into the version',                    \ | 
|---|
|  | 137 | name: 'Build',                                                                  \ | 
|---|
|  | 138 | defaultValue: '0',                                                              \ | 
|---|
|  | 139 | ],                                                                                              \ | 
|---|
| [4011b98] | 140 | ], | 
|---|
|  | 141 | ]]) | 
|---|
|  | 142 |  | 
|---|
| [4b138dd] | 143 | // It's unfortunate but it looks like we need to checkout the entire repo just to get | 
|---|
|  | 144 | // - the pretty git printer | 
|---|
|  | 145 | // - Jenkins.tools | 
|---|
|  | 146 | checkout scm | 
|---|
|  | 147 |  | 
|---|
|  | 148 | Tools = load "Jenkins/tools.groovy" | 
|---|
|  | 149 |  | 
|---|
| [c3d3c22] | 150 | currentBuild.description = "Distributing Tarball" | 
|---|
|  | 151 | def ref = params.GitRef ? params.GitRef : "HEAD" | 
|---|
|  | 152 | echo "Distributing git commit ${ref}" | 
|---|
| [f78ead5] | 153 |  | 
|---|
| [8fe6040] | 154 | return [params.GitRef, params.Build] | 
|---|
| [6855d14] | 155 | } | 
|---|
| [4011b98] | 156 |  | 
|---|