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