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}-} |
Jan Kundrát | 489d5b2 | 2023-02-01 02:41:58 +0100 | [diff] [blame] | 13 | ZUUL_SRC_COMMON_PREFIX=${ZUUL_PROJECT_SRC_DIR:0:-${#LEAF_PROJECT_NAME}} |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 14 | |
| 15 | CI_PARALLEL_JOBS=$(awk -vcpu=$(getconf _NPROCESSORS_ONLN) 'BEGIN{printf "%.0f", cpu*1.3+1}') |
Tomáš Pecka | 2030fc4 | 2023-02-16 16:41:19 +0100 | [diff] [blame] | 16 | CMAKE_OPTIONS="" |
Jan Kundrát | 489d5b2 | 2023-02-01 02:41:58 +0100 | [diff] [blame] | 17 | CFLAGS="-O2 -g -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer" |
| 18 | CXXFLAGS="-O2 -g -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer" |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 19 | LDFLAGS="" |
| 20 | |
| 21 | if [[ $ZUUL_JOB_NAME =~ .*-clang.* ]]; then |
| 22 | export CC=clang |
| 23 | export CXX=clang++ |
| 24 | export LD=clang |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 25 | fi |
| 26 | |
| 27 | if [[ $ZUUL_JOB_NAME =~ .*-ubsan ]]; then |
| 28 | export CFLAGS="-fsanitize=undefined ${CFLAGS}" |
| 29 | export CXXFLAGS="-fsanitize=undefined ${CXXFLAGS}" |
| 30 | export LDFLAGS="-fsanitize=undefined ${LDFLAGS}" |
Jan Kundrát | 9b8bb73 | 2021-01-27 15:39:12 +0100 | [diff] [blame] | 31 | export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 32 | fi |
| 33 | |
Jan Kundrát | 489d5b2 | 2023-02-01 02:41:58 +0100 | [diff] [blame] | 34 | if [[ $ZUUL_JOB_NAME =~ .*-asan-ubsan ]]; then |
| 35 | export CFLAGS="-fsanitize=address,undefined -Wp,-U_FORTIFY_SOURCE ${CFLAGS}" |
| 36 | export CXXFLAGS="-fsanitize=address,undefined -Wp,-U_FORTIFY_SOURCE ${CXXFLAGS}" |
| 37 | export LDFLAGS="-fsanitize=address,undefined ${LDFLAGS}" |
| 38 | export ASAN_OPTIONS=intercept_tls_get_addr=0,log_to_syslog=true,handle_abort=2,strip_path_prefix=${ZUUL_SRC_COMMON_PREFIX} |
| 39 | export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 40 | fi |
| 41 | |
| 42 | if [[ $ZUUL_JOB_NAME =~ .*-tsan ]]; then |
Jan Kundrát | 489d5b2 | 2023-02-01 02:41:58 +0100 | [diff] [blame] | 43 | export CFLAGS="-fsanitize=thread -Wp,-U_FORTIFY_SOURCE ${CFLAGS}" |
| 44 | export CXXFLAGS="-fsanitize=thread -Wp,-U_FORTIFY_SOURCE ${CXXFLAGS}" |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 45 | export LDFLAGS="-fsanitize=thread ${LDFLAGS}" |
Jan Kundrát | 9b8bb73 | 2021-01-27 15:39:12 +0100 | [diff] [blame] | 46 | export TSAN_OPTIONS="suppressions=$HOME/target/tsan.supp" |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 47 | fi |
| 48 | |
| 49 | if [[ $ZUUL_JOB_NAME =~ .*-cover.* ]]; then |
| 50 | export CFLAGS="${CFLAGS} --coverage" |
| 51 | export CXXFLAGS="${CXXFLAGS} --coverage" |
| 52 | export LDFLAGS="${LDFLAGS} --coverage" |
| 53 | fi |
| 54 | |
| 55 | PREFIX=~/target |
| 56 | mkdir ${PREFIX} |
| 57 | BUILD_DIR=~/build |
| 58 | mkdir ${BUILD_DIR} |
Tomáš Pecka | 9fa5f6a | 2021-04-13 11:36:11 +0200 | [diff] [blame] | 59 | export PATH=${PREFIX}/bin:/sbin:/usr/sbin:$PATH |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 60 | export LD_LIBRARY_PATH=${PREFIX}/lib64:${PREFIX}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} |
| 61 | export PKG_CONFIG_PATH=${PREFIX}/lib64/pkgconfig:${PREFIX}/lib/pkgconfig:${PREFIX}/share/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH} |
| 62 | |
| 63 | ARTIFACT_URL=$(jq < ~/zuul-env.json -r '[.artifacts[]? | select(.name == "tarball") | select(.project == "CzechLight/dependencies")][-1]?.url + ""') |
| 64 | |
| 65 | if [[ -z "${ARTIFACT_URL}" ]]; then |
| 66 | # nothing ahead in the pipeline -> fallback to the latest promoted artifact |
| 67 | DEPSRCDIR=$(jq < ~/zuul-env.json -e -r ".projects[] | select(.name == \"CzechLight/dependencies\").src_dir") |
| 68 | DEP_SUBMODULE_COMMIT=$(git --git-dir ${HOME}/${DEPSRCDIR}/.git rev-parse HEAD) |
Jan Kundrát | c5a5491 | 2022-03-28 13:00:06 +0200 | [diff] [blame] | 69 | ARTIFACT_URL="https://object-store.cloud.muni.cz/swift/v1/ci-artifacts-${ZUUL_TENANT}/${ZUUL_GERRIT_HOSTNAME}/CzechLight/dependencies/deps-${ZUUL_JOB_NAME_NO_PROJECT%%-cover?(-previous)}/${DEP_SUBMODULE_COMMIT}.tar.zst" |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 70 | fi |
| 71 | |
| 72 | curl ${ARTIFACT_URL} | unzstd --stdout | tar -C ${PREFIX} -xf - |
| 73 | |
Tomáš Pecka | be79707 | 2022-07-15 20:45:52 +0200 | [diff] [blame] | 74 | # build sysrepo-ietf-alarms project (for tests) |
| 75 | BUILD_SYSREPO_IETF_ALARMS=~/build-alarms |
| 76 | mkdir ${BUILD_SYSREPO_IETF_ALARMS} |
| 77 | pushd ${BUILD_SYSREPO_IETF_ALARMS} |
| 78 | cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${ZUUL_PROJECT_SRC_DIR}/../sysrepo-ietf-alarms |
| 79 | ninja-build install |
| 80 | popd |
| 81 | |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 82 | cd ${BUILD_DIR} |
| 83 | cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR} |
| 84 | ninja-build |
Tomáš Pecka | be79707 | 2022-07-15 20:45:52 +0200 | [diff] [blame] | 85 | |
| 86 | set_save=$- |
| 87 | set -E |
| 88 | trap "echo sysrepo-ietf-alarmsd test failed, copying log; cp ${BUILD_DIR}/sysrepo-ietf-alarmsd.log ~/zuul-output/logs" ERR |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 89 | ctest -j${CI_PARALLEL_JOBS} --output-on-failure |
Tomáš Pecka | be79707 | 2022-07-15 20:45:52 +0200 | [diff] [blame] | 90 | trap - ERR |
| 91 | set +E -$set_save |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 92 | |
| 93 | if [[ $JOB_PERFORM_EXTRA_WORK == 1 ]]; then |
| 94 | ninja-build doc |
| 95 | pushd html |
| 96 | zip -r ~/zuul-output/docs/html.zip . |
| 97 | popd |
| 98 | fi |
| 99 | |
| 100 | if [[ $LDFLAGS =~ .*--coverage.* ]]; then |
| 101 | gcovr -j ${CI_PARALLEL_JOBS} --object-directory ${BUILD_DIR} --root ${ZUUL_PROJECT_SRC_DIR} --xml --output ${BUILD_DIR}/coverage.xml |
| 102 | fi |