1# This file is sourced in to the CI environment
2# in .gitlab-ci.yml
3#
4
5# Sets the error behaviour options for shell throughout the CI environment
6#
7set -o errexit # Exit if command failed.
8set -o pipefail # Exit if pipe failed.
9
10# We can use the appropriate CI variable for debugging
11DEBUG_SHELL=${DEBUG_SHELL:-"0"}
12[ "${DEBUG_SHELL}" = "1" ] && set -x
13
14[ -z $CI_COMMIT_REF_NAME ] && echo "This internal script should only be run by a Gitlab CI runner." && exit 1
15
16# Compiler flags to thoroughly check the IDF code in some CI jobs
17# (Depends on default options '-Wno-error=XXX' used in the IDF build system)
18
19PEDANTIC_FLAGS="-DIDF_CI_BUILD -Werror -Werror=deprecated-declarations -Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function"
20export PEDANTIC_CFLAGS="${PEDANTIC_FLAGS} -Wstrict-prototypes"
21export PEDANTIC_CXXFLAGS="${PEDANTIC_FLAGS}"
22
23# ccache related settings.
24# IDF_CCACHE_ENABLE may be enabled at job level (see build.yml). However it is possible to override it
25# globally via CI_CCACHE_DISABLE, in case there are any ccache related issues.
26if [ "$CI_CCACHE_DISABLE" = 1 ]; then
27    export IDF_CCACHE_ENABLE=0
28    echo "INFO: ccache disabled globally using CI_CCACHE_DISABLE=0"
29fi
30
31# Set ccache base directory to the project checkout path, to cancel out differences between runners
32export CCACHE_BASEDIR="${CI_PROJECT_DIR}"
33
34# In tools/ci/find_apps_build_apps.sh, we use --work-dir argument to copy apps to a separate location
35# before building them. This results in cache misses, even though the same code is compiled.
36# To solve this issue, we can disable 'hash_dir' option of ccache by setting CCACHE_NOHASHDIR env variable.
37# Note, this can result in issues with debug information, see:
38#   https://ccache.dev/manual/4.5.html#_compiling_in_different_directories
39#
40# 'CI_CCACHE_DISABLE_NOHASHDIR' variable can be used at project level to revert to hash_dir=true, in
41# case we start seeing failures due to false cache hits.
42if [ "${CI_CCACHE_DISABLE_NOHASHDIR}" != "1" ]; then
43    export CCACHE_NOHASHDIR="1"
44    echo "INFO: ccache CCACHE_NOHASHDIR option is enabled"
45fi
46
47# If 'REDIS_CACHE' variable is set at runner (or project) level, use that as secondary ccache storage.
48# This can be disabled at project level using 'CI_CCACHE_DISABLE_SECONDARY', in case of issues.
49if [ "${CI_CCACHE_DISABLE_SECONDARY}" != "1" ] && [ -n "${REDIS_CACHE}" ]; then
50    export CCACHE_SECONDARY_STORAGE="redis://${REDIS_CACHE}"
51    echo "INFO: Using CCACHE_SECONDARY_STORAGE=${CCACHE_SECONDARY_STORAGE}"
52fi
53