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 |
---|
17 | Version = '' |
---|
18 | |
---|
19 | // Local variables |
---|
20 | def err = null |
---|
21 | def log_needed = false |
---|
22 | |
---|
23 | currentBuild.result = "SUCCESS" |
---|
24 | |
---|
25 | //Wrap build to add timestamp to command line |
---|
26 | wrap([$class: 'TimestamperBuildWrapper']) { |
---|
27 | |
---|
28 | final commit, build |
---|
29 | (commit, build) = prepare_build() |
---|
30 | |
---|
31 | node('x64') { |
---|
32 | BuildDir = pwd tmp: true |
---|
33 | SrcDir = pwd tmp: false |
---|
34 | |
---|
35 | Tools.Clean() |
---|
36 | |
---|
37 | Tools.Checkout( commit ) |
---|
38 | |
---|
39 | Version = GetVersion( build ) |
---|
40 | |
---|
41 | Configure() |
---|
42 | |
---|
43 | Package() |
---|
44 | |
---|
45 | Test() |
---|
46 | |
---|
47 | Archive() |
---|
48 | } |
---|
49 | |
---|
50 | // Update the build directories when exiting the node |
---|
51 | BuildDir = pwd tmp: true |
---|
52 | SrcDir = pwd tmp: false |
---|
53 | } |
---|
54 | |
---|
55 | } |
---|
56 | |
---|
57 | //=========================================================================================================== |
---|
58 | // Main compilation routines |
---|
59 | //=========================================================================================================== |
---|
60 | def GetVersion(build) { |
---|
61 | final pver = sh( |
---|
62 | returnStdout: true, |
---|
63 | script: "sed 's/AC_INIT(\\[cfa-cc\\],\\[\\(.*\\)\\],\\[cforall@plg.uwaterloo.ca\\])/\\1/;t;d' ${SrcDir}/configure.ac" |
---|
64 | ).trim() |
---|
65 | |
---|
66 | final version = "${pver}.${build}" |
---|
67 | |
---|
68 | echo "Package Version: ${pver}" |
---|
69 | echo "Build Version: ${build}" |
---|
70 | echo "Long Version: ${version}" |
---|
71 | |
---|
72 | return version |
---|
73 | } |
---|
74 | |
---|
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() { |
---|
105 | Tools.BuildStage('Test', true) { |
---|
106 | dir (BuildDir) { |
---|
107 | sh "make VERSION=${Version} distcheck -j 8" |
---|
108 | } |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | def Archive() { |
---|
113 | Tools.BuildStage('Archive', true) { |
---|
114 | dir (BuildDir) { |
---|
115 | archiveArtifacts artifacts: "cfa-cc-*.tar.gz", fingerprint: true |
---|
116 | } |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
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: [ \ |
---|
135 | [$class: 'StringParameterDefinition', \ |
---|
136 | description: 'The git commit to checkout', \ |
---|
137 | name: 'GitRef', \ |
---|
138 | defaultValue: '', \ |
---|
139 | ], \ |
---|
140 | [$class: 'StringParameterDefinition', \ |
---|
141 | description: 'Build Number to put into the version', \ |
---|
142 | name: 'Build', \ |
---|
143 | defaultValue: '0', \ |
---|
144 | ], \ |
---|
145 | ], |
---|
146 | ]]) |
---|
147 | |
---|
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 | |
---|
155 | currentBuild.description = "Distributing Tarball" |
---|
156 | def ref = params.GitRef ? params.GitRef : "HEAD" |
---|
157 | echo "Distributing git commit ${ref}" |
---|
158 | |
---|
159 | return [params.GitRef, params.Build] |
---|
160 | } |
---|
161 | |
---|