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)' \ |
| 27 | ${ZUUL_PROJECT_SRC_DIR}/CMakeLists.txt |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 28 | fi |
| 29 | |
| 30 | if [[ $ZUUL_JOB_NAME =~ .*-ubsan ]]; then |
| 31 | export CFLAGS="-fsanitize=undefined ${CFLAGS}" |
| 32 | export CXXFLAGS="-fsanitize=undefined ${CXXFLAGS}" |
| 33 | export LDFLAGS="-fsanitize=undefined ${LDFLAGS}" |
| 34 | fi |
| 35 | |
| 36 | if [[ $ZUUL_JOB_NAME =~ .*-asan ]]; then |
| 37 | export CFLAGS="-fsanitize=address ${CFLAGS}" |
| 38 | export CXXFLAGS="-fsanitize=address ${CXXFLAGS}" |
| 39 | export LDFLAGS="-fsanitize=address ${LDFLAGS}" |
| 40 | fi |
| 41 | |
| 42 | if [[ $ZUUL_JOB_NAME =~ .*-tsan ]]; then |
| 43 | export CFLAGS="-fsanitize=thread ${CFLAGS}" |
| 44 | export CXXFLAGS="-fsanitize=thread ${CXXFLAGS}" |
| 45 | export LDFLAGS="-fsanitize=thread ${LDFLAGS}" |
Tomáš Pecka | 98ad18d | 2020-11-13 15:39:55 +0100 | [diff] [blame] | 46 | export TSAN_OPTIONS="suppressions=$HOME/target/tsan.supp:detect_deadlocks=0" |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 47 | fi |
| 48 | |
| 49 | if [[ $ZUUL_JOB_NAME =~ .*-cover.* ]]; then |
| 50 | export CFLAGS="${CFLAGS} --coverage" |
| 51 | export CXXFLAGS="${CXXFLAGS} --coverage" |
| 52 | export LDFLAGS="${LDFLAGS} --coverage" |
| 53 | fi |
| 54 | |
| 55 | PREFIX=~/target |
| 56 | mkdir ${PREFIX} |
| 57 | BUILD_DIR=~/build |
| 58 | mkdir ${BUILD_DIR} |
| 59 | export PATH=${PREFIX}/bin:$PATH |
| 60 | export LD_LIBRARY_PATH=${PREFIX}/lib64:${PREFIX}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} |
| 61 | export PKG_CONFIG_PATH=${PREFIX}/lib64/pkgconfig:${PREFIX}/lib/pkgconfig:${PREFIX}/share/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH} |
| 62 | |
| 63 | ARTIFACT_URL=$(jq < ~/zuul-env.json -r '[.artifacts[]? | select(.name == "tarball") | select(.project == "CzechLight/dependencies")][-1]?.url + ""') |
| 64 | |
| 65 | if [[ -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át | 24b3505 | 2020-11-11 17:37:33 +0100 | [diff] [blame] | 69 | 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] | 70 | fi |
| 71 | |
| 72 | curl ${ARTIFACT_URL} | unzstd --stdout | tar -C ${PREFIX} -xf - |
| 73 | |
Tomáš Pecka | 1f42cfe | 2020-10-21 18:38:27 +0200 | [diff] [blame] | 74 | BUILD_SD=~/build-sd |
| 75 | pushd ${ZUUL_PROJECT_SRC_DIR}/../../github/systemd/systemd |
| 76 | env \ |
| 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 |
| 95 | ninja-build -C ${BUILD_SD} install |
| 96 | popd |
| 97 | |
Tomáš Pecka | 5123e00 | 2020-06-05 15:29:21 +0200 | [diff] [blame] | 98 | cd ${BUILD_DIR} |
| 99 | cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR} |
| 100 | ninja-build |
| 101 | ctest -j${CI_PARALLEL_JOBS} --output-on-failure |
| 102 | |
| 103 | if [[ $JOB_PERFORM_EXTRA_WORK == 1 ]]; then |
| 104 | ninja-build doc |
| 105 | pushd html |
| 106 | zip -r ~/zuul-output/docs/html.zip . |
| 107 | popd |
| 108 | fi |
| 109 | |
| 110 | if [[ $LDFLAGS =~ .*--coverage.* ]]; then |
| 111 | gcovr -j ${CI_PARALLEL_JOBS} --object-directory ${BUILD_DIR} --root ${ZUUL_PROJECT_SRC_DIR} --xml --output ${BUILD_DIR}/coverage.xml |
| 112 | fi |