Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -eux -o pipefail |
| 4 | shopt -s failglob extglob |
| 5 | |
| 6 | ZUUL_JOB_NAME=$(jq < ~/zuul-env.json -r '.job') |
| 7 | ZUUL_TENANT=$(jq < ~/zuul-env.json -r '.tenant') |
Jan Kundrát | 14baf2e | 2022-03-23 22:14:19 +0100 | [diff] [blame^] | 8 | LEAF_PROJECT_NAME=CzechLight/velia |
| 9 | ZUUL_PROJECT_SRC_DIR=$HOME/$(jq < ~/zuul-env.json -r ".projects[] | select(.name == \"${LEAF_PROJECT_NAME}\").src_dir") |
| 10 | ZUUL_PROJECT_SHORT_NAME=$(jq < ~/zuul-env.json -r ".projects[] | select(.name == \"${LEAF_PROJECT_NAME}\").short_name") |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 11 | ZUUL_GERRIT_HOSTNAME=$(jq < ~/zuul-env.json -r '.project.canonical_hostname') |
Jan Kundrát | 14baf2e | 2022-03-23 22:14:19 +0100 | [diff] [blame^] | 12 | ZUUL_JOB_NAME_NO_PROJECT=${ZUUL_JOB_NAME##${ZUUL_PROJECT_SHORT_NAME}-} |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 13 | |
| 14 | CI_PARALLEL_JOBS=$(awk -vcpu=$(getconf _NPROCESSORS_ONLN) 'BEGIN{printf "%.0f", cpu*1.3+1}') |
Tomáš Pecka | 9fa5f6a | 2021-04-13 11:36:11 +0200 | [diff] [blame] | 15 | CMAKE_OPTIONS="-DTEST_NETWORK_WITH_SUDO=ON" |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 16 | CFLAGS="" |
| 17 | CXXFLAGS="" |
| 18 | LDFLAGS="" |
| 19 | |
| 20 | if [[ $ZUUL_JOB_NAME =~ .*-clang.* ]]; then |
| 21 | export CC=clang |
| 22 | export CXX=clang++ |
| 23 | export LD=clang |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 24 | fi |
| 25 | |
| 26 | if [[ $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át | 9b8bb73 | 2021-01-27 15:39:12 +0100 | [diff] [blame] | 30 | export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 31 | fi |
| 32 | |
| 33 | if [[ $ZUUL_JOB_NAME =~ .*-asan ]]; then |
| 34 | export CFLAGS="-fsanitize=address ${CFLAGS}" |
| 35 | export CXXFLAGS="-fsanitize=address ${CXXFLAGS}" |
| 36 | export LDFLAGS="-fsanitize=address ${LDFLAGS}" |
| 37 | fi |
| 38 | |
| 39 | if [[ $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át | 9b8bb73 | 2021-01-27 15:39:12 +0100 | [diff] [blame] | 43 | export TSAN_OPTIONS="suppressions=$HOME/target/tsan.supp" |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 44 | fi |
| 45 | |
| 46 | if [[ $ZUUL_JOB_NAME =~ .*-cover.* ]]; then |
| 47 | export CFLAGS="${CFLAGS} --coverage" |
| 48 | export CXXFLAGS="${CXXFLAGS} --coverage" |
| 49 | export LDFLAGS="${LDFLAGS} --coverage" |
| 50 | fi |
| 51 | |
| 52 | PREFIX=~/target |
| 53 | mkdir ${PREFIX} |
| 54 | BUILD_DIR=~/build |
| 55 | mkdir ${BUILD_DIR} |
Tomáš Pecka | 9fa5f6a | 2021-04-13 11:36:11 +0200 | [diff] [blame] | 56 | export PATH=${PREFIX}/bin:/sbin:/usr/sbin:$PATH |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 57 | export LD_LIBRARY_PATH=${PREFIX}/lib64:${PREFIX}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} |
| 58 | export PKG_CONFIG_PATH=${PREFIX}/lib64/pkgconfig:${PREFIX}/lib/pkgconfig:${PREFIX}/share/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH} |
| 59 | |
| 60 | ARTIFACT_URL=$(jq < ~/zuul-env.json -r '[.artifacts[]? | select(.name == "tarball") | select(.project == "CzechLight/dependencies")][-1]?.url + ""') |
| 61 | |
| 62 | if [[ -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át | 14baf2e | 2022-03-23 22:14:19 +0100 | [diff] [blame^] | 66 | 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áš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 67 | fi |
| 68 | |
| 69 | curl ${ARTIFACT_URL} | unzstd --stdout | tar -C ${PREFIX} -xf - |
| 70 | |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 71 | cd ${BUILD_DIR} |
| 72 | cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR} |
| 73 | ninja-build |
| 74 | ctest -j${CI_PARALLEL_JOBS} --output-on-failure |
| 75 | |
| 76 | if [[ $JOB_PERFORM_EXTRA_WORK == 1 ]]; then |
| 77 | ninja-build doc |
| 78 | pushd html |
| 79 | zip -r ~/zuul-output/docs/html.zip . |
| 80 | popd |
| 81 | fi |
| 82 | |
| 83 | if [[ $LDFLAGS =~ .*--coverage.* ]]; then |
| 84 | gcovr -j ${CI_PARALLEL_JOBS} --object-directory ${BUILD_DIR} --root ${ZUUL_PROJECT_SRC_DIR} --xml --output ${BUILD_DIR}/coverage.xml |
| 85 | fi |