2016-09-26 03:13:32 -04:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Build all examples from the examples directory, out of tree to
|
|
|
|
# ensure they can run when copied to a new directory.
|
|
|
|
#
|
|
|
|
# Runs as part of CI process.
|
|
|
|
#
|
2017-09-03 21:15:04 -04:00
|
|
|
# Assumes PWD is an out-of-tree build directory, and will copy examples
|
2017-06-07 04:30:25 -04:00
|
|
|
# to individual subdirectories, one by one.
|
2016-09-26 03:13:32 -04:00
|
|
|
#
|
2017-06-07 04:30:25 -04:00
|
|
|
#
|
|
|
|
# Without arguments it just builds all examples
|
|
|
|
#
|
|
|
|
# With one argument <JOB_NAME> it builds part of the examples. This is a useful for
|
|
|
|
# parallel execution in CI.
|
|
|
|
# <JOB_NAME> must look like this:
|
|
|
|
# <some_text_label>_<num>
|
|
|
|
# It scans .gitlab-ci.yaml to count number of jobs which have name "<some_text_label>_<num>"
|
|
|
|
# It scans the filesystem to count all examples
|
|
|
|
# Based on this, it decides to run qa set of examples.
|
|
|
|
#
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Safety settings (see https://gist.github.com/ilg-ul/383869cbb01f61a51c4d).
|
|
|
|
|
2018-03-27 01:13:35 -04:00
|
|
|
if [[ ! -z ${DEBUG_SHELL} ]]
|
2017-06-07 04:30:25 -04: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.
|
|
|
|
set -o nounset # Exit if variable not set.
|
|
|
|
|
|
|
|
# Remove the initial space and instead use '\n'.
|
|
|
|
IFS=$'\n\t'
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
die() {
|
|
|
|
echo "${1:-"Unknown Error"}" 1>&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
[ -z ${IDF_PATH} ] && die "IDF_PATH is not set"
|
2017-12-28 05:20:14 -05:00
|
|
|
[ -z ${LOG_PATH} ] && die "LOG_PATH is not set"
|
2018-01-04 23:38:44 -05:00
|
|
|
[ -d ${LOG_PATH} ] || mkdir -p ${LOG_PATH}
|
2017-06-07 04:30:25 -04:00
|
|
|
|
2017-08-31 23:42:39 -04:00
|
|
|
echo "build_examples running in ${PWD}"
|
|
|
|
|
2017-02-10 01:38:24 -05:00
|
|
|
export BATCH_BUILD=1
|
|
|
|
export V=0 # only build verbose if there's an error
|
|
|
|
|
2017-06-27 23:40:54 -04:00
|
|
|
shopt -s lastpipe # Workaround for Bash to use variables in loops (http://mywiki.wooledge.org/BashFAQ/024)
|
2017-12-28 05:20:14 -05:00
|
|
|
|
2016-09-26 03:13:32 -04:00
|
|
|
RESULT=0
|
2016-12-30 00:13:07 -05:00
|
|
|
FAILED_EXAMPLES=""
|
2017-12-28 05:20:14 -05:00
|
|
|
RESULT_ISSUES=22 # magic number result code for issues found
|
|
|
|
LOG_SUSPECTED=${LOG_PATH}/common_log.txt
|
2018-01-04 23:38:44 -05:00
|
|
|
touch ${LOG_SUSPECTED}
|
2018-12-10 00:26:40 -05:00
|
|
|
SDKCONFIG_DEFAULTS_CI=sdkconfig.ci
|
2016-12-06 13:39:56 -05:00
|
|
|
|
2018-11-07 02:19:56 -05:00
|
|
|
EXAMPLE_PATHS=$( find ${IDF_PATH}/examples/ -type f -name Makefile | grep -v "/build_system/cmake/" | sort )
|
|
|
|
|
2019-08-25 23:00:33 -04:00
|
|
|
if [ -z "${CI_NODE_TOTAL:-}" ]
|
2017-06-07 04:30:25 -04:00
|
|
|
then
|
|
|
|
START_NUM=0
|
|
|
|
END_NUM=999
|
|
|
|
else
|
2019-04-28 03:29:05 -04:00
|
|
|
JOB_NUM=${CI_NODE_INDEX}
|
2017-06-07 04:30:25 -04:00
|
|
|
# count number of the jobs
|
2019-04-28 03:29:05 -04:00
|
|
|
NUM_OF_JOBS=${CI_NODE_TOTAL}
|
2017-06-07 04:30:25 -04:00
|
|
|
|
|
|
|
# count number of examples
|
2018-11-07 02:19:56 -05:00
|
|
|
NUM_OF_EXAMPLES=$( echo "${EXAMPLE_PATHS}" | wc -l )
|
2017-06-07 04:30:25 -04:00
|
|
|
[ -z ${NUM_OF_EXAMPLES} ] && die "NUM_OF_EXAMPLES is bad"
|
|
|
|
|
|
|
|
# separate intervals
|
|
|
|
#57 / 5 == 12
|
|
|
|
NUM_OF_EX_PER_JOB=$(( (${NUM_OF_EXAMPLES} + ${NUM_OF_JOBS} - 1) / ${NUM_OF_JOBS} ))
|
|
|
|
[ -z ${NUM_OF_EX_PER_JOB} ] && die "NUM_OF_EX_PER_JOB is bad"
|
|
|
|
|
|
|
|
# ex.: [0; 12); [12; 24); [24; 36); [36; 48); [48; 60)
|
2019-04-28 03:29:05 -04:00
|
|
|
START_NUM=$(( (${JOB_NUM} - 1) * ${NUM_OF_EX_PER_JOB} ))
|
2017-06-07 04:30:25 -04:00
|
|
|
[ -z ${START_NUM} ] && die "START_NUM is bad"
|
|
|
|
|
2019-04-28 03:29:05 -04:00
|
|
|
END_NUM=$(( ${JOB_NUM} * ${NUM_OF_EX_PER_JOB} ))
|
2017-06-07 04:30:25 -04:00
|
|
|
[ -z ${END_NUM} ] && die "END_NUM is bad"
|
|
|
|
fi
|
|
|
|
|
2017-06-06 06:26:31 -04:00
|
|
|
build_example () {
|
2017-06-07 04:30:25 -04:00
|
|
|
local ID=$1
|
|
|
|
shift
|
2017-06-06 06:26:31 -04:00
|
|
|
local MAKE_FILE=$1
|
|
|
|
shift
|
2017-01-16 17:08:35 -05:00
|
|
|
|
2017-06-06 06:26:31 -04:00
|
|
|
local EXAMPLE_DIR=$(dirname "${MAKE_FILE}")
|
|
|
|
local EXAMPLE_NAME=$(basename "${EXAMPLE_DIR}")
|
2020-11-30 07:11:36 -05:00
|
|
|
|
2018-10-26 01:44:14 -04:00
|
|
|
# Check if the example needs a different base directory.
|
|
|
|
# Path of the Makefile relative to $IDF_PATH
|
|
|
|
local MAKE_FILE_REL=${MAKE_FILE#"${IDF_PATH}/"}
|
|
|
|
# Look for it in build_example_dirs.txt:
|
|
|
|
local COPY_ROOT_REL=$(sed -n -E "s|${MAKE_FILE_REL}[[:space:]]+(.*)|\1|p" < ${IDF_PATH}/tools/ci/build_example_dirs.txt)
|
|
|
|
if [[ -n "${COPY_ROOT_REL}" && -d "${IDF_PATH}/${COPY_ROOT_REL}/" ]]; then
|
|
|
|
local COPY_ROOT=${IDF_PATH}/${COPY_ROOT_REL}
|
|
|
|
else
|
|
|
|
local COPY_ROOT=${EXAMPLE_DIR}
|
|
|
|
fi
|
2017-06-06 06:26:31 -04:00
|
|
|
|
2017-06-07 04:30:25 -04:00
|
|
|
echo "Building ${EXAMPLE_NAME} as ${ID}..."
|
|
|
|
mkdir -p "example_builds/${ID}"
|
2018-10-26 01:44:14 -04:00
|
|
|
cp -r "${COPY_ROOT}" "example_builds/${ID}"
|
|
|
|
local COPY_ROOT_PARENT=$(dirname ${COPY_ROOT})
|
|
|
|
local EXAMPLE_DIR_REL=${EXAMPLE_DIR#"${COPY_ROOT_PARENT}"}
|
|
|
|
pushd "example_builds/${ID}/${EXAMPLE_DIR_REL}"
|
2017-01-16 17:08:35 -05:00
|
|
|
# be stricter in the CI build than the default IDF settings
|
2018-11-27 06:16:18 -05:00
|
|
|
export EXTRA_CFLAGS=${PEDANTIC_CFLAGS}
|
2017-01-16 17:08:35 -05:00
|
|
|
export EXTRA_CXXFLAGS=${EXTRA_CFLAGS}
|
|
|
|
|
2018-12-10 00:26:40 -05:00
|
|
|
# sdkconfig files are normally not checked into git, but may be present when
|
|
|
|
# a developer runs this script locally
|
|
|
|
rm -f sdkconfig
|
|
|
|
|
|
|
|
# If sdkconfig.ci file is present, append it to sdkconfig.defaults,
|
|
|
|
# replacing environment variables
|
|
|
|
if [[ -f "$SDKCONFIG_DEFAULTS_CI" ]]; then
|
2020-04-22 09:29:06 -04:00
|
|
|
# Make sure that the last line of sdkconfig.defaults is terminated. Otherwise, the first line
|
|
|
|
# of $SDKCONFIG_DEFAULTS_CI will be joined with the last one of sdkconfig.defaults.
|
|
|
|
echo >> sdkconfig.defaults
|
2018-12-10 00:26:40 -05:00
|
|
|
cat $SDKCONFIG_DEFAULTS_CI | $IDF_PATH/tools/ci/envsubst.py >> sdkconfig.defaults
|
|
|
|
fi
|
|
|
|
|
2017-01-16 17:08:35 -05:00
|
|
|
# build non-verbose first
|
2017-12-28 05:20:14 -05:00
|
|
|
local BUILDLOG=${LOG_PATH}/ex_${ID}_log.txt
|
2018-01-04 23:38:44 -05:00
|
|
|
touch ${BUILDLOG}
|
|
|
|
|
2018-10-31 06:33:51 -04:00
|
|
|
local FLASH_ARGS=build/download.config
|
|
|
|
|
2018-01-04 23:38:44 -05:00
|
|
|
make clean >>${BUILDLOG} 2>&1 &&
|
|
|
|
make defconfig >>${BUILDLOG} 2>&1 &&
|
|
|
|
make all >>${BUILDLOG} 2>&1 &&
|
2018-10-31 06:33:51 -04:00
|
|
|
make print_flash_cmd >${FLASH_ARGS}.full 2>>${BUILDLOG} ||
|
2018-01-04 23:38:44 -05:00
|
|
|
{
|
|
|
|
RESULT=$?; FAILED_EXAMPLES+=" ${EXAMPLE_NAME}" ;
|
2017-06-27 23:40:54 -04:00
|
|
|
}
|
2018-01-04 23:38:44 -05:00
|
|
|
|
2018-10-31 06:33:51 -04:00
|
|
|
tail -n 1 ${FLASH_ARGS}.full > ${FLASH_ARGS} || :
|
|
|
|
test -s ${FLASH_ARGS} || die "Error: ${FLASH_ARGS} file is empty"
|
|
|
|
|
2018-01-04 23:38:44 -05:00
|
|
|
cat ${BUILDLOG}
|
2017-06-06 06:26:31 -04:00
|
|
|
popd
|
|
|
|
|
2018-12-17 01:03:45 -05:00
|
|
|
grep -i "error\|warning\|command not found" "${BUILDLOG}" 2>&1 >> "${LOG_SUSPECTED}" || :
|
2017-06-06 06:26:31 -04:00
|
|
|
}
|
|
|
|
|
2017-06-07 04:30:25 -04:00
|
|
|
EXAMPLE_NUM=0
|
|
|
|
|
2019-04-28 03:29:05 -04:00
|
|
|
echo "Current job will build example ${START_NUM} - ${END_NUM}"
|
|
|
|
|
2018-11-07 02:19:56 -05:00
|
|
|
for EXAMPLE_PATH in ${EXAMPLE_PATHS}
|
2017-06-06 06:26:31 -04:00
|
|
|
do
|
2017-06-07 04:30:25 -04:00
|
|
|
if [[ $EXAMPLE_NUM -lt $START_NUM || $EXAMPLE_NUM -ge $END_NUM ]]
|
|
|
|
then
|
|
|
|
EXAMPLE_NUM=$(( $EXAMPLE_NUM + 1 ))
|
|
|
|
continue
|
|
|
|
fi
|
2018-11-07 02:19:56 -05:00
|
|
|
echo ">>> example [ ${EXAMPLE_NUM} ] - $EXAMPLE_PATH"
|
2017-06-07 04:30:25 -04:00
|
|
|
|
2018-11-07 02:19:56 -05:00
|
|
|
build_example "${EXAMPLE_NUM}" "${EXAMPLE_PATH}"
|
2017-06-07 04:30:25 -04:00
|
|
|
|
|
|
|
EXAMPLE_NUM=$(( $EXAMPLE_NUM + 1 ))
|
2016-09-26 03:13:32 -04:00
|
|
|
done
|
|
|
|
|
2017-06-06 06:26:31 -04:00
|
|
|
# show warnings
|
|
|
|
echo -e "\nFound issues:"
|
|
|
|
|
2017-12-28 05:20:14 -05:00
|
|
|
# Ignore the next messages:
|
|
|
|
# "error.o" or "-Werror" in compiler's command line
|
|
|
|
# "reassigning to symbol" or "changes choice state" in sdkconfig
|
2018-09-18 01:07:21 -04:00
|
|
|
# 'Compiler and toochain versions is not supported' from make/project.mk
|
2018-08-29 23:24:34 -04:00
|
|
|
IGNORE_WARNS="\
|
|
|
|
library/error\.o\
|
2018-09-18 01:07:21 -04:00
|
|
|
\|\ -Werror\
|
|
|
|
\|error\.d\
|
2018-08-29 23:24:34 -04:00
|
|
|
\|reassigning to symbol\
|
|
|
|
\|changes choice state\
|
|
|
|
\|Compiler version is not supported\
|
|
|
|
\|Toolchain version is not supported\
|
2020-11-30 07:11:36 -05:00
|
|
|
\|Python 3 versions older than 3.6 are not supported\
|
|
|
|
\|Python 2 is deprecated and will be removed in future versions\
|
2018-08-29 23:24:34 -04:00
|
|
|
"
|
|
|
|
|
|
|
|
sort -u "${LOG_SUSPECTED}" | grep -v "${IGNORE_WARNS}" \
|
2017-12-28 05:20:14 -05:00
|
|
|
&& RESULT=$RESULT_ISSUES \
|
|
|
|
|| echo -e "\tNone"
|
2016-12-06 13:39:56 -05:00
|
|
|
|
2017-12-28 05:20:14 -05:00
|
|
|
[ -z ${FAILED_EXAMPLES} ] || echo -e "\nThere are errors in the next examples: $FAILED_EXAMPLES"
|
|
|
|
[ $RESULT -eq 0 ] || echo -e "\nFix all warnings and errors above to pass the test!"
|
2016-12-30 00:13:07 -05:00
|
|
|
|
2017-06-07 04:30:25 -04:00
|
|
|
echo -e "\nReturn code = $RESULT"
|
2016-09-26 03:13:32 -04:00
|
|
|
|
2017-06-06 06:26:31 -04:00
|
|
|
exit $RESULT
|