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') |
| 8 | ZUUL_PROJECT_SRC_DIR=$HOME/$(jq < ~/zuul-env.json -r '.project.src_dir') |
| 9 | ZUUL_PROJECT_SHORT_NAME=$(jq < ~/zuul-env.json -r '.project.short_name') |
| 10 | ZUUL_GERRIT_HOSTNAME=$(jq < ~/zuul-env.json -r '.project.canonical_hostname') |
| 11 | |
| 12 | CI_PARALLEL_JOBS=$(awk -vcpu=$(getconf _NPROCESSORS_ONLN) 'BEGIN{printf "%.0f", cpu*1.3+1}') |
| 13 | CMAKE_OPTIONS="" |
| 14 | CFLAGS="" |
| 15 | CXXFLAGS="" |
| 16 | LDFLAGS="" |
| 17 | |
| 18 | if [[ $ZUUL_JOB_NAME =~ .*-clang.* ]]; then |
| 19 | export CC=clang |
| 20 | export CXX=clang++ |
| 21 | export LD=clang |
| 22 | export CXXFLAGS="-stdlib=libc++" |
Jan Kundrát | 6efb8ca | 2020-10-20 00:58:57 +0200 | [diff] [blame] | 23 | # 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át | babbab9 | 2021-01-27 09:25:05 +0100 | [diff] [blame^] | 27 | -e 's/fmt::fmt/fmt::fmt-header-only/' \ |
Jan Kundrát | 6efb8ca | 2020-10-20 00:58:57 +0200 | [diff] [blame] | 28 | ${ZUUL_PROJECT_SRC_DIR}/CMakeLists.txt |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 29 | fi |
| 30 | |
| 31 | if [[ $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át | 9b8bb73 | 2021-01-27 15:39:12 +0100 | [diff] [blame] | 35 | export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 36 | fi |
| 37 | |
| 38 | if [[ $ZUUL_JOB_NAME =~ .*-asan ]]; then |
| 39 | export CFLAGS="-fsanitize=address ${CFLAGS}" |
| 40 | export CXXFLAGS="-fsanitize=address ${CXXFLAGS}" |
| 41 | export LDFLAGS="-fsanitize=address ${LDFLAGS}" |
| 42 | fi |
| 43 | |
| 44 | if [[ $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át | 9b8bb73 | 2021-01-27 15:39:12 +0100 | [diff] [blame] | 48 | export TSAN_OPTIONS="suppressions=$HOME/target/tsan.supp" |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 49 | fi |
| 50 | |
| 51 | if [[ $ZUUL_JOB_NAME =~ .*-cover.* ]]; then |
| 52 | export CFLAGS="${CFLAGS} --coverage" |
| 53 | export CXXFLAGS="${CXXFLAGS} --coverage" |
| 54 | export LDFLAGS="${LDFLAGS} --coverage" |
| 55 | fi |
| 56 | |
| 57 | PREFIX=~/target |
| 58 | mkdir ${PREFIX} |
| 59 | BUILD_DIR=~/build |
| 60 | mkdir ${BUILD_DIR} |
| 61 | export PATH=${PREFIX}/bin:$PATH |
| 62 | export LD_LIBRARY_PATH=${PREFIX}/lib64:${PREFIX}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} |
| 63 | export PKG_CONFIG_PATH=${PREFIX}/lib64/pkgconfig:${PREFIX}/lib/pkgconfig:${PREFIX}/share/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH} |
| 64 | |
| 65 | ARTIFACT_URL=$(jq < ~/zuul-env.json -r '[.artifacts[]? | select(.name == "tarball") | select(.project == "CzechLight/dependencies")][-1]?.url + ""') |
| 66 | |
| 67 | if [[ -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át | 24b3505 | 2020-11-11 17:37:33 +0100 | [diff] [blame] | 71 | 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áš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 72 | fi |
| 73 | |
| 74 | curl ${ARTIFACT_URL} | unzstd --stdout | tar -C ${PREFIX} -xf - |
| 75 | |
Tomáš Pecka | 1f42cfe | 2020-10-21 18:38:27 +0200 | [diff] [blame] | 76 | BUILD_SD=~/build-sd |
| 77 | pushd ${ZUUL_PROJECT_SRC_DIR}/../../github/systemd/systemd |
| 78 | env \ |
| 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 |
| 97 | ninja-build -C ${BUILD_SD} install |
| 98 | popd |
| 99 | |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 100 | cd ${BUILD_DIR} |
| 101 | cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR} |
| 102 | ninja-build |
| 103 | ctest -j${CI_PARALLEL_JOBS} --output-on-failure |
| 104 | |
| 105 | if [[ $JOB_PERFORM_EXTRA_WORK == 1 ]]; then |
| 106 | ninja-build doc |
| 107 | pushd html |
| 108 | zip -r ~/zuul-output/docs/html.zip . |
| 109 | popd |
| 110 | fi |
| 111 | |
| 112 | if [[ $LDFLAGS =~ .*--coverage.* ]]; then |
| 113 | gcovr -j ${CI_PARALLEL_JOBS} --object-directory ${BUILD_DIR} --root ${ZUUL_PROJECT_SRC_DIR} --xml --output ${BUILD_DIR}/coverage.xml |
| 114 | fi |