blob: acc4eea1e3694eefc521107f1e9ac261fbe44eab [file] [log] [blame]
Jan Kundrátd9d26a92018-02-22 12:49:21 +01001#!/bin/bash
Jan Kundrát73e3bf22019-02-28 15:44:02 +01002
3set -eux -o pipefail
4shopt -s failglob
5
6ZUUL_JOB_NAME=$(jq < ~/zuul-env.json -r '.job')
7ZUUL_PROJECT_SRC_DIR=$HOME/$(jq < ~/zuul-env.json -r '.project.src_dir')
8ZUUL_PROJECT_SHORT_NAME=$(jq < ~/zuul-env.json -r '.project.short_name')
9
10CI_PARALLEL_JOBS=$(grep -c '^processor' /proc/cpuinfo)
11CMAKE_OPTIONS=""
12CFLAGS=""
13CXXFLAGS=""
14LDFLAGS=""
15
16if [[ $ZUUL_JOB_NAME =~ .*-clang.* ]]; then
17 export CC=clang
18 export CXX=clang++
19 export LD=clang
20 export CXXFLAGS="-stdlib=libc++"
21fi
22
23if [[ $ZUUL_JOB_NAME =~ .*-ubsan ]]; then
24 export CFLAGS="-fsanitize=undefined ${CFLAGS}"
25 export CXXFLAGS="-fsanitize=undefined ${CXXFLAGS}"
26 export LDFLAGS="-fsanitize=undefined ${LDFLAGS}"
27fi
28
29if [[ $ZUUL_JOB_NAME =~ .*-asan ]]; then
30 export CFLAGS="-fsanitize=address ${CFLAGS}"
31 export CXXFLAGS="-fsanitize=address ${CXXFLAGS}"
32 export LDFLAGS="-fsanitize=address ${LDFLAGS}"
33fi
34
35PREFIX=~/target
36mkdir ${PREFIX}
37BUILD_DIR=~/build
38mkdir ${BUILD_DIR}
39export PATH=${PREFIX}/bin:$PATH
40export LD_LIBRARY_PATH=${PREFIX}/lib64:${PREFIX}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
41export PKG_CONFIG_PATH=${PREFIX}/lib64/pkgconfig:${PREFIX}/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
42
43ARTIFACT_URL=""
44
45if [[ "$(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
57fi
58
59DEP_SUBMODULE_COMMIT=$(git ls-tree -l master submodules/dependencies | cut -d ' ' -f 3)
60
61if [[ -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
64fi
65
66ARTIFACT_FILE=$(basename ${ARTIFACT_URL})
67DEP_HASH_FROM_ARTIFACT=$(echo "${ARTIFACT_FILE}" | sed -e 's/^czechlight-dependencies-//' -e 's/\.tar\.xz$//')
68if [[ "${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
71fi
72curl ${ARTIFACT_URL} --output ${ARTIFACT_FILE}
73tar -C ${PREFIX} -xf ${ARTIFACT_FILE}
74rm ${ARTIFACT_FILE}
75
76cd ${BUILD_DIR}
77cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR}
78ninja-build
79ctest -j${CI_PARALLEL_JOBS} --output-on-failure
80ninja-build doc
81mv html ~/zuul-output/docs/