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') |
| 7 | ZUUL_PROJECT_SRC_DIR=$HOME/$(jq < ~/zuul-env.json -r '.project.src_dir') |
| 8 | ZUUL_PROJECT_SHORT_NAME=$(jq < ~/zuul-env.json -r '.project.short_name') |
| 9 | |
| 10 | CI_PARALLEL_JOBS=$(grep -c '^processor' /proc/cpuinfo) |
| 11 | CMAKE_OPTIONS="" |
| 12 | CFLAGS="" |
| 13 | CXXFLAGS="" |
| 14 | LDFLAGS="" |
| 15 | |
| 16 | if [[ $ZUUL_JOB_NAME =~ .*-clang.* ]]; then |
| 17 | export CC=clang |
| 18 | export CXX=clang++ |
| 19 | export LD=clang |
| 20 | export CXXFLAGS="-stdlib=libc++" |
| 21 | fi |
| 22 | |
| 23 | if [[ $ZUUL_JOB_NAME =~ .*-ubsan ]]; then |
| 24 | export CFLAGS="-fsanitize=undefined ${CFLAGS}" |
| 25 | export CXXFLAGS="-fsanitize=undefined ${CXXFLAGS}" |
| 26 | export LDFLAGS="-fsanitize=undefined ${LDFLAGS}" |
| 27 | fi |
| 28 | |
| 29 | if [[ $ZUUL_JOB_NAME =~ .*-asan ]]; then |
| 30 | export CFLAGS="-fsanitize=address ${CFLAGS}" |
| 31 | export CXXFLAGS="-fsanitize=address ${CXXFLAGS}" |
| 32 | export LDFLAGS="-fsanitize=address ${LDFLAGS}" |
| 33 | fi |
| 34 | |
| 35 | PREFIX=~/target |
| 36 | mkdir ${PREFIX} |
| 37 | BUILD_DIR=~/build |
| 38 | mkdir ${BUILD_DIR} |
| 39 | export PATH=${PREFIX}/bin:$PATH |
| 40 | export LD_LIBRARY_PATH=${PREFIX}/lib64:${PREFIX}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} |
| 41 | export PKG_CONFIG_PATH=${PREFIX}/lib64/pkgconfig:${PREFIX}/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH} |
| 42 | |
| 43 | ARTIFACT_URL="" |
| 44 | |
| 45 | if [[ "$(jq < ~/zuul-env.json -r '.artifacts[0].project')" = "CzechLight/dependencies" && |
| 46 | "$(jq < ~/zuul-env.json -r '.artifacts[0].name')" = "tarball" ]]; then |
| 47 | # FIXME: Zuul feeds us with wrong artifact (from a different provider) for some reason :( |
| 48 | # so let's look into builds from the change pipeline and fetch their artifact directly |
| 49 | #ARTIFACT_URL=$(jq < ~/zuul-env.json -r '.artifacts[0].url') |
| 50 | |
| 51 | CHANGE_BUILD_QUERY=$(jq -r '.items | map(select(.project.name == "CzechLight/dependencies"))[-1] | ("change=" + .change + "&patchset=" + .patchset)' < ~/zuul-env.json) |
| 52 | if [[ "${CHANGE_BUILD_QUERY}" != "null" ]]; then |
| 53 | # We depend on some change from project CzechLight/dependencies, let's look at the latest one |
| 54 | ZUUL_TENANT=$(jq < ~/zuul-env.json -r '.tenant') |
| 55 | ARTIFACT_URL=$(curl "https://zuul.gerrit.cesnet.cz/api/tenant/${ZUUL_TENANT}/builds?pipeline=check&job_name=${ZUUL_JOB_NAME}&${CHANGE_BUILD_QUERY}" | jq -r '.[].artifacts[0].url') |
| 56 | fi |
| 57 | fi |
| 58 | |
| 59 | DEP_SUBMODULE_COMMIT=$(git ls-tree -l master submodules/dependencies | cut -d ' ' -f 3) |
| 60 | |
| 61 | if [[ -z "${ARTIFACT_URL}" ]]; then |
| 62 | # fallback to a promoted artifact |
| 63 | ARTIFACT_URL=https://ci-logs.gerrit.cesnet.cz/t/public/artifacts/${ZUUL_JOB_NAME}/czechlight-dependencies-${DEP_SUBMODULE_COMMIT}.tar.xz |
| 64 | fi |
| 65 | |
| 66 | ARTIFACT_FILE=$(basename ${ARTIFACT_URL}) |
| 67 | DEP_HASH_FROM_ARTIFACT=$(echo "${ARTIFACT_FILE}" | sed -e 's/^czechlight-dependencies-//' -e 's/\.tar\.xz$//') |
| 68 | if [[ "${DEP_HASH_FROM_ARTIFACT}" != "${DEP_SUBMODULE_COMMIT}" ]]; then |
| 69 | echo "Mismatched artifact: HEAD of ./submodules/dependencies does not match artifact commit ref" |
| 70 | exit 1 |
| 71 | fi |
| 72 | curl ${ARTIFACT_URL} --output ${ARTIFACT_FILE} |
| 73 | tar -C ${PREFIX} -xf ${ARTIFACT_FILE} |
| 74 | rm ${ARTIFACT_FILE} |
| 75 | |
| 76 | cd ${BUILD_DIR} |
| 77 | cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR} |
| 78 | ninja-build |
| 79 | ctest -j${CI_PARALLEL_JOBS} --output-on-failure |
| 80 | ninja-build doc |
| 81 | mv html ~/zuul-output/docs/ |