-
Notifications
You must be signed in to change notification settings - Fork 298
/
common.groovy
419 lines (375 loc) · 13.3 KB
/
common.groovy
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
def isWindows() {
return !isUnix()
}
void standardSetup() {
echo "${env.NODE_NAME}"
if (isWindows()) {
echo "PATH: ${env.PATH}"
bat "git clean -ffdx -e OMSetup && git submodule foreach --recursive \"git clean -ffdx\""
return
}
// Jenkins cleans with -fdx; --ffdx is needed to remove git repositories
sh "git clean -ffdx && git submodule foreach --recursive git clean -ffdx"
}
def numPhysicalCPU() {
if (env.JENKINS_NUM_PHYSICAL_CPU) {
return env.JENKINS_NUM_PHYSICAL_CPU
}
if (isWindows())
{
return env.NUMBER_OF_PROCESSORS.toInteger() / 2 ?: 1
}
def uname = sh script: 'uname', returnStdout: true
if (uname.startsWith("Darwin")) {
env.JENKINS_NUM_PHYSICAL_CPU = sh (
script: 'sysctl hw.physicalcpu_max | cut -d" " -f2',
returnStdout: true
).trim().toInteger() ?: 1
} else {
env.JENKINS_NUM_PHYSICAL_CPU = sh (
script: 'lscpu -p | egrep -v "^#" | sort -u -t, -k 2,4 | wc -l',
returnStdout: true
).trim().toInteger() ?: 1
}
return env.JENKINS_NUM_PHYSICAL_CPU
}
def numLogicalCPU() {
if (env.JENKINS_NUM_LOGICAL_CPU) {
return env.JENKINS_NUM_LOGICAL_CPU
}
if (isWindows())
{
return env.NUMBER_OF_PROCESSORS.toInteger() ?: 1
}
def uname = sh script: 'uname', returnStdout: true
if (uname.startsWith("Darwin")) {
env.JENKINS_NUM_LOGICAL_CPU = sh (
script: 'sysctl hw.logicalcpu_max | cut -d" " -f2',
returnStdout: true
).trim().toInteger() ?: 1
} else {
env.JENKINS_NUM_LOGICAL_CPU = sh (
script: 'lscpu -p | egrep -v "^#" | wc -l',
returnStdout: true
).trim().toInteger() ?: 1
}
return env.JENKINS_NUM_LOGICAL_CPU
}
void partest(cache=true, extraArgs='') {
if (isWindows()) {
bat ("""
set OMDEV=C:\\OMDev
echo on
(
echo export MSYS_WORKSPACE="`cygpath '${WORKSPACE}'`"
echo echo MSYS_WORKSPACE: \${MSYS_WORKSPACE}
echo export OPENMODELICAHOME="\${MSYS_WORKSPACE}/build"
echo export OPENMODELICALIBRARY="${MSYS_WORKSPACE}\\build\\lib\\omlibrary"
echo cd ${MSYS_WORKSPACE}/testsuite/partest
echo time perl ./runtests.pl -j8 -nocolour -with-xml
echo CODE=\$?
echo if test "\$CODE\" = 0 -o "\$CODE" = 7; then
echo cp -f ../runtest.db.* "${env.RUNTESTDB}/"
echo fi
echo if test "\$CODE" = 0 -o "\$CODE" = 7; then
echo exit 0
echo else
echo exit $CODE
echo fi
) > runTestWindows.sh
set MSYSTEM=MINGW64
set MSYS2_PATH_TYPE=inherit
%OMDEV%\\tools\\msys\\usr\\bin\\sh --login -i -c "cd `cygpath '${WORKSPACE}'` && chmod +x runTestWindows.sh && ./runTestWindows.sh && rm -f ./runTestWindows.sh"
""")
} else {
sh "rm -f omc-diff.skip && ${makeCommand()} -C testsuite/difftool clean && ${makeCommand()} --output-sync -C testsuite/difftool"
sh 'build/bin/omc-diff -v1.4'
sh ("""#!/bin/bash -x
ulimit -t 1500
ulimit -v 6291456 # Max 6GB per process
cd testsuite/partest
./runtests.pl -j${numPhysicalCPU()} -nocolour -with-xml ${extraArgs}
CODE=\$?
test \$CODE = 0 -o \$CODE = 7 || exit 1
"""
+ (cache ?
"""
if test \$CODE = 0; then
mkdir -p "${env.RUNTESTDB}/"
cp ../runtest.db.* "${env.RUNTESTDB}/"
fi
""" : ''))
}
junit 'testsuite/partest/result.xml'
}
void patchConfigStatus() {
if (isUnix())
{
// Running on nodes with different paths for the workspace
sh 'sed -i.bak "s,--with-ombuilddir=[A-Za-z0-9./_-]*,--with-ombuilddir=`pwd`/build," config.status OMCompiler/config.status'
}
}
void makeLibsAndCache(libs='core') {
if (isWindows())
{
// do nothing
} else {
// If we don't have any result, copy to the master to get a somewhat decent cache
sh "cp -f ${env.RUNTESTDB}/${cacheBranchEscape()}/runtest.db.* testsuite/ || " +
"cp -f ${env.RUNTESTDB}/master/runtest.db.* testsuite/ || true"
// env.WORKSPACE is null in the docker agent, so link the svn/git cache afterwards
sh "mkdir -p '${env.LIBRARIES}/om-pkg-cache'"
sh "mkdir -p testsuite/libraries-for-testing/.openmodelica/"
sh "ln -s '${env.LIBRARIES}/om-pkg-cache' testsuite/libraries-for-testing/.openmodelica/"
generateTemplates()
sh "touch omc.skip"
def cmd = "${makeCommand()} -j${numLogicalCPU()} --output-sync libs-for-testing ReferenceFiles omc-diff"
if (env.SHARED_LOCK) {
lock(env.SHARED_LOCK) {
sh cmd
}
} else {
sh cmd
}
}
}
void buildOMC(CC, CXX, extraFlags) {
standardSetup()
if (isWindows()) {
bat ("""
set OMDEV=C:\\OMDev
echo on
(
echo export MSYS_WORKSPACE="`cygpath '${WORKSPACE}'`"
echo echo MSYS_WORKSPACE: \${MSYS_WORKSPACE}
echo cd \${MSYS_WORKSPACE}
echo export MAKETHREADS=-j16
echo set -e
echo export OPENMODELICAHOME="\${MSYS_WORKSPACE}/build"
echo export OPENMODELICALIBRARY="\${MSYS_WORKSPACE}/build/lib/omlibrary"
echo time make -f Makefile.omdev.mingw \${MAKETHREADS} omc testsuite-depends
echo cd \${MSYS_WORKSPACE}
echo make -f Makefile.omdev.mingw \${MAKETHREADS} BUILDTYPE=Release all-runtimes
echo echo Check that omc can be started and a model can be build for NF OF with runtimes C Cpp FMU
echo ./build/bin/omc --version
echo mkdir .sanity-check
echo cd .sanity-check
echo cp ../testsuite/sanity-check/testSanity.mos .
echo ../build/bin/omc --linearizationDumpLanguage=matlab testSanity.mos
echo export PATH=\$PATH:../build/bin/:../build/lib/omc/omsicpp:../build/lib/omc/cpp
echo ./M
echo ./M -l=1.0
echo ls linear_M.m
echo ls M.fmu
echo rm -rf M* OMCppM* linear_M*
echo ../build/bin/omc --simCodeTarget=Cpp testSanity.mos
echo ./M
echo ls M.fmu
echo rm -rf M* OMCppM*
echo cd ..
echo rm -rf .sanity-check
echo cd testsuite/flattening/libraries/biochem
echo ../../../rtest --return-with-error-code EnzMM.mos
) > buildOMCWindows.sh
set MSYSTEM=MINGW64
set MSYS2_PATH_TYPE=inherit
%OMDEV%\\tools\\msys\\usr\\bin\\sh --login -i -c "cd `cygpath '${WORKSPACE}'` && chmod +x buildOMCWindows.sh && ./buildOMCWindows.sh && rm -f ./buildOMCWindows.sh"
""")
} else {
sh 'autoconf'
// Note: Do not use -march=native since we might use an incompatible machine in later stages
sh "./configure CC='${CC}' CXX='${CXX}' FC=gfortran CFLAGS=-Os --with-cppruntime --without-omc --without-omlibrary --with-omniORB --enable-modelica3d ${extraFlags}"
// OMSimulator requires HOME to be set and writeable
sh "HOME='${env.WORKSPACE}' ${makeCommand()} -j${numPhysicalCPU()} --output-sync omc omc-diff omsimulator"
sh 'find build/lib/*/omc/ -name "*.so" -exec strip {} ";"'
sh '''
mv build build.sanity-check
mkdir .sanity-check
cd .sanity-check
echo 'loadString("model M end M;");getErrorString();buildModel(M);getErrorString();' > test.mos
cat test.mos
../build.sanity-check/bin/omc test.mos
./M
cd ..
mv build.sanity-check build
rm -rf .sanity-check
'''
sh "cd OMCompiler/Compiler/boot && ./find-unused-import.sh ../*/*.mo"
}
}
void buildGUI(stash, isQt5) {
if (isWindows()) {
bat ("""
set OMDEV=C:\\OMDev
echo on
(
echo export MSYS_WORKSPACE="`cygpath '${WORKSPACE}'`"
echo echo MSYS_WORKSPACE: \${MSYS_WORKSPACE}
echo cd \${MSYS_WORKSPACE}
echo export MAKETHREADS=-j16
echo set -e
echo export OPENMODELICAHOME="\${MSYS_WORKSPACE}/build"
echo export OPENMODELICALIBRARY="\${MSYS_WORKSPACE}/build/lib/omlibrary"
echo time make -f Makefile.omdev.mingw \${MAKETHREADS} qtclients
echo echo Check that at least OMEdit can be started
echo ./build/bin/OMEdit --help
) > buildGUIWindows.sh
set MSYSTEM=MINGW64
set MSYS2_PATH_TYPE=inherit
%OMDEV%\\tools\\msys\\usr\\bin\\sh --login -i -c "cd `cygpath '${WORKSPACE}'` && chmod +x buildGUIWindows.sh && ./buildGUIWindows.sh && rm -f ./buildGUIWindows.sh"
""")
} else {
if (stash) {
standardSetup()
unstash stash
}
sh 'autoconf'
if (stash) {
patchConfigStatus()
}
sh 'CONFIG=`./config.status --config` && ./configure `eval $CONFIG`'
// compile OMSens_Qt for Qt5
if (isQt5) {
sh "touch omc.skip omc-diff.skip ReferenceFiles.skip omsimulator.skip && ${makeCommand()} -q omc omc-diff ReferenceFiles omsimulator" // Pretend we already built omc since we already did so
} else {
sh "touch omc.skip omc-diff.skip ReferenceFiles.skip omsimulator.skip omsens_qt.skip && ${makeCommand()} -q omc omc-diff ReferenceFiles omsimulator omsens_qt" // Pretend we already built omc since we already did so
}
sh "${makeCommand()} -j${numPhysicalCPU()} --output-sync" // Builds the GUI files
}
}
void buildAndRunOMEditTestsuite(stash) {
if (isWindows()) {
bat ("""
set OMDEV=C:\\OMDev
echo on
(
echo export MSYS_WORKSPACE="`cygpath '${WORKSPACE}'`"
echo echo MSYS_WORKSPACE: \${MSYS_WORKSPACE}
echo cd \${MSYS_WORKSPACE}
echo export MAKETHREADS=-j16
echo set -e
echo export OPENMODELICAHOME="\${MSYS_WORKSPACE}/build"
echo export OPENMODELICALIBRARY="\${MSYS_WORKSPACE}/build/lib/omlibrary"
echo time make -f Makefile.omdev.mingw \${MAKETHREADS} omedit-testsuite
echo export "APPDATA=\${PWD}/testsuite/libraries-for-testing"
echo cd build/bin
echo ./RunOMEditTestsuite.sh
) > buildOMEditTestsuiteWindows.sh
set MSYSTEM=MINGW64
set MSYS2_PATH_TYPE=inherit
%OMDEV%\\tools\\msys\\usr\\bin\\sh --login -i -c "cd `cygpath '${WORKSPACE}'` && chmod +x buildOMEditTestsuiteWindows.sh && ./buildOMEditTestsuiteWindows.sh && rm -f ./buildOMEditTestsuiteWindows.sh"
""")
} else {
if (stash) {
standardSetup()
unstash stash
}
sh 'autoconf'
if (stash) {
patchConfigStatus()
}
sh 'CONFIG=`./config.status --config` && ./configure `eval $CONFIG`'
sh "touch omc.skip omc-diff.skip ReferenceFiles.skip omsimulator.skip omedit.skip omplot.skip && ${makeCommand()} -q omc omc-diff ReferenceFiles omsimulator omedit omplot" // Pretend we already built omc since we already did so
sh "${makeCommand()} -j${numPhysicalCPU()} --output-sync omedit-testsuite" // Builds the OMEdit testsuite
sh label: 'RunOMEditTestsuite', script: '''
HOME="\$PWD/testsuite/libraries-for-testing"
cd build/bin
xvfb-run ./RunOMEditTestsuite.sh
'''
}
}
void generateTemplates() {
if (isWindows()) {
// do nothing
} else {
patchConfigStatus()
// Runs Susan again, for bootstrapping tests, etc
sh "${makeCommand()} -C OMCompiler/Compiler/Template/ -f Makefile.in OMC=\$PWD/build/bin/omc"
sh 'cd OMCompiler && ./config.status'
sh './config.status'
}
}
def getVersion() {
if (isWindows()) {
return (bat (script: 'set OMDEV=C:\\OMDev && set MSYSTEM=MINGW64 && set MSYS2_PATH_TYPE=inherit && %OMDEV%\\tools\\msys\\usr\\bin\\sh --login -i -c "build/bin/omc --version | grep -o \"v[0-9]\\+[.][0-9]\\+[.][0-9]\\+[^ ]*\""', returnStdout: true)).replaceAll("\\s","")
} else {
return (sh (script: 'build/bin/omc --version | grep -o "v[0-9]\\+[.][0-9]\\+[.][0-9]\\+[^ ]*"', returnStdout: true)).replaceAll("\\s","")
}
}
void compliance() {
if (isWindows()) {
// do nothing for now
} else {
standardSetup()
unstash 'omc-clang'
makeLibsAndCache('all')
sh 'HOME=$PWD/testsuite/libraries-for-testing/ build/bin/omc -g=MetaModelica build/share/doc/omc/testmodels/ComplianceSuite.mos'
sh "mv ${env.COMPLIANCEPREFIX}.html ${env.COMPLIANCEPREFIX}-current.html"
sh "test -f ${env.COMPLIANCEPREFIX}.xml"
// Only publish openmodelica-current.html if we are running master
sh "cp -p ${env.COMPLIANCEPREFIX}-current.html ${env.COMPLIANCEPREFIX}${cacheBranch()=='master' ? '' : ('-' + cacheBranchEscape())}-${getVersion()}.html"
sh "test ! '${cacheBranch()}' = 'master' || rm -f ${env.COMPLIANCEPREFIX}-current.html"
stash name: "${env.COMPLIANCEPREFIX}", includes: "${env.COMPLIANCEPREFIX}-*.html"
archiveArtifacts "${env.COMPLIANCEPREFIX}*${getVersion()}.html, ${env.COMPLIANCEPREFIX}.failures"
// get rid of freaking %
sh "sed -i.bak 's/%/\\%/g' ${env.COMPLIANCEPREFIX}.ignore.xml && sed -i.bak 's/[^[:print:]]/ /g' ${env.COMPLIANCEPREFIX}.ignore.xml"
junit "${env.COMPLIANCEPREFIX}.ignore.xml"
}
}
def cacheBranch() {
return "${env.CHANGE_TARGET ?: env.GIT_BRANCH}"
}
def cacheBranchEscape() {
def name = (cacheBranch()).replace('maintenance/v','')
name = name.replace('/','-')
return name
}
def tagName() {
def name = env.TAG_NAME ?: cacheBranchEscape()
return name == "master" ? "latest" : name
}
def makeCommand() {
// OSX uses gmake as the GNU make program
return env.GMAKE ?: "make"
}
def shouldWeBuildOSX() {
if (isPR()) {
if (pullRequest.labels.contains("CI/Build OSX")) {
return true
}
}
return params.BUILD_OSX
}
def shouldWeBuildMINGW() {
if (isPR()) {
if (pullRequest.labels.contains("CI/Build MINGW")) {
return true
}
}
return params.BUILD_MINGW
}
def shouldWeRunTests() {
if (isPR()) {
def skipTestsFilesList = [".*[.]md",
"OMEdit/.*",
"OMNotebook/.*",
"OMPlot/.*",
"OMShell/.*"]
def runTest = false
for (commitFile in pullRequest.files) {
def results = skipTestsFilesList.findAll {element -> commitFile.filename.matches(element)}
if (results.size() > 0) {
continue
} else {
runTest = true
break;
}
}
return runTest
}
return true
}
def isPR() {
return env.CHANGE_ID ? true : false
}
return this