blob: aea3316ab5fa7bb53222f5e966745fe348598b3b [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
36PREFIX=~/target
37mkdir ${PREFIX}
38BUILD_DIR=~/build
39mkdir ${BUILD_DIR}
40export PATH=${PREFIX}/bin:$PATH
41export LD_LIBRARY_PATH=${PREFIX}/lib64:${PREFIX}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
42export PKG_CONFIG_PATH=${PREFIX}/lib64/pkgconfig:${PREFIX}/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
43
44ARTIFACT_URL=""
45
46if [[ "$(jq < ~/zuul-env.json -r '.artifacts[0].project')" = "CzechLight/dependencies" &&
47 "$(jq < ~/zuul-env.json -r '.artifacts[0].name')" = "tarball" ]]; then
Jan Kundrát8a914662019-02-28 18:11:55 +010048 ARTIFACT_URL=$(jq < ~/zuul-env.json -r '.artifacts[0].url')
Jan Kundrát73e3bf22019-02-28 15:44:02 +010049fi
50
51DEP_SUBMODULE_COMMIT=$(git ls-tree -l master submodules/dependencies | cut -d ' ' -f 3)
52
53if [[ -z "${ARTIFACT_URL}" ]]; then
54 # fallback to a promoted artifact
Jan Kundrát8a914662019-02-28 18:11:55 +010055 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 +010056fi
57
58ARTIFACT_FILE=$(basename ${ARTIFACT_URL})
59DEP_HASH_FROM_ARTIFACT=$(echo "${ARTIFACT_FILE}" | sed -e 's/^czechlight-dependencies-//' -e 's/\.tar\.xz$//')
60if [[ "${DEP_HASH_FROM_ARTIFACT}" != "${DEP_SUBMODULE_COMMIT}" ]]; then
61 echo "Mismatched artifact: HEAD of ./submodules/dependencies does not match artifact commit ref"
62 exit 1
63fi
64curl ${ARTIFACT_URL} --output ${ARTIFACT_FILE}
65tar -C ${PREFIX} -xf ${ARTIFACT_FILE}
66rm ${ARTIFACT_FILE}
67
68cd ${BUILD_DIR}
69cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR}
70ninja-build
71ctest -j${CI_PARALLEL_JOBS} --output-on-failure
72ninja-build doc
73mv html ~/zuul-output/docs/