blob: 7cc580dfcc68bd58bbb4954cc795478c2f874598 [file] [log] [blame]
Tomáš Pecka5123e002020-06-05 15:29:21 +02001#!/bin/bash
2
3set -eux -o pipefail
4shopt -s failglob extglob
5
6ZUUL_JOB_NAME=$(jq < ~/zuul-env.json -r '.job')
7ZUUL_TENANT=$(jq < ~/zuul-env.json -r '.tenant')
Jan Kundrát14baf2e2022-03-23 22:14:19 +01008LEAF_PROJECT_NAME=CzechLight/velia
9ZUUL_PROJECT_SRC_DIR=$HOME/$(jq < ~/zuul-env.json -r ".projects[] | select(.name == \"${LEAF_PROJECT_NAME}\").src_dir")
10ZUUL_PROJECT_SHORT_NAME=$(jq < ~/zuul-env.json -r ".projects[] | select(.name == \"${LEAF_PROJECT_NAME}\").short_name")
Tomáš Pecka5123e002020-06-05 15:29:21 +020011ZUUL_GERRIT_HOSTNAME=$(jq < ~/zuul-env.json -r '.project.canonical_hostname')
Jan Kundrát14baf2e2022-03-23 22:14:19 +010012ZUUL_JOB_NAME_NO_PROJECT=${ZUUL_JOB_NAME##${ZUUL_PROJECT_SHORT_NAME}-}
Tomáš Pecka5123e002020-06-05 15:29:21 +020013
14CI_PARALLEL_JOBS=$(awk -vcpu=$(getconf _NPROCESSORS_ONLN) 'BEGIN{printf "%.0f", cpu*1.3+1}')
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +020015CMAKE_OPTIONS="-DTEST_NETWORK_WITH_SUDO=ON"
Tomáš Pecka5123e002020-06-05 15:29:21 +020016CFLAGS=""
17CXXFLAGS=""
18LDFLAGS=""
19
20if [[ $ZUUL_JOB_NAME =~ .*-clang.* ]]; then
21 export CC=clang
22 export CXX=clang++
23 export LD=clang
Tomáš Pecka5123e002020-06-05 15:29:21 +020024fi
25
26if [[ $ZUUL_JOB_NAME =~ .*-ubsan ]]; then
27 export CFLAGS="-fsanitize=undefined ${CFLAGS}"
28 export CXXFLAGS="-fsanitize=undefined ${CXXFLAGS}"
29 export LDFLAGS="-fsanitize=undefined ${LDFLAGS}"
Jan Kundrát9b8bb732021-01-27 15:39:12 +010030 export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1
Tomáš Pecka5123e002020-06-05 15:29:21 +020031fi
32
33if [[ $ZUUL_JOB_NAME =~ .*-asan ]]; then
34 export CFLAGS="-fsanitize=address ${CFLAGS}"
35 export CXXFLAGS="-fsanitize=address ${CXXFLAGS}"
36 export LDFLAGS="-fsanitize=address ${LDFLAGS}"
37fi
38
39if [[ $ZUUL_JOB_NAME =~ .*-tsan ]]; then
40 export CFLAGS="-fsanitize=thread ${CFLAGS}"
41 export CXXFLAGS="-fsanitize=thread ${CXXFLAGS}"
42 export LDFLAGS="-fsanitize=thread ${LDFLAGS}"
Jan Kundrát9b8bb732021-01-27 15:39:12 +010043 export TSAN_OPTIONS="suppressions=$HOME/target/tsan.supp"
Tomáš Pecka5123e002020-06-05 15:29:21 +020044fi
45
46if [[ $ZUUL_JOB_NAME =~ .*-cover.* ]]; then
47 export CFLAGS="${CFLAGS} --coverage"
48 export CXXFLAGS="${CXXFLAGS} --coverage"
49 export LDFLAGS="${LDFLAGS} --coverage"
50fi
51
52PREFIX=~/target
53mkdir ${PREFIX}
54BUILD_DIR=~/build
55mkdir ${BUILD_DIR}
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +020056export PATH=${PREFIX}/bin:/sbin:/usr/sbin:$PATH
Tomáš Pecka5123e002020-06-05 15:29:21 +020057export LD_LIBRARY_PATH=${PREFIX}/lib64:${PREFIX}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
58export PKG_CONFIG_PATH=${PREFIX}/lib64/pkgconfig:${PREFIX}/lib/pkgconfig:${PREFIX}/share/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
59
60ARTIFACT_URL=$(jq < ~/zuul-env.json -r '[.artifacts[]? | select(.name == "tarball") | select(.project == "CzechLight/dependencies")][-1]?.url + ""')
61
62if [[ -z "${ARTIFACT_URL}" ]]; then
63 # nothing ahead in the pipeline -> fallback to the latest promoted artifact
64 DEPSRCDIR=$(jq < ~/zuul-env.json -e -r ".projects[] | select(.name == \"CzechLight/dependencies\").src_dir")
65 DEP_SUBMODULE_COMMIT=$(git --git-dir ${HOME}/${DEPSRCDIR}/.git rev-parse HEAD)
Jan Kundrát14baf2e2022-03-23 22:14:19 +010066 ARTIFACT_URL="https://object-store.cloud.muni.cz/swift/v1/ci-artifacts-${ZUUL_TENANT}/${ZUUL_GERRIT_HOSTNAME}/CzechLight/dependencies/${ZUUL_JOB_NAME_NO_PROJECT%%-cover?(-previous)}/${DEP_SUBMODULE_COMMIT}.tar.zst"
Tomáš Pecka5123e002020-06-05 15:29:21 +020067fi
68
69curl ${ARTIFACT_URL} | unzstd --stdout | tar -C ${PREFIX} -xf -
70
Tomáš Pecka5123e002020-06-05 15:29:21 +020071cd ${BUILD_DIR}
72cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR}
73ninja-build
74ctest -j${CI_PARALLEL_JOBS} --output-on-failure
75
76if [[ $JOB_PERFORM_EXTRA_WORK == 1 ]]; then
77 ninja-build doc
78 pushd html
79 zip -r ~/zuul-output/docs/html.zip .
80 popd
81fi
82
83if [[ $LDFLAGS =~ .*--coverage.* ]]; then
84 gcovr -j ${CI_PARALLEL_JOBS} --object-directory ${BUILD_DIR} --root ${ZUUL_PROJECT_SRC_DIR} --xml --output ${BUILD_DIR}/coverage.xml
85fi