2020-04-02 23:10:02 +00:00
|
|
|
#!/usr/bin/env bash
|
2016-09-26 07:13:32 +00:00
|
|
|
#
|
2020-04-22 06:49:05 +00:00
|
|
|
# Build all examples from the examples directory, in BUILD_PATH to
|
2016-09-26 07:13:32 +00:00
|
|
|
# ensure they can run when copied to a new directory.
|
|
|
|
#
|
|
|
|
# Runs as part of CI process.
|
|
|
|
#
|
2017-06-07 08:30:25 +00:00
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Safety settings (see https://gist.github.com/ilg-ul/383869cbb01f61a51c4d).
|
|
|
|
|
2018-03-27 05:13:35 +00:00
|
|
|
if [[ ! -z ${DEBUG_SHELL} ]]
|
2017-06-07 08:30:25 +00:00
|
|
|
then
|
|
|
|
set -x # Activate the expand mode if DEBUG is anything but empty.
|
|
|
|
fi
|
|
|
|
|
|
|
|
set -o errexit # Exit if command failed.
|
|
|
|
set -o pipefail # Exit if pipe failed.
|
|
|
|
|
2020-04-22 06:49:05 +00:00
|
|
|
export PATH="$IDF_PATH/tools/ci:$IDF_PATH/tools:$PATH"
|
2017-06-07 08:30:25 +00:00
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
die() {
|
|
|
|
echo "${1:-"Unknown Error"}" 1>&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
[ -z ${IDF_PATH} ] && die "IDF_PATH is not set"
|
2017-12-28 10:20:14 +00:00
|
|
|
[ -z ${LOG_PATH} ] && die "LOG_PATH is not set"
|
2020-04-22 06:49:05 +00:00
|
|
|
[ -z ${BUILD_PATH} ] && die "BUILD_PATH is not set"
|
|
|
|
[ -z ${IDF_TARGET} ] && die "IDF_TARGET is not set"
|
2020-04-22 09:05:59 +00:00
|
|
|
[ -z ${EXAMPLE_TEST_BUILD_SYSTEM} ] && die "EXAMPLE_TEST_BUILD_SYSTEM is not set"
|
2020-04-20 06:30:31 +00:00
|
|
|
[ -z ${SCAN_EXAMPLE_TEST_JSON} ] && die "SCAN_EXAMPLE_TEST_JSON is not set"
|
2018-01-05 04:38:44 +00:00
|
|
|
[ -d ${LOG_PATH} ] || mkdir -p ${LOG_PATH}
|
2020-04-22 06:49:05 +00:00
|
|
|
[ -d ${BUILD_PATH} ] || mkdir -p ${BUILD_PATH}
|
2017-06-07 08:30:25 +00:00
|
|
|
|
2020-04-22 06:49:05 +00:00
|
|
|
if [ -z ${CI_NODE_TOTAL} ]; then
|
|
|
|
CI_NODE_TOTAL=1
|
|
|
|
echo "Assuming CI_NODE_TOTAL=${CI_NODE_TOTAL}"
|
|
|
|
fi
|
|
|
|
if [ -z ${CI_NODE_INDEX} ]; then
|
|
|
|
# Gitlab uses a 1-based index
|
|
|
|
CI_NODE_INDEX=1
|
|
|
|
echo "Assuming CI_NODE_INDEX=${CI_NODE_INDEX}"
|
|
|
|
fi
|
2017-02-10 06:38:24 +00:00
|
|
|
|
2017-12-28 10:20:14 +00:00
|
|
|
|
2020-04-22 06:49:05 +00:00
|
|
|
export EXTRA_CFLAGS="${PEDANTIC_CFLAGS:-}"
|
|
|
|
export EXTRA_CXXFLAGS="${PEDANTIC_CXXFLAGS:-}"
|
2016-12-06 18:39:56 +00:00
|
|
|
|
2020-04-22 06:49:05 +00:00
|
|
|
set -o nounset # Exit if variable not set.
|
2018-11-07 07:19:56 +00:00
|
|
|
|
2020-04-22 06:49:05 +00:00
|
|
|
export REALPATH=realpath
|
|
|
|
if [ "$(uname -s)" = "Darwin" ]; then
|
|
|
|
export REALPATH=grealpath
|
2017-06-07 08:30:25 +00:00
|
|
|
fi
|
|
|
|
|
2020-04-22 06:49:05 +00:00
|
|
|
# Convert LOG_PATH and BUILD_PATH to relative, to make the json file less verbose.
|
|
|
|
LOG_PATH=$(${REALPATH} --relative-to ${IDF_PATH} ${LOG_PATH})
|
|
|
|
BUILD_PATH=$(${REALPATH} --relative-to ${IDF_PATH} ${BUILD_PATH})
|
2017-06-06 10:26:31 +00:00
|
|
|
|
2020-04-22 06:49:05 +00:00
|
|
|
ALL_BUILD_LIST_JSON="${BUILD_PATH}/list.json"
|
|
|
|
JOB_BUILD_LIST_JSON="${BUILD_PATH}/list_job_${CI_NODE_INDEX}.json"
|
2017-06-07 08:30:25 +00:00
|
|
|
|
2020-04-22 06:49:05 +00:00
|
|
|
echo "build_examples running for target $IDF_TARGET"
|
2019-04-28 07:29:05 +00:00
|
|
|
|
2020-04-22 06:49:05 +00:00
|
|
|
cd ${IDF_PATH}
|
2017-06-07 08:30:25 +00:00
|
|
|
|
2020-04-22 06:49:05 +00:00
|
|
|
# This part of the script produces the same result for all the example build jobs. It may be moved to a separate stage
|
|
|
|
# (pre-build) later, then the build jobs will receive ${BUILD_LIST_JSON} file as an artifact.
|
2017-06-07 08:30:25 +00:00
|
|
|
|
2020-04-22 06:49:05 +00:00
|
|
|
# If changing the work-dir or build-dir format, remember to update the "artifacts" in gitlab-ci configs, and IDFApp.py.
|
2016-09-26 07:13:32 +00:00
|
|
|
|
2020-04-22 06:49:05 +00:00
|
|
|
${IDF_PATH}/tools/find_apps.py examples \
|
|
|
|
-vv \
|
|
|
|
--format json \
|
2020-04-22 09:05:59 +00:00
|
|
|
--build-system ${EXAMPLE_TEST_BUILD_SYSTEM} \
|
2020-04-22 06:49:05 +00:00
|
|
|
--target ${IDF_TARGET} \
|
|
|
|
--recursive \
|
|
|
|
--exclude examples/build_system/idf_as_lib \
|
|
|
|
--work-dir "${BUILD_PATH}/@f/@w/@t" \
|
|
|
|
--build-dir build \
|
|
|
|
--build-log "${LOG_PATH}/@f_@w.txt" \
|
|
|
|
--output ${ALL_BUILD_LIST_JSON} \
|
|
|
|
--config 'sdkconfig.ci=default' \
|
|
|
|
--config 'sdkconfig.ci.*=' \
|
|
|
|
--config '=default' \
|
2020-04-20 06:30:31 +00:00
|
|
|
--scan-tests-json ${SCAN_EXAMPLE_TEST_JSON}
|
2017-06-06 10:26:31 +00:00
|
|
|
|
2020-04-22 06:49:05 +00:00
|
|
|
# --config rules above explained:
|
|
|
|
# 1. If sdkconfig.ci exists, use it build the example with configuration name "default"
|
|
|
|
# 2. If sdkconfig.ci.* exists, use it to build the "*" configuration
|
|
|
|
# 3. If none of the above exist, build the default configuration under the name "default"
|
2018-08-30 03:24:34 +00:00
|
|
|
|
2020-04-22 06:49:05 +00:00
|
|
|
# The part below is where the actual builds happen
|
2016-12-06 18:39:56 +00:00
|
|
|
|
2020-04-22 06:49:05 +00:00
|
|
|
${IDF_PATH}/tools/build_apps.py \
|
|
|
|
-vv \
|
|
|
|
--format json \
|
|
|
|
--keep-going \
|
|
|
|
--parallel-count ${CI_NODE_TOTAL} \
|
|
|
|
--parallel-index ${CI_NODE_INDEX} \
|
|
|
|
--output-build-list ${JOB_BUILD_LIST_JSON} \
|
|
|
|
${ALL_BUILD_LIST_JSON}\
|
2016-12-30 05:13:07 +00:00
|
|
|
|
2016-09-26 07:13:32 +00:00
|
|
|
|
2020-04-22 06:49:05 +00:00
|
|
|
# Check for build warnings
|
2020-04-23 11:13:09 +00:00
|
|
|
#${IDF_PATH}/tools/ci/check_build_warnings.py -vv ${JOB_BUILD_LIST_JSON}
|