blob: 7ba9954950e6aec1c031964b40117744295e2c7b [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')
Jan Kundrátdba63582019-06-06 13:09:30 +020010ZUUL_GERRIT_HOSTNAME=$(jq < ~/zuul-env.json -r '.project.canonical_hostname')
Jan Kundrát73e3bf22019-02-28 15:44:02 +010011
12CI_PARALLEL_JOBS=$(grep -c '^processor' /proc/cpuinfo)
13CMAKE_OPTIONS=""
14CFLAGS=""
15CXXFLAGS=""
16LDFLAGS=""
17
18if [[ $ZUUL_JOB_NAME =~ .*-clang.* ]]; then
19 export CC=clang
20 export CXX=clang++
21 export LD=clang
22 export CXXFLAGS="-stdlib=libc++"
23fi
24
25if [[ $ZUUL_JOB_NAME =~ .*-ubsan ]]; then
26 export CFLAGS="-fsanitize=undefined ${CFLAGS}"
27 export CXXFLAGS="-fsanitize=undefined ${CXXFLAGS}"
28 export LDFLAGS="-fsanitize=undefined ${LDFLAGS}"
29fi
30
31if [[ $ZUUL_JOB_NAME =~ .*-asan ]]; then
32 export CFLAGS="-fsanitize=address ${CFLAGS}"
33 export CXXFLAGS="-fsanitize=address ${CXXFLAGS}"
34 export LDFLAGS="-fsanitize=address ${LDFLAGS}"
35fi
36
Jan Kundrát7b7c8232019-03-13 14:04:06 +010037if [[ $ZUUL_JOB_NAME =~ .*-tsan ]]; then
38 export CFLAGS="-fsanitize=thread ${CFLAGS}"
39 export CXXFLAGS="-fsanitize=thread ${CXXFLAGS}"
40 export LDFLAGS="-fsanitize=thread ${LDFLAGS}"
41fi
42
Jan Kundrát73e3bf22019-02-28 15:44:02 +010043PREFIX=~/target
44mkdir ${PREFIX}
45BUILD_DIR=~/build
46mkdir ${BUILD_DIR}
47export PATH=${PREFIX}/bin:$PATH
48export LD_LIBRARY_PATH=${PREFIX}/lib64:${PREFIX}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
Jan Kundrát0e783ac2019-10-30 12:29:17 +010049export PKG_CONFIG_PATH=${PREFIX}/lib64/pkgconfig:${PREFIX}/lib/pkgconfig:${PREFIX}/share/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
Jan Kundrát73e3bf22019-02-28 15:44:02 +010050
51ARTIFACT_URL=""
52
Jan Kundrátdf70cb12019-05-29 12:47:50 +020053if [[ "$(jq < ~/zuul-env.json -r '.artifacts[-1].project')" = "CzechLight/dependencies" &&
54 "$(jq < ~/zuul-env.json -r '.artifacts[-1].name')" = "tarball" ]]; then
55 ARTIFACT_URL=$(jq < ~/zuul-env.json -r '.artifacts[-1].url')
Jan Kundrát73e3bf22019-02-28 15:44:02 +010056fi
57
58DEP_SUBMODULE_COMMIT=$(git ls-tree -l master submodules/dependencies | cut -d ' ' -f 3)
59
60if [[ -z "${ARTIFACT_URL}" ]]; then
61 # fallback to a promoted artifact
Jan Kundrátdba63582019-06-06 13:09:30 +020062 ARTIFACT_URL="https://object-store.cloud.muni.cz/swift/v1/ci-artifacts-${ZUUL_TENANT}/${ZUUL_GERRIT_HOSTNAME}/CzechLight/dependencies/${ZUUL_JOB_NAME}/${DEP_SUBMODULE_COMMIT}.tar.xz"
Jan Kundrát73e3bf22019-02-28 15:44:02 +010063fi
64
65ARTIFACT_FILE=$(basename ${ARTIFACT_URL})
66DEP_HASH_FROM_ARTIFACT=$(echo "${ARTIFACT_FILE}" | sed -e 's/^czechlight-dependencies-//' -e 's/\.tar\.xz$//')
67if [[ "${DEP_HASH_FROM_ARTIFACT}" != "${DEP_SUBMODULE_COMMIT}" ]]; then
68 echo "Mismatched artifact: HEAD of ./submodules/dependencies does not match artifact commit ref"
69 exit 1
70fi
71curl ${ARTIFACT_URL} --output ${ARTIFACT_FILE}
72tar -C ${PREFIX} -xf ${ARTIFACT_FILE}
73rm ${ARTIFACT_FILE}
74
Václav Kubernátc31bd602019-03-07 11:44:48 +010075# TODO: move this to CzechLight/dependencies
76mkdir -p /home/ci/target/var-run
77
Jan Kundrát73e3bf22019-02-28 15:44:02 +010078cd ${BUILD_DIR}
79cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR}
80ninja-build
81ctest -j${CI_PARALLEL_JOBS} --output-on-failure
82ninja-build doc
Jan Kundrátdba63582019-06-06 13:09:30 +020083pushd html
84zip -r ~/zuul-output/docs/html.zip .
85popd