blob: 5438b0a26aebed3aa0ca42b90ed91faecad7c79d [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')
Jan Kundrát8a914662019-02-28 18:11:55 +01007ZUUL_TENANT=$(jq < ~/zuul-env.json -r '.tenant')
Jan Kundrát73e3bf22019-02-28 15:44:02 +01008ZUUL_PROJECT_SRC_DIR=$HOME/$(jq < ~/zuul-env.json -r '.project.src_dir')
9ZUUL_PROJECT_SHORT_NAME=$(jq < ~/zuul-env.json -r '.project.short_name')
10
11CI_PARALLEL_JOBS=$(grep -c '^processor' /proc/cpuinfo)
12CMAKE_OPTIONS=""
13CFLAGS=""
14CXXFLAGS=""
15LDFLAGS=""
16
17if [[ $ZUUL_JOB_NAME =~ .*-clang.* ]]; then
18 export CC=clang
19 export CXX=clang++
20 export LD=clang
21 export CXXFLAGS="-stdlib=libc++"
22fi
23
24if [[ $ZUUL_JOB_NAME =~ .*-ubsan ]]; then
25 export CFLAGS="-fsanitize=undefined ${CFLAGS}"
26 export CXXFLAGS="-fsanitize=undefined ${CXXFLAGS}"
27 export LDFLAGS="-fsanitize=undefined ${LDFLAGS}"
28fi
29
30if [[ $ZUUL_JOB_NAME =~ .*-asan ]]; then
31 export CFLAGS="-fsanitize=address ${CFLAGS}"
32 export CXXFLAGS="-fsanitize=address ${CXXFLAGS}"
33 export LDFLAGS="-fsanitize=address ${LDFLAGS}"
34fi
35
Jan Kundrát7b7c8232019-03-13 14:04:06 +010036if [[ $ZUUL_JOB_NAME =~ .*-tsan ]]; then
37 export CFLAGS="-fsanitize=thread ${CFLAGS}"
38 export CXXFLAGS="-fsanitize=thread ${CXXFLAGS}"
39 export LDFLAGS="-fsanitize=thread ${LDFLAGS}"
40fi
41
Jan Kundrát73e3bf22019-02-28 15:44:02 +010042PREFIX=~/target
43mkdir ${PREFIX}
44BUILD_DIR=~/build
45mkdir ${BUILD_DIR}
46export PATH=${PREFIX}/bin:$PATH
47export LD_LIBRARY_PATH=${PREFIX}/lib64:${PREFIX}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
48export PKG_CONFIG_PATH=${PREFIX}/lib64/pkgconfig:${PREFIX}/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
49
50ARTIFACT_URL=""
51
52if [[ "$(jq < ~/zuul-env.json -r '.artifacts[0].project')" = "CzechLight/dependencies" &&
53 "$(jq < ~/zuul-env.json -r '.artifacts[0].name')" = "tarball" ]]; then
Jan Kundrát8a914662019-02-28 18:11:55 +010054 ARTIFACT_URL=$(jq < ~/zuul-env.json -r '.artifacts[0].url')
Jan Kundrát73e3bf22019-02-28 15:44:02 +010055fi
56
57DEP_SUBMODULE_COMMIT=$(git ls-tree -l master submodules/dependencies | cut -d ' ' -f 3)
58
59if [[ -z "${ARTIFACT_URL}" ]]; then
60 # fallback to a promoted artifact
Jan Kundrát8a914662019-02-28 18:11:55 +010061 ARTIFACT_URL="https://ci-logs.gerrit.cesnet.cz/t/${ZUUL_TENANT,,}/artifacts/${ZUUL_JOB_NAME}/czechlight-dependencies-${DEP_SUBMODULE_COMMIT}.tar.xz"
Jan Kundrát73e3bf22019-02-28 15:44:02 +010062fi
63
64ARTIFACT_FILE=$(basename ${ARTIFACT_URL})
65DEP_HASH_FROM_ARTIFACT=$(echo "${ARTIFACT_FILE}" | sed -e 's/^czechlight-dependencies-//' -e 's/\.tar\.xz$//')
66if [[ "${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
69fi
70curl ${ARTIFACT_URL} --output ${ARTIFACT_FILE}
71tar -C ${PREFIX} -xf ${ARTIFACT_FILE}
72rm ${ARTIFACT_FILE}
73
74cd ${BUILD_DIR}
75cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR}
76ninja-build
77ctest -j${CI_PARALLEL_JOBS} --output-on-failure
78ninja-build doc
79mv html ~/zuul-output/docs/