blob: 5cc60ab3b4a3a71bf3aa6999350ddb9c7797ce3b [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')
8ZUUL_PROJECT_SRC_DIR=$HOME/$(jq < ~/zuul-env.json -r '.project.src_dir')
9ZUUL_PROJECT_SHORT_NAME=$(jq < ~/zuul-env.json -r '.project.short_name')
10ZUUL_GERRIT_HOSTNAME=$(jq < ~/zuul-env.json -r '.project.canonical_hostname')
11
12CI_PARALLEL_JOBS=$(awk -vcpu=$(getconf _NPROCESSORS_ONLN) 'BEGIN{printf "%.0f", cpu*1.3+1}')
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++"
Jan Kundrát6efb8ca2020-10-20 00:58:57 +020023 # spdlog passes std::string instances, and it's built against GCC's libstdc++ on the CI
24 sed -i \
25 -e 's/spdlog::spdlog/spdlog::spdlog_header_only/' \
26 -e '/find_package(spdlog/ a add_definitions(-DFMT_HEADER_ONLY)' \
Václav Kubernátbabbab92021-01-27 09:25:05 +010027 -e 's/fmt::fmt/fmt::fmt-header-only/' \
Jan Kundrát6efb8ca2020-10-20 00:58:57 +020028 ${ZUUL_PROJECT_SRC_DIR}/CMakeLists.txt
Tomáš Pecka5123e002020-06-05 15:29:21 +020029fi
30
31if [[ $ZUUL_JOB_NAME =~ .*-ubsan ]]; then
32 export CFLAGS="-fsanitize=undefined ${CFLAGS}"
33 export CXXFLAGS="-fsanitize=undefined ${CXXFLAGS}"
34 export LDFLAGS="-fsanitize=undefined ${LDFLAGS}"
Jan Kundrát9b8bb732021-01-27 15:39:12 +010035 export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1
Tomáš Pecka5123e002020-06-05 15:29:21 +020036fi
37
38if [[ $ZUUL_JOB_NAME =~ .*-asan ]]; then
39 export CFLAGS="-fsanitize=address ${CFLAGS}"
40 export CXXFLAGS="-fsanitize=address ${CXXFLAGS}"
41 export LDFLAGS="-fsanitize=address ${LDFLAGS}"
42fi
43
44if [[ $ZUUL_JOB_NAME =~ .*-tsan ]]; then
45 export CFLAGS="-fsanitize=thread ${CFLAGS}"
46 export CXXFLAGS="-fsanitize=thread ${CXXFLAGS}"
47 export LDFLAGS="-fsanitize=thread ${LDFLAGS}"
Jan Kundrát9b8bb732021-01-27 15:39:12 +010048 export TSAN_OPTIONS="suppressions=$HOME/target/tsan.supp"
Tomáš Pecka5123e002020-06-05 15:29:21 +020049fi
50
51if [[ $ZUUL_JOB_NAME =~ .*-cover.* ]]; then
52 export CFLAGS="${CFLAGS} --coverage"
53 export CXXFLAGS="${CXXFLAGS} --coverage"
54 export LDFLAGS="${LDFLAGS} --coverage"
55fi
56
57PREFIX=~/target
58mkdir ${PREFIX}
59BUILD_DIR=~/build
60mkdir ${BUILD_DIR}
61export PATH=${PREFIX}/bin:$PATH
62export LD_LIBRARY_PATH=${PREFIX}/lib64:${PREFIX}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
63export PKG_CONFIG_PATH=${PREFIX}/lib64/pkgconfig:${PREFIX}/lib/pkgconfig:${PREFIX}/share/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
64
65ARTIFACT_URL=$(jq < ~/zuul-env.json -r '[.artifacts[]? | select(.name == "tarball") | select(.project == "CzechLight/dependencies")][-1]?.url + ""')
66
67if [[ -z "${ARTIFACT_URL}" ]]; then
68 # nothing ahead in the pipeline -> fallback to the latest promoted artifact
69 DEPSRCDIR=$(jq < ~/zuul-env.json -e -r ".projects[] | select(.name == \"CzechLight/dependencies\").src_dir")
70 DEP_SUBMODULE_COMMIT=$(git --git-dir ${HOME}/${DEPSRCDIR}/.git rev-parse HEAD)
Jan Kundrát24b35052020-11-11 17:37:33 +010071 ARTIFACT_URL="https://object-store.cloud.muni.cz/swift/v1/ci-artifacts-${ZUUL_TENANT}/${ZUUL_GERRIT_HOSTNAME}/CzechLight/dependencies/${ZUUL_JOB_NAME%%-cover?(-previous)}/${DEP_SUBMODULE_COMMIT}.tar.zst"
Tomáš Pecka5123e002020-06-05 15:29:21 +020072fi
73
74curl ${ARTIFACT_URL} | unzstd --stdout | tar -C ${PREFIX} -xf -
75
Tomáš Pecka1f42cfe2020-10-21 18:38:27 +020076BUILD_SD=~/build-sd
77pushd ${ZUUL_PROJECT_SRC_DIR}/../../github/systemd/systemd
78env \
79 -u CC \
80 -u CXX \
81 -u LD \
82 -u CFLAGS \
83 -u CXXFLAGS \
84 -u LDFLAGS \
85 meson ${BUILD_SD} \
86 -Drootprefix=${PREFIX} \
87 -Dprefix=${PREFIX} \
88 -Dsysconfdir=${PREFIX}/etc \
89 -Dlocalstatedir=${PREFIX}/var \
90 -Dsysvinit-path=${PREFIX}/etc/init.d \
91 -Dsysvrcnd-path=${PREFIX}/etc/rc.d \
92 -Drc-local=${PREFIX}/etc/rc.local \
93 -Dcertificate-root=${PREFIX}/etc/ssl \
94 -Dbashcompletiondir=${PREFIX}/share/bash-completion/completions \
95 -Dcreate-log-dirs=false \
96 -Dhwdb=false
97ninja-build -C ${BUILD_SD} install
98popd
99
Tomáš Pecka5123e002020-06-05 15:29:21 +0200100cd ${BUILD_DIR}
101cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR}
102ninja-build
103ctest -j${CI_PARALLEL_JOBS} --output-on-failure
104
105if [[ $JOB_PERFORM_EXTRA_WORK == 1 ]]; then
106 ninja-build doc
107 pushd html
108 zip -r ~/zuul-output/docs/html.zip .
109 popd
110fi
111
112if [[ $LDFLAGS =~ .*--coverage.* ]]; then
113 gcovr -j ${CI_PARALLEL_JOBS} --object-directory ${BUILD_DIR} --root ${ZUUL_PROJECT_SRC_DIR} --xml --output ${BUILD_DIR}/coverage.xml
114fi