forked from amzn/hawktracer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
260 lines (218 loc) · 7.57 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import groovy.transform.InheritConstructors
String libTestOutFile = 'tests/lib/hawktracer_tests.xml'
String parserTestOutFile = 'tests/parser/hawktracer_parser_tests.xml'
stage('Linux') {
def linuxBuild = new LinuxBuild(this, 'Linux')
.withDebugBuild()
.withCodeCoverage()
.withTests()
.withAsan()
runBuild(linuxBuild, 'ignite-linux', 'ignite-linux')
}
stage('OSX') {
def osxBuild = new LinuxBuild(this, 'OSX')
.withDebugBuild()
.withTests()
withEnv (['PATH+MAVEN=/usr/local/bin']) {
runBuild(osxBuild, 'hawktracer-osx', 'hawktracer-osx')
}
}
stage('Windows') {
def winBuild = new MSVCBuild(this, 'MSVC')
.withTests()
runBuild(winBuild, 'ignite-windows', 'ignite-windows')
}
stage('Raspberry PI') {
def rpiBuild = new RaspberryBuild(this, 'Raspberry PI')
.withToolchain('../rpi-toolchain.cmake')
.withInitialCacheFile('../TryRunResults.cmake')
.withBenchmarks()
runBuild(rpiBuild, 'ignite-build', 'hawktracer-rpi')
}
def runBuild(HTBuild htBuild, String buildNode, String testNode) {
stage(htBuild.getName()) {
boolean sameNode = testNode == buildNode
try {
node(buildNode) {
stage(htBuild.getName() + ': checkout') {
checkout scm
}
stage(htBuild.getName() + ': configure') {
htBuild.configure()
}
stage(htBuild.getName() + ': build') {
htBuild.build()
}
if (!sameNode) htBuild.stashBuildArtifacts(testNode + '-build-artifacts')
}
node (testNode) {
if (!sameNode) unstash testNode + '-build-artifacts'
if (htBuild.testsEnabled) {
stage(htBuild.getName() + ': run tests') {
htBuild.runTests()
}
}
if (htBuild.benchmarksEnabled) {
stage(htBuild.getName() + ': run benchmarks') {
htBuild.runBenchmarks()
}
}
if (!sameNode) {
htBuild.stashReports(htBuild.getName() + '-reports')
deleteDir()
}
}
node (buildNode) {
if (!sameNode) unstash htBuild.getName() + '-reports'
htBuild.publishReports()
}
} catch (exc) {
echo 'Build failed: ' + exc.toString()
echo 'Message: ' + exc.getMessage()
echo 'CallStack: ' + exc.getStackTrace()
error("Build failed.")
} finally {
node(buildNode) {
deleteDir()
}
}
}
}
abstract class HTBuild {
protected String cmakeArgs = ' -DENABLE_EXAMPLES=ON -DENABLE_BENCHMARKS=ON'
protected final context
protected boolean coverageEnabled
protected String name
public boolean testsEnabled
public boolean benchmarksEnabled
HTBuild(context, name) {
this.context = context
this.coverageEnabled = false
this.testsEnabled = false
this.benchmarksEnabled = false
this.name = name
}
def getName() {
return name
}
def withToolchain(String toolchainPath) {
cmakeArgs += ' -DCMAKE_TOOLCHAIN_FILE=' + toolchainPath
return this
}
def withInitialCacheFile(String cacheFile) {
cmakeArgs += ' -C ' + cacheFile
return this
}
def withDebugBuild() {
cmakeArgs += ' -DCMAKE_BUILD_TYPE=Debug'
return this
}
def withBenchmarks() {
cmakeArgs += ' -DENABLE_BENCHMARKS=ON'
this.benchmarksEnabled = true
return this
}
def withCodeCoverage() {
cmakeArgs += ' -DENABLE_CODE_COVERAGE=ON'
coverageEnabled = true
return this
}
def withTests() {
cmakeArgs += ' -DENABLE_TESTS=ON'
testsEnabled = true
return this
}
def withAsan() {
cmakeArgs += ' -DENABLE_ASAN=ON'
return this
}
def publishReports() {
context.stage(name + ': publish reports') {
if (testsEnabled) {
context.junit 'tests/**/*.xml'
}
if (coverageEnabled) {
context.step([$class: 'CoberturaPublisher', coberturaReportFile: 'coverage.xml'])
}
if (benchmarksEnabled) {
// TODO publish benchmark results
}
}
}
def stashBuildArtifacts(String stashName) {}
def stashReports(String stashName) {}
abstract def configure()
abstract def build()
abstract def runTests()
abstract def runBenchmarks()
}
@InheritConstructors
class LinuxBuild extends HTBuild {
def configure() {
context.sh 'cmake ' + this.cmakeArgs + ' .'
}
def build() {
context.sh 'make -j 2'
}
def runTests() {
context.sh 'make test CTEST_OUTPUT_ON_FAILURE=1'
if (coverageEnabled) {
context.sh 'gcovr -r . --exclude=examples/* --exclude=tests/* --exclude=benchmarks/* --html --xml -o coverage.xml'
}
}
def runBenchmarks() {
context.sh 'LD_LIBRARY_PATH=./lib ./benchmarks/hawktracer_benchmarks --benchmark_format=json --benchmark_out=benchmark.json'
}
def stashBuildArtifacts(String stashName) {
String buildArtifacts = 'lib/libhawktracer.so,'
if (benchmarksEnabled) {
buildArtifacts += 'benchmarks/hawktracer_benchmarks,'
}
if (testsEnabled) {
buildArtifacts += 'tests/lib/hawktracer_test_gtest,'
buildArtifacts += 'tests/lib/hawktracer_test_destroy_timeline_after_uninit,'
buildArtifacts += 'tests/parser/hawktracer_test_parser,'
}
context.stash includes: buildArtifacts, name: stashName
}
def stashReports(String stashName) {
String reports = ''
if (benchmarksEnabled) {
reports += 'benchmark.json,'
}
if (testsEnabled) {
reports += context.libTestOutFile + ',' + context.parserTestOutFile
}
context.stash includes: reports, name: stashName
}
}
@InheritConstructors
class MSVCBuild extends HTBuild {
def configure() {
context.bat 'cmake ' + this.cmakeArgs + ' .'
}
def build() {
context.bat 'msbuild /p:Configuration=Release HawkTracer.sln'
}
def runTests() {
context.bat 'copy tests\\googletest\\googlemock\\gtest\\Release\\gtest.dll tests\\lib\\Release\\'
context.bat 'copy lib\\Release\\hawktracer.dll tests\\lib\\Release\\'
context.bat 'copy tests\\googletest\\googlemock\\gtest\\Release\\gtest.dll tests\\parser\\Release\\'
context.bat 'copy lib\\Release\\hawktracer.dll tests\\parser\\Release\\'
context.bat 'ctest --verbose'
}
def runBenchmarks() {
context.bat 'copy lib\\Release\\hawktracer.dll benchmarks\\Release\\'
context.bat './benchmarks/hawktracer_benchmarks --benchmark_format=json --benchmark_out=benchmark.json'
// TODO: we should have common step to add platform to benchmark.json
}
}
@InheritConstructors
class RaspberryBuild extends LinuxBuild {
@Override
def runTests() {
context.sh 'LD_LIBRARY_PATH=./lib ./tests/lib/hawktracer_test_gtest --gtest_output=xml:' + context.libTestOutFile
context.sh 'LD_LIBRARY_PATH=./lib ./tests/parser/hawktracer_test_parser --gtest_output=xml:' + context.parserTestOutFile
context.sh 'LD_LIBRARY_PATH=./lib ./tests/lib/hawktracer_test_destroy_timeline_after_uninit'
}
}