2016-09-26 07:13:32 +00: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-04 01:15:04 +00:00
|
|
|
# Assumes PWD is an out-of-tree build directory, and will copy examples
|
2017-06-07 08:30:25 +00:00
|
|
|
# to individual subdirectories, one by one.
|
2016-09-26 07:13:32 +00:00
|
|
|
#
|
2017-06-07 08:30:25 +00: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 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.
|
|
|
|
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 10:20:14 +00:00
|
|
|
[ -z ${LOG_PATH} ] && die "LOG_PATH is not set"
|
2018-01-05 04:38:44 +00:00
|
|
|
[ -d ${LOG_PATH} ] || mkdir -p ${LOG_PATH}
|
2017-06-07 08:30:25 +00:00
|
|
|
|
2017-09-01 03:42:39 +00:00
|
|
|
echo "build_examples running in ${PWD}"
|
|
|
|
|
2017-02-10 06:38:24 +00:00
|
|
|
export BATCH_BUILD=1
|
|
|
|
export V=0 # only build verbose if there's an error
|
|
|
|
|
2017-06-28 03:40:54 +00:00
|
|
|
shopt -s lastpipe # Workaround for Bash to use variables in loops (http://mywiki.wooledge.org/BashFAQ/024)
|
2017-12-28 10:20:14 +00:00
|
|
|
|
2016-09-26 07:13:32 +00:00
|
|
|
RESULT=0
|
2016-12-30 05:13:07 +00:00
|
|
|
FAILED_EXAMPLES=""
|
2017-12-28 10:20:14 +00:00
|
|
|
RESULT_ISSUES=22 # magic number result code for issues found
|
|
|
|
LOG_SUSPECTED=${LOG_PATH}/common_log.txt
|
2018-01-05 04:38:44 +00:00
|
|
|
touch ${LOG_SUSPECTED}
|
2018-12-10 05:26:40 +00:00
|
|
|
SDKCONFIG_DEFAULTS_CI=sdkconfig.ci
|
2016-12-06 18:39:56 +00:00
|
|
|
|
2018-11-07 07:19:56 +00:00
|
|
|
EXAMPLE_PATHS=$( find ${IDF_PATH}/examples/ -type f -name Makefile | grep -v "/build_system/cmake/" | sort )
|
|
|
|
|
2019-07-30 14:26:43 +00:00
|
|
|
if [ -z "${CI_NODE_TOTAL:-}" ]
|
2017-06-07 08:30:25 +00:00
|
|
|
then
|
|
|
|
START_NUM=0
|
2019-07-30 14:26:43 +00:00
|
|
|
if [ "${1:-}" ]; then
|
|
|
|
START_NUM=$1
|
|
|
|
fi
|
2017-06-07 08:30:25 +00:00
|
|
|
END_NUM=999
|
|
|
|
else
|
2019-04-28 07:29:05 +00:00
|
|
|
JOB_NUM=${CI_NODE_INDEX}
|
2017-06-07 08:30:25 +00:00
|
|
|
# count number of the jobs
|
2019-04-28 07:29:05 +00:00
|
|
|
NUM_OF_JOBS=${CI_NODE_TOTAL}
|
2017-06-07 08:30:25 +00:00
|
|
|
|
|
|
|
# count number of examples
|
2018-11-07 07:19:56 +00:00
|
|
|
NUM_OF_EXAMPLES=$( echo "${EXAMPLE_PATHS}" | wc -l )
|
2017-06-07 08:30:25 +00: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 07:29:05 +00:00
|
|
|
START_NUM=$(( (${JOB_NUM} - 1) * ${NUM_OF_EX_PER_JOB} ))
|
2017-06-07 08:30:25 +00:00
|
|
|
[ -z ${START_NUM} ] && die "START_NUM is bad"
|
|
|
|
|
2019-04-28 07:29:05 +00:00
|
|
|
END_NUM=$(( ${JOB_NUM} * ${NUM_OF_EX_PER_JOB} ))
|
2017-06-07 08:30:25 +00:00
|
|
|
[ -z ${END_NUM} ] && die "END_NUM is bad"
|
|
|
|
fi
|
|
|
|
|
2017-06-06 10:26:31 +00:00
|
|
|
build_example () {
|
2017-06-07 08:30:25 +00:00
|
|
|
local ID=$1
|
|
|
|
shift
|
2017-06-06 10:26:31 +00:00
|
|
|
local MAKE_FILE=$1
|
|
|
|
shift
|
2017-01-16 22:08:35 +00:00
|
|
|
|
2017-06-06 10:26:31 +00:00
|
|
|
local EXAMPLE_DIR=$(dirname "${MAKE_FILE}")
|
|
|
|
local EXAMPLE_NAME=$(basename "${EXAMPLE_DIR}")
|
2018-10-26 05:44:14 +00: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 10:26:31 +00:00
|
|
|
|
2017-06-07 08:30:25 +00:00
|
|
|
echo "Building ${EXAMPLE_NAME} as ${ID}..."
|
|
|
|
mkdir -p "example_builds/${ID}"
|
2018-10-26 05:44:14 +00: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 22:08:35 +00:00
|
|
|
# be stricter in the CI build than the default IDF settings
|
2018-11-27 11:16:18 +00:00
|
|
|
export EXTRA_CFLAGS=${PEDANTIC_CFLAGS}
|
2019-03-19 08:02:35 +00:00
|
|
|
export EXTRA_CXXFLAGS=${PEDANTIC_CXXFLAGS}
|
2017-01-16 22:08:35 +00:00
|
|
|
|
2018-12-10 05:26:40 +00: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
|
|
|
|
cat $SDKCONFIG_DEFAULTS_CI | $IDF_PATH/tools/ci/envsubst.py >> sdkconfig.defaults
|
|
|
|
fi
|
|
|
|
|
2017-01-16 22:08:35 +00:00
|
|
|
# build non-verbose first
|
2017-12-28 10:20:14 +00:00
|
|
|
local BUILDLOG=${LOG_PATH}/ex_${ID}_log.txt
|
2018-01-05 04:38:44 +00:00
|
|
|
touch ${BUILDLOG}
|
|
|
|
|
2018-10-31 10:33:51 +00:00
|
|
|
local FLASH_ARGS=build/download.config
|
|
|
|
|
2018-01-05 04:38:44 +00:00
|
|
|
make clean >>${BUILDLOG} 2>&1 &&
|
|
|
|
make defconfig >>${BUILDLOG} 2>&1 &&
|
|
|
|
make all >>${BUILDLOG} 2>&1 &&
|
2018-10-31 10:33:51 +00:00
|
|
|
make print_flash_cmd >${FLASH_ARGS}.full 2>>${BUILDLOG} ||
|
2018-01-05 04:38:44 +00:00
|
|
|
{
|
|
|
|
RESULT=$?; FAILED_EXAMPLES+=" ${EXAMPLE_NAME}" ;
|
2017-06-28 03:40:54 +00:00
|
|
|
}
|
2018-01-05 04:38:44 +00:00
|
|
|
|
2018-10-31 10:33:51 +00:00
|
|
|
tail -n 1 ${FLASH_ARGS}.full > ${FLASH_ARGS} || :
|
|
|
|
test -s ${FLASH_ARGS} || die "Error: ${FLASH_ARGS} file is empty"
|
|
|
|
|
2018-01-05 04:38:44 +00:00
|
|
|
cat ${BUILDLOG}
|
2017-06-06 10:26:31 +00:00
|
|
|
popd
|
|
|
|
|
2018-12-17 06:03:45 +00:00
|
|
|
grep -i "error\|warning\|command not found" "${BUILDLOG}" 2>&1 >> "${LOG_SUSPECTED}" || :
|
2017-06-06 10:26:31 +00:00
|
|
|
}
|
|
|
|
|
2017-06-07 08:30:25 +00:00
|
|
|
EXAMPLE_NUM=0
|
|
|
|
|
2019-04-28 07:29:05 +00:00
|
|
|
echo "Current job will build example ${START_NUM} - ${END_NUM}"
|
|
|
|
|
2018-11-07 07:19:56 +00:00
|
|
|
for EXAMPLE_PATH in ${EXAMPLE_PATHS}
|
2017-06-06 10:26:31 +00:00
|
|
|
do
|
2017-06-07 08:30:25 +00:00
|
|
|
if [[ $EXAMPLE_NUM -lt $START_NUM || $EXAMPLE_NUM -ge $END_NUM ]]
|
|
|
|
then
|
|
|
|
EXAMPLE_NUM=$(( $EXAMPLE_NUM + 1 ))
|
|
|
|
continue
|
|
|
|
fi
|
2018-11-07 07:19:56 +00:00
|
|
|
echo ">>> example [ ${EXAMPLE_NUM} ] - $EXAMPLE_PATH"
|
2017-06-07 08:30:25 +00:00
|
|
|
|
2018-11-07 07:19:56 +00:00
|
|
|
build_example "${EXAMPLE_NUM}" "${EXAMPLE_PATH}"
|
2017-06-07 08:30:25 +00:00
|
|
|
|
|
|
|
EXAMPLE_NUM=$(( $EXAMPLE_NUM + 1 ))
|
2016-09-26 07:13:32 +00:00
|
|
|
done
|
|
|
|
|
2017-06-06 10:26:31 +00:00
|
|
|
# show warnings
|
|
|
|
echo -e "\nFound issues:"
|
|
|
|
|
2017-12-28 10:20:14 +00: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 05:07:21 +00:00
|
|
|
# 'Compiler and toochain versions is not supported' from make/project.mk
|
2018-08-30 03:24:34 +00:00
|
|
|
IGNORE_WARNS="\
|
|
|
|
library/error\.o\
|
2018-09-18 05:07:21 +00:00
|
|
|
\|\ -Werror\
|
|
|
|
\|error\.d\
|
2018-08-30 03:24:34 +00:00
|
|
|
\|reassigning to symbol\
|
|
|
|
\|changes choice state\
|
|
|
|
\|Compiler version is not supported\
|
|
|
|
\|Toolchain version is not supported\
|
|
|
|
"
|
|
|
|
|
|
|
|
sort -u "${LOG_SUSPECTED}" | grep -v "${IGNORE_WARNS}" \
|
2017-12-28 10:20:14 +00:00
|
|
|
&& RESULT=$RESULT_ISSUES \
|
|
|
|
|| echo -e "\tNone"
|
2016-12-06 18:39:56 +00:00
|
|
|
|
2017-12-28 10:20:14 +00: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 05:13:07 +00:00
|
|
|
|
2017-06-07 08:30:25 +00:00
|
|
|
echo -e "\nReturn code = $RESULT"
|
2016-09-26 07:13:32 +00:00
|
|
|
|
2017-06-06 10:26:31 +00:00
|
|
|
exit $RESULT
|