|
| 1 | +void standardSetup() { |
| 2 | + echo "${env.NODE_NAME}" |
| 3 | + // Jenkins cleans with -fdx; --ffdx is needed to remove git repositories |
| 4 | + sh "git clean -ffdx && git submodule foreach --recursive git clean -ffdx" |
| 5 | +} |
| 6 | + |
| 7 | +def numPhysicalCPU() { |
| 8 | + def uname = sh script: 'uname', returnStdout: true |
| 9 | + if (uname.startsWith("Darwin")) { |
| 10 | + return sh ( |
| 11 | + script: 'sysctl hw.physicalcpu_max | cut -d" " -f2', |
| 12 | + returnStdout: true |
| 13 | + ).trim().toInteger() ?: 1 |
| 14 | + } else { |
| 15 | + return sh ( |
| 16 | + script: 'lscpu -p | egrep -v "^#" | sort -u -t, -k 2,4 | wc -l', |
| 17 | + returnStdout: true |
| 18 | + ).trim().toInteger() ?: 1 |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +def numLogicalCPU() { |
| 23 | + def uname = sh script: 'uname', returnStdout: true |
| 24 | + if (uname.startsWith("Darwin")) { |
| 25 | + return sh ( |
| 26 | + script: 'sysctl hw.logicalcpu_max | cut -d" " -f2', |
| 27 | + returnStdout: true |
| 28 | + ).trim().toInteger() ?: 1 |
| 29 | + } else { |
| 30 | + return sh ( |
| 31 | + script: 'lscpu -p | egrep -v "^#" | wc -l', |
| 32 | + returnStdout: true |
| 33 | + ).trim().toInteger() ?: 1 |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +void partest(cache=true, extraArgs='') { |
| 38 | + sh ("""#!/bin/bash -x |
| 39 | + ulimit -t 1500 |
| 40 | + ulimit -v 6291456 # Max 6GB per process |
| 41 | +
|
| 42 | + cd testsuite/partest |
| 43 | + ./runtests.pl -j${numPhysicalCPU()} -nocolour -with-xml ${extraArgs} |
| 44 | + CODE=\$? |
| 45 | + test \$CODE = 0 -o \$CODE = 7 || exit 1 |
| 46 | + """ |
| 47 | + + (cache ? |
| 48 | + """ |
| 49 | + if test \$CODE = 0; then |
| 50 | + mkdir -p "${env.RUNTESTDB}/" |
| 51 | + cp ../runtest.db.* "${env.RUNTESTDB}/" |
| 52 | + fi |
| 53 | + """ : '')) |
| 54 | + junit 'testsuite/partest/result.xml' |
| 55 | +} |
| 56 | + |
| 57 | +void patchConfigStatus() { |
| 58 | + // Running on nodes with different paths for the workspace |
| 59 | + sh 'sed -i "s,--with-ombuilddir=[A-Za-z0-9/_-]*,--with-ombuilddir=`pwd`/build," config.status OMCompiler/config.status' |
| 60 | +} |
| 61 | + |
| 62 | +void makeLibsAndCache(libs='core') { |
| 63 | + // If we don't have any result, copy to the master to get a somewhat decent cache |
| 64 | + sh "cp -f ${env.RUNTESTDB}/${cacheBranch()}/runtest.db.* testsuite/ || " + |
| 65 | + "cp -f ${env.RUNTESTDB}/master/runtest.db.* testsuite/ || true" |
| 66 | + // env.WORKSPACE is null in the docker agent, so link the svn/git cache afterwards |
| 67 | + sh "mkdir -p '${env.LIBRARIES}/svn' '${env.LIBRARIES}/git'" |
| 68 | + sh "find libraries" |
| 69 | + sh "ln -s '${env.LIBRARIES}/svn' '${env.LIBRARIES}/git' libraries/" |
| 70 | + generateTemplates() |
| 71 | + def cmd = "make -j${numLogicalCPU()} --output-sync omlibrary-${libs} ReferenceFiles" |
| 72 | + if (env.SHARED_LOCK) { |
| 73 | + lock(env.SHARED_LOCK) { |
| 74 | + sh cmd |
| 75 | + } |
| 76 | + } else { |
| 77 | + sh cmd |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +void buildOMC(CC, CXX, extraFlags) { |
| 82 | + standardSetup() |
| 83 | + sh 'autoconf' |
| 84 | + // Note: Do not use -march=native since we might use an incompatible machine in later stages |
| 85 | + sh "./configure CC='${CC}' CXX='${CXX}' FC=gfortran CFLAGS=-Os --with-cppruntime --without-omc --without-omlibrary --with-omniORB --enable-modelica3d ${extraFlags}" |
| 86 | + // OMSimulator requires HOME to be set and writeable |
| 87 | + sh "HOME='${env.WORKSPACE}' make -j${numPhysicalCPU()} --output-sync omc omc-diff omsimulator" |
| 88 | + sh 'find build/lib/*/omc/ -name "*.so" -exec strip {} ";"' |
| 89 | +} |
| 90 | + |
| 91 | +void buildGUI(stash) { |
| 92 | + standardSetup() |
| 93 | + if (stash) { |
| 94 | + unstash stash |
| 95 | + } |
| 96 | + sh 'autoconf' |
| 97 | + patchConfigStatus() |
| 98 | + sh 'CONFIG=`./config.status --config` && ./configure `eval $CONFIG`' |
| 99 | + sh 'touch omc.skip omc-diff.skip ReferenceFiles.skip omsimulator.skip && make -q omc omc-diff ReferenceFiles omsimulator' // Pretend we already built omc since we already did so |
| 100 | + sh "make -j${numPhysicalCPU()} --output-sync" // Builds the GUI files |
| 101 | +} |
| 102 | + |
| 103 | +void generateTemplates() { |
| 104 | + patchConfigStatus() |
| 105 | + // Runs Susan again, for bootstrapping tests, etc |
| 106 | + sh 'make -C OMCompiler/Compiler/Template/ -f Makefile.in OMC=$PWD/build/bin/omc' |
| 107 | + sh 'cd OMCompiler && ./config.status' |
| 108 | + sh './config.status' |
| 109 | +} |
| 110 | + |
| 111 | +def getVersion() { |
| 112 | + return (sh (script: 'build/bin/omc --version | grep -o "v[0-9]\\+[.][0-9]\\+[.][0-9]\\+[^ ]*"', returnStdout: true)).replaceAll("\\s","") |
| 113 | +} |
| 114 | + |
| 115 | +void compliance() { |
| 116 | + standardSetup() |
| 117 | + unstash 'omc-clang' |
| 118 | + makeLibsAndCache('all') |
| 119 | + sh 'build/bin/omc -g=MetaModelica build/share/doc/omc/testmodels/ComplianceSuite.mos' |
| 120 | + sh "mv ${env.COMPLIANCEPREFIX}.html ${env.COMPLIANCEPREFIX}-current.html" |
| 121 | + sh "test -f ${env.COMPLIANCEPREFIX}.xml" |
| 122 | + // Only publish openmodelica-current.html if we are running master |
| 123 | + sh "cp -p ${env.COMPLIANCEPREFIX}-current.html ${env.COMPLIANCEPREFIX}${cacheBranch()=='master' ? '' : ('-' + cacheBranch()).replace('/','-')}-${getVersion()}.html" |
| 124 | + sh "test ! '${cacheBranch()}' = 'master' || rm -f ${env.COMPLIANCEPREFIX}-current.html" |
| 125 | + stash name: "${env.COMPLIANCEPREFIX}", includes: "${env.COMPLIANCEPREFIX}-*.html" |
| 126 | + archiveArtifacts "${env.COMPLIANCEPREFIX}*${getVersion()}.html, ${env.COMPLIANCEPREFIX}.failures" |
| 127 | + // get rid of freaking % |
| 128 | + sh "sed -i.bak 's/%/\\%/g' ${env.COMPLIANCEPREFIX}.ignore.xml && sed -i.bak 's/[^[:print:]]/ /g' ${env.COMPLIANCEPREFIX}.ignore.xml" |
| 129 | + junit "${env.COMPLIANCEPREFIX}.ignore.xml" |
| 130 | +} |
| 131 | + |
| 132 | +def cacheBranch() { |
| 133 | + return "${env.CHANGE_TARGET ?: env.GIT_BRANCH}" |
| 134 | +} |
| 135 | + |
| 136 | +def tagName() { |
| 137 | + def name = env.TAG_NAME ?: cacheBranch() |
| 138 | + return name == "master" ? "latest" : name |
| 139 | +} |
| 140 | + |
| 141 | +return this |
0 commit comments