Jan Kundrát | d9d26a9 | 2018-02-22 12:49:21 +0100 | [diff] [blame] | 1 | #!/bin/bash |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 2 | |
| 3 | set -eux -o pipefail |
| 4 | shopt -s failglob |
| 5 | |
| 6 | ZUUL_JOB_NAME=$(jq < ~/zuul-env.json -r '.job') |
Jan Kundrát | 8a91466 | 2019-02-28 18:11:55 +0100 | [diff] [blame] | 7 | ZUUL_TENANT=$(jq < ~/zuul-env.json -r '.tenant') |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 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 | |
| 11 | CI_PARALLEL_JOBS=$(grep -c '^processor' /proc/cpuinfo) |
| 12 | CMAKE_OPTIONS="" |
| 13 | CFLAGS="" |
| 14 | CXXFLAGS="" |
| 15 | LDFLAGS="" |
| 16 | |
| 17 | if [[ $ZUUL_JOB_NAME =~ .*-clang.* ]]; then |
| 18 | export CC=clang |
| 19 | export CXX=clang++ |
| 20 | export LD=clang |
| 21 | export CXXFLAGS="-stdlib=libc++" |
| 22 | fi |
| 23 | |
| 24 | if [[ $ZUUL_JOB_NAME =~ .*-ubsan ]]; then |
| 25 | export CFLAGS="-fsanitize=undefined ${CFLAGS}" |
| 26 | export CXXFLAGS="-fsanitize=undefined ${CXXFLAGS}" |
| 27 | export LDFLAGS="-fsanitize=undefined ${LDFLAGS}" |
| 28 | fi |
| 29 | |
| 30 | if [[ $ZUUL_JOB_NAME =~ .*-asan ]]; then |
| 31 | export CFLAGS="-fsanitize=address ${CFLAGS}" |
| 32 | export CXXFLAGS="-fsanitize=address ${CXXFLAGS}" |
| 33 | export LDFLAGS="-fsanitize=address ${LDFLAGS}" |
| 34 | fi |
| 35 | |
Jan Kundrát | 7b7c823 | 2019-03-13 14:04:06 +0100 | [diff] [blame] | 36 | if [[ $ZUUL_JOB_NAME =~ .*-tsan ]]; then |
| 37 | export CFLAGS="-fsanitize=thread ${CFLAGS}" |
| 38 | export CXXFLAGS="-fsanitize=thread ${CXXFLAGS}" |
| 39 | export LDFLAGS="-fsanitize=thread ${LDFLAGS}" |
| 40 | fi |
| 41 | |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 42 | PREFIX=~/target |
| 43 | mkdir ${PREFIX} |
| 44 | BUILD_DIR=~/build |
| 45 | mkdir ${BUILD_DIR} |
| 46 | export PATH=${PREFIX}/bin:$PATH |
| 47 | export LD_LIBRARY_PATH=${PREFIX}/lib64:${PREFIX}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} |
| 48 | export PKG_CONFIG_PATH=${PREFIX}/lib64/pkgconfig:${PREFIX}/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH} |
| 49 | |
| 50 | ARTIFACT_URL="" |
| 51 | |
| 52 | if [[ "$(jq < ~/zuul-env.json -r '.artifacts[0].project')" = "CzechLight/dependencies" && |
| 53 | "$(jq < ~/zuul-env.json -r '.artifacts[0].name')" = "tarball" ]]; then |
Jan Kundrát | 8a91466 | 2019-02-28 18:11:55 +0100 | [diff] [blame] | 54 | ARTIFACT_URL=$(jq < ~/zuul-env.json -r '.artifacts[0].url') |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 55 | fi |
| 56 | |
| 57 | DEP_SUBMODULE_COMMIT=$(git ls-tree -l master submodules/dependencies | cut -d ' ' -f 3) |
| 58 | |
| 59 | if [[ -z "${ARTIFACT_URL}" ]]; then |
| 60 | # fallback to a promoted artifact |
Jan Kundrát | 8a91466 | 2019-02-28 18:11:55 +0100 | [diff] [blame] | 61 | ARTIFACT_URL="https://ci-logs.gerrit.cesnet.cz/t/${ZUUL_TENANT,,}/artifacts/${ZUUL_JOB_NAME}/czechlight-dependencies-${DEP_SUBMODULE_COMMIT}.tar.xz" |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 62 | fi |
| 63 | |
| 64 | ARTIFACT_FILE=$(basename ${ARTIFACT_URL}) |
| 65 | DEP_HASH_FROM_ARTIFACT=$(echo "${ARTIFACT_FILE}" | sed -e 's/^czechlight-dependencies-//' -e 's/\.tar\.xz$//') |
| 66 | if [[ "${DEP_HASH_FROM_ARTIFACT}" != "${DEP_SUBMODULE_COMMIT}" ]]; then |
| 67 | echo "Mismatched artifact: HEAD of ./submodules/dependencies does not match artifact commit ref" |
| 68 | exit 1 |
| 69 | fi |
| 70 | curl ${ARTIFACT_URL} --output ${ARTIFACT_FILE} |
| 71 | tar -C ${PREFIX} -xf ${ARTIFACT_FILE} |
| 72 | rm ${ARTIFACT_FILE} |
| 73 | |
| 74 | cd ${BUILD_DIR} |
| 75 | cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR} |
| 76 | ninja-build |
| 77 | ctest -j${CI_PARALLEL_JOBS} --output-on-failure |
| 78 | ninja-build doc |
| 79 | mv html ~/zuul-output/docs/ |