blob: 5af1e6a7ef8b7c6a39dc7b09fc2092de0aa7ffa3 [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}"
34fi
35
36if [[ $ZUUL_JOB_NAME =~ .*-asan ]]; then
37 export CFLAGS="-fsanitize=address ${CFLAGS}"
38 export CXXFLAGS="-fsanitize=address ${CXXFLAGS}"
39 export LDFLAGS="-fsanitize=address ${LDFLAGS}"
40fi
41
42if [[ $ZUUL_JOB_NAME =~ .*-tsan ]]; then
43 export CFLAGS="-fsanitize=thread ${CFLAGS}"
44 export CXXFLAGS="-fsanitize=thread ${CXXFLAGS}"
45 export LDFLAGS="-fsanitize=thread ${LDFLAGS}"
Tomáš Pecka98ad18d2020-11-13 15:39:55 +010046 export TSAN_OPTIONS="suppressions=$HOME/target/tsan.supp:detect_deadlocks=0"
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}
59export PATH=${PREFIX}/bin:$PATH
60export 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át24b35052020-11-11 17:37:33 +010069 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 +020070fi
71
72curl ${ARTIFACT_URL} | unzstd --stdout | tar -C ${PREFIX} -xf -
73
Tomáš Pecka1f42cfe2020-10-21 18:38:27 +020074BUILD_SD=~/build-sd
75pushd ${ZUUL_PROJECT_SRC_DIR}/../../github/systemd/systemd
76env \
77 -u CC \
78 -u CXX \
79 -u LD \
80 -u CFLAGS \
81 -u CXXFLAGS \
82 -u LDFLAGS \
83 meson ${BUILD_SD} \
84 -Drootprefix=${PREFIX} \
85 -Dprefix=${PREFIX} \
86 -Dsysconfdir=${PREFIX}/etc \
87 -Dlocalstatedir=${PREFIX}/var \
88 -Dsysvinit-path=${PREFIX}/etc/init.d \
89 -Dsysvrcnd-path=${PREFIX}/etc/rc.d \
90 -Drc-local=${PREFIX}/etc/rc.local \
91 -Dcertificate-root=${PREFIX}/etc/ssl \
92 -Dbashcompletiondir=${PREFIX}/share/bash-completion/completions \
93 -Dcreate-log-dirs=false \
94 -Dhwdb=false
95ninja-build -C ${BUILD_SD} install
96popd
97
Tomáš Pecka5123e002020-06-05 15:29:21 +020098cd ${BUILD_DIR}
99cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR}
100ninja-build
101ctest -j${CI_PARALLEL_JOBS} --output-on-failure
102
103if [[ $JOB_PERFORM_EXTRA_WORK == 1 ]]; then
104 ninja-build doc
105 pushd html
106 zip -r ~/zuul-output/docs/html.zip .
107 popd
108fi
109
110if [[ $LDFLAGS =~ .*--coverage.* ]]; then
111 gcovr -j ${CI_PARALLEL_JOBS} --object-directory ${BUILD_DIR} --root ${ZUUL_PROJECT_SRC_DIR} --xml --output ${BUILD_DIR}/coverage.xml
112fi