blob: fe8d8a7b04b5db421215ab9231f20dcd20945b53 [file] [log] [blame]
Jan Kundrátd9d26a92018-02-22 12:49:21 +01001#!/bin/bash
Jan Kundrát73e3bf22019-02-28 15:44:02 +01002
3set -eux -o pipefail
Jan Kundráte6c0f5c2020-04-08 00:08:28 +02004shopt -s failglob extglob
Jan Kundrát73e3bf22019-02-28 15:44:02 +01005
6ZUUL_JOB_NAME=$(jq < ~/zuul-env.json -r '.job')
Jan Kundrát8a914662019-02-28 18:11:55 +01007ZUUL_TENANT=$(jq < ~/zuul-env.json -r '.tenant')
Jan Kundrát73e3bf22019-02-28 15:44:02 +01008ZUUL_PROJECT_SRC_DIR=$HOME/$(jq < ~/zuul-env.json -r '.project.src_dir')
9ZUUL_PROJECT_SHORT_NAME=$(jq < ~/zuul-env.json -r '.project.short_name')
Jan Kundrátdba63582019-06-06 13:09:30 +020010ZUUL_GERRIT_HOSTNAME=$(jq < ~/zuul-env.json -r '.project.canonical_hostname')
Jan Kundrát73e3bf22019-02-28 15:44:02 +010011
12CI_PARALLEL_JOBS=$(grep -c '^processor' /proc/cpuinfo)
13CMAKE_OPTIONS=""
14CFLAGS=""
15CXXFLAGS=""
16LDFLAGS=""
17
18if [[ $ZUUL_JOB_NAME =~ .*-clang.* ]]; then
19 export CC=clang
20 export CXX=clang++
21 export LD=clang
22 export CXXFLAGS="-stdlib=libc++"
23fi
24
25if [[ $ZUUL_JOB_NAME =~ .*-ubsan ]]; then
26 export CFLAGS="-fsanitize=undefined ${CFLAGS}"
27 export CXXFLAGS="-fsanitize=undefined ${CXXFLAGS}"
28 export LDFLAGS="-fsanitize=undefined ${LDFLAGS}"
29fi
30
31if [[ $ZUUL_JOB_NAME =~ .*-asan ]]; then
32 export CFLAGS="-fsanitize=address ${CFLAGS}"
33 export CXXFLAGS="-fsanitize=address ${CXXFLAGS}"
34 export LDFLAGS="-fsanitize=address ${LDFLAGS}"
Jan Kundrát107b0892020-04-20 16:08:17 +020035
36 if [[ $ZUUL_JOB_NAME =~ f31-.* ]]; then
37 # On Fedora 31, libev's ev_realloc looks fishy for sysrepoctl & sysrepocfg
38 export LSAN_OPTIONS="suppressions=${ZUUL_PROJECT_SRC_DIR}/ci/lsan.supp:print_suppressions=0"
39 fi
Jan Kundrát73e3bf22019-02-28 15:44:02 +010040fi
41
Jan Kundrát7b7c8232019-03-13 14:04:06 +010042if [[ $ZUUL_JOB_NAME =~ .*-tsan ]]; then
43 export CFLAGS="-fsanitize=thread ${CFLAGS}"
44 export CXXFLAGS="-fsanitize=thread ${CXXFLAGS}"
45 export LDFLAGS="-fsanitize=thread ${LDFLAGS}"
46fi
47
Jan Kundrátcf5c6362020-01-16 22:54:47 +010048if [[ $ZUUL_JOB_NAME =~ -gcc$ ]]; then
49 # Python and ASAN (and, presumably, all other sanitizers) are tricky to use from a Python DSO,
50 # I was, e.g., getting unrelated failures from libyang's thread-local global access (ly_errno)
51 # even when correctly injecting the ASAN runtime via LD_PRELOAD. Let's just give up and only
52 # enable this when not using sanitizers.
53 # I'm still adding some code to CMakeLists.txt which makes it work locally (Jan's dev environment
54 # with GCC8 and ASAN, Gentoo).
55 CMAKE_OPTIONS="${CMAKE_OPTIONS} -DWITH_PYTHON_BINDINGS=ON"
56fi
57
Jan Kundráte6c0f5c2020-04-08 00:08:28 +020058if [[ $ZUUL_JOB_NAME =~ .*-cover.* ]]; then
59 export CFLAGS="${CFLAGS} --coverage"
60 export CXXFLAGS="${CXXFLAGS} --coverage"
61 export LDFLAGS="${LDFLAGS} --coverage"
62fi
63
Jan Kundrát73e3bf22019-02-28 15:44:02 +010064PREFIX=~/target
65mkdir ${PREFIX}
66BUILD_DIR=~/build
67mkdir ${BUILD_DIR}
68export PATH=${PREFIX}/bin:$PATH
69export LD_LIBRARY_PATH=${PREFIX}/lib64:${PREFIX}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
Jan Kundrát0e783ac2019-10-30 12:29:17 +010070export PKG_CONFIG_PATH=${PREFIX}/lib64/pkgconfig:${PREFIX}/lib/pkgconfig:${PREFIX}/share/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
Jan Kundrát73e3bf22019-02-28 15:44:02 +010071
Jan Kundrát566d33c2020-04-17 14:33:37 +020072ARTIFACT_URL=$(jq < ~/zuul-env.json -r '[.artifacts[]? | select(.name == "tarball") | select(.project == "CzechLight/dependencies")][-1]?.url + ""')
Jan Kundrát73e3bf22019-02-28 15:44:02 +010073
74DEP_SUBMODULE_COMMIT=$(git ls-tree -l master submodules/dependencies | cut -d ' ' -f 3)
75
76if [[ -z "${ARTIFACT_URL}" ]]; then
77 # fallback to a promoted artifact
Jan Kundrát88cfbdc2020-04-14 14:16:07 +020078 ARTIFACT_URL="https://object-store.cloud.muni.cz/swift/v1/ci-artifacts-${ZUUL_TENANT}/${ZUUL_GERRIT_HOSTNAME}/CzechLight/dependencies/${ZUUL_JOB_NAME%%-cover?(-previous|-diff)}/${DEP_SUBMODULE_COMMIT}.tar.xz"
Jan Kundrát73e3bf22019-02-28 15:44:02 +010079fi
80
81ARTIFACT_FILE=$(basename ${ARTIFACT_URL})
82DEP_HASH_FROM_ARTIFACT=$(echo "${ARTIFACT_FILE}" | sed -e 's/^czechlight-dependencies-//' -e 's/\.tar\.xz$//')
83if [[ "${DEP_HASH_FROM_ARTIFACT}" != "${DEP_SUBMODULE_COMMIT}" ]]; then
84 echo "Mismatched artifact: HEAD of ./submodules/dependencies does not match artifact commit ref"
85 exit 1
86fi
87curl ${ARTIFACT_URL} --output ${ARTIFACT_FILE}
88tar -C ${PREFIX} -xf ${ARTIFACT_FILE}
89rm ${ARTIFACT_FILE}
90
91cd ${BUILD_DIR}
92cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR}
93ninja-build
94ctest -j${CI_PARALLEL_JOBS} --output-on-failure
Jan Kundrát20c17482020-04-08 00:39:05 +020095
96if [[ $JOB_PERFORM_EXTRA_WORK == 1 ]]; then
97 ninja-build doc
98 pushd html
99 zip -r ~/zuul-output/docs/html.zip .
100 popd
101fi
Jan Kundráte6c0f5c2020-04-08 00:08:28 +0200102
103if [[ $LDFLAGS =~ .*--coverage.* ]]; then
104 gcovr -j ${CI_PARALLEL_JOBS} --object-directory ${BUILD_DIR} --root ${ZUUL_PROJECT_SRC_DIR} --xml --output ${BUILD_DIR}/coverage.xml
105fi