blob: a8d33b0c3a3893904f14749ac16a8c436a11ac1b [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}-}
Jan Kundrát489d5b22023-02-01 02:41:58 +010013ZUUL_SRC_COMMON_PREFIX=${ZUUL_PROJECT_SRC_DIR:0:-${#LEAF_PROJECT_NAME}}
Tomáš Pecka5123e002020-06-05 15:29:21 +020014
15CI_PARALLEL_JOBS=$(awk -vcpu=$(getconf _NPROCESSORS_ONLN) 'BEGIN{printf "%.0f", cpu*1.3+1}')
Tomáš Pecka2030fc42023-02-16 16:41:19 +010016CMAKE_OPTIONS=""
Jan Kundrát489d5b22023-02-01 02:41:58 +010017CFLAGS="-O2 -g -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"
18CXXFLAGS="-O2 -g -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"
Tomáš Pecka5123e002020-06-05 15:29:21 +020019LDFLAGS=""
20
21if [[ $ZUUL_JOB_NAME =~ .*-clang.* ]]; then
22 export CC=clang
23 export CXX=clang++
24 export LD=clang
Tomáš Pecka5123e002020-06-05 15:29:21 +020025fi
26
27if [[ $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át9b8bb732021-01-27 15:39:12 +010031 export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1
Tomáš Pecka5123e002020-06-05 15:29:21 +020032fi
33
Jan Kundrát489d5b22023-02-01 02:41:58 +010034if [[ $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áš Pecka5123e002020-06-05 15:29:21 +020040fi
41
42if [[ $ZUUL_JOB_NAME =~ .*-tsan ]]; then
Jan Kundrát489d5b22023-02-01 02:41:58 +010043 export CFLAGS="-fsanitize=thread -Wp,-U_FORTIFY_SOURCE ${CFLAGS}"
44 export CXXFLAGS="-fsanitize=thread -Wp,-U_FORTIFY_SOURCE ${CXXFLAGS}"
Tomáš Pecka5123e002020-06-05 15:29:21 +020045 export LDFLAGS="-fsanitize=thread ${LDFLAGS}"
Jan Kundrát9b8bb732021-01-27 15:39:12 +010046 export TSAN_OPTIONS="suppressions=$HOME/target/tsan.supp"
Tomáš Pecka5123e002020-06-05 15:29:21 +020047fi
48
49if [[ $ZUUL_JOB_NAME =~ .*-cover.* ]]; then
50 export CFLAGS="${CFLAGS} --coverage"
51 export CXXFLAGS="${CXXFLAGS} --coverage"
52 export LDFLAGS="${LDFLAGS} --coverage"
53fi
54
55PREFIX=~/target
56mkdir ${PREFIX}
57BUILD_DIR=~/build
58mkdir ${BUILD_DIR}
Tomáš Pecka9fa5f6a2021-04-13 11:36:11 +020059export PATH=${PREFIX}/bin:/sbin:/usr/sbin:$PATH
Tomáš Pecka5123e002020-06-05 15:29:21 +020060export LD_LIBRARY_PATH=${PREFIX}/lib64:${PREFIX}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
61export PKG_CONFIG_PATH=${PREFIX}/lib64/pkgconfig:${PREFIX}/lib/pkgconfig:${PREFIX}/share/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
62
63ARTIFACT_URL=$(jq < ~/zuul-env.json -r '[.artifacts[]? | select(.name == "tarball") | select(.project == "CzechLight/dependencies")][-1]?.url + ""')
64
65if [[ -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átc5a54912022-03-28 13:00:06 +020069 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áš Pecka5123e002020-06-05 15:29:21 +020070fi
71
72curl ${ARTIFACT_URL} | unzstd --stdout | tar -C ${PREFIX} -xf -
73
Tomáš Peckabe797072022-07-15 20:45:52 +020074# build sysrepo-ietf-alarms project (for tests)
75BUILD_SYSREPO_IETF_ALARMS=~/build-alarms
76mkdir ${BUILD_SYSREPO_IETF_ALARMS}
77pushd ${BUILD_SYSREPO_IETF_ALARMS}
78cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${ZUUL_PROJECT_SRC_DIR}/../sysrepo-ietf-alarms
79ninja-build install
80popd
81
Tomáš Pecka5123e002020-06-05 15:29:21 +020082cd ${BUILD_DIR}
83cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR}
84ninja-build
Tomáš Peckabe797072022-07-15 20:45:52 +020085
86set_save=$-
87set -E
88trap "echo sysrepo-ietf-alarmsd test failed, copying log; cp ${BUILD_DIR}/sysrepo-ietf-alarmsd.log ~/zuul-output/logs" ERR
Tomáš Pecka5123e002020-06-05 15:29:21 +020089ctest -j${CI_PARALLEL_JOBS} --output-on-failure
Tomáš Peckabe797072022-07-15 20:45:52 +020090trap - ERR
91set +E -$set_save
Tomáš Pecka5123e002020-06-05 15:29:21 +020092
93if [[ $JOB_PERFORM_EXTRA_WORK == 1 ]]; then
94 ninja-build doc
95 pushd html
96 zip -r ~/zuul-output/docs/html.zip .
97 popd
98fi
99
100if [[ $LDFLAGS =~ .*--coverage.* ]]; then
101 gcovr -j ${CI_PARALLEL_JOBS} --object-directory ${BUILD_DIR} --root ${ZUUL_PROJECT_SRC_DIR} --xml --output ${BUILD_DIR}/coverage.xml
102fi