blob: bfd345709ac1b4b8dc6de2391359d5629d2bffc2 [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)' \
27 ${ZUUL_PROJECT_SRC_DIR}/CMakeLists.txt
Tomáš Pecka5123e002020-06-05 15:29:21 +020028fi
29
30if [[ $ZUUL_JOB_NAME =~ .*-ubsan ]]; then
31 export CFLAGS="-fsanitize=undefined ${CFLAGS}"
32 export CXXFLAGS="-fsanitize=undefined ${CXXFLAGS}"
33 export LDFLAGS="-fsanitize=undefined ${LDFLAGS}"
Jan Kundrát9b8bb732021-01-27 15:39:12 +010034 export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1
Tomáš Pecka5123e002020-06-05 15:29:21 +020035fi
36
37if [[ $ZUUL_JOB_NAME =~ .*-asan ]]; then
38 export CFLAGS="-fsanitize=address ${CFLAGS}"
39 export CXXFLAGS="-fsanitize=address ${CXXFLAGS}"
40 export LDFLAGS="-fsanitize=address ${LDFLAGS}"
41fi
42
43if [[ $ZUUL_JOB_NAME =~ .*-tsan ]]; then
44 export CFLAGS="-fsanitize=thread ${CFLAGS}"
45 export CXXFLAGS="-fsanitize=thread ${CXXFLAGS}"
46 export LDFLAGS="-fsanitize=thread ${LDFLAGS}"
Jan Kundrát9b8bb732021-01-27 15:39:12 +010047 export TSAN_OPTIONS="suppressions=$HOME/target/tsan.supp"
Tomáš Pecka5123e002020-06-05 15:29:21 +020048fi
49
50if [[ $ZUUL_JOB_NAME =~ .*-cover.* ]]; then
51 export CFLAGS="${CFLAGS} --coverage"
52 export CXXFLAGS="${CXXFLAGS} --coverage"
53 export LDFLAGS="${LDFLAGS} --coverage"
54fi
55
56PREFIX=~/target
57mkdir ${PREFIX}
58BUILD_DIR=~/build
59mkdir ${BUILD_DIR}
60export PATH=${PREFIX}/bin:$PATH
61export LD_LIBRARY_PATH=${PREFIX}/lib64:${PREFIX}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
62export PKG_CONFIG_PATH=${PREFIX}/lib64/pkgconfig:${PREFIX}/lib/pkgconfig:${PREFIX}/share/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
63
64ARTIFACT_URL=$(jq < ~/zuul-env.json -r '[.artifacts[]? | select(.name == "tarball") | select(.project == "CzechLight/dependencies")][-1]?.url + ""')
65
66if [[ -z "${ARTIFACT_URL}" ]]; then
67 # nothing ahead in the pipeline -> fallback to the latest promoted artifact
68 DEPSRCDIR=$(jq < ~/zuul-env.json -e -r ".projects[] | select(.name == \"CzechLight/dependencies\").src_dir")
69 DEP_SUBMODULE_COMMIT=$(git --git-dir ${HOME}/${DEPSRCDIR}/.git rev-parse HEAD)
Jan Kundrát24b35052020-11-11 17:37:33 +010070 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 +020071fi
72
73curl ${ARTIFACT_URL} | unzstd --stdout | tar -C ${PREFIX} -xf -
74
Tomáš Pecka1f42cfe2020-10-21 18:38:27 +020075BUILD_SD=~/build-sd
76pushd ${ZUUL_PROJECT_SRC_DIR}/../../github/systemd/systemd
77env \
78 -u CC \
79 -u CXX \
80 -u LD \
81 -u CFLAGS \
82 -u CXXFLAGS \
83 -u LDFLAGS \
84 meson ${BUILD_SD} \
85 -Drootprefix=${PREFIX} \
86 -Dprefix=${PREFIX} \
87 -Dsysconfdir=${PREFIX}/etc \
88 -Dlocalstatedir=${PREFIX}/var \
89 -Dsysvinit-path=${PREFIX}/etc/init.d \
90 -Dsysvrcnd-path=${PREFIX}/etc/rc.d \
91 -Drc-local=${PREFIX}/etc/rc.local \
92 -Dcertificate-root=${PREFIX}/etc/ssl \
93 -Dbashcompletiondir=${PREFIX}/share/bash-completion/completions \
94 -Dcreate-log-dirs=false \
95 -Dhwdb=false
96ninja-build -C ${BUILD_SD} install
97popd
98
Tomáš Pecka5123e002020-06-05 15:29:21 +020099cd ${BUILD_DIR}
100cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR}
101ninja-build
102ctest -j${CI_PARALLEL_JOBS} --output-on-failure
103
104if [[ $JOB_PERFORM_EXTRA_WORK == 1 ]]; then
105 ninja-build doc
106 pushd html
107 zip -r ~/zuul-output/docs/html.zip .
108 popd
109fi
110
111if [[ $LDFLAGS =~ .*--coverage.* ]]; then
112 gcovr -j ${CI_PARALLEL_JOBS} --object-directory ${BUILD_DIR} --root ${ZUUL_PROJECT_SRC_DIR} --xml --output ${BUILD_DIR}/coverage.xml
113fi