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-06-07 08:30:25 +00:00
|
|
|
# Assumes CWD is an out-of-tree build directory, and will copy examples
|
|
|
|
# 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).
|
|
|
|
|
|
|
|
if [[ ! -z ${DEBUG} ]]
|
|
|
|
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"
|
|
|
|
|
|
|
|
# only 0 or 1 arguments
|
|
|
|
[ $# -le 1 ] || die "Have to run as $(basename $0) [<JOB_NAME>]"
|
2016-09-26 07:13:32 +00:00
|
|
|
|
2017-02-10 06:38:24 +00:00
|
|
|
export BATCH_BUILD=1
|
|
|
|
export V=0 # only build verbose if there's an error
|
|
|
|
|
2016-09-26 07:13:32 +00:00
|
|
|
RESULT=0
|
2016-12-30 05:13:07 +00:00
|
|
|
FAILED_EXAMPLES=""
|
2016-09-26 07:13:32 +00:00
|
|
|
|
2016-12-06 18:39:56 +00:00
|
|
|
RESULT_WARNINGS=22 # magic number result code for "warnings found"
|
2017-06-06 10:26:31 +00:00
|
|
|
LOG_WARNINGS=$(mktemp -t example_all.XXXX.log)
|
2016-12-06 18:39:56 +00:00
|
|
|
|
2017-06-07 08:30:25 +00:00
|
|
|
if [ $# -eq 0 ]
|
|
|
|
then
|
|
|
|
START_NUM=0
|
|
|
|
END_NUM=999
|
|
|
|
else
|
|
|
|
JOB_NAME=$1
|
|
|
|
|
|
|
|
# parse text prefix at the beginning of string 'some_your_text_NUM'
|
|
|
|
# (will be 'some_your_text' without last '_')
|
|
|
|
JOB_PATTERN=$( echo ${JOB_NAME} | sed -n -r 's/^(.*)_[0-9]+$/\1/p' )
|
|
|
|
[ -z ${JOB_PATTERN} ] && die "JOB_PATTERN is bad"
|
|
|
|
|
|
|
|
# parse number 'NUM' at the end of string 'some_your_text_NUM'
|
|
|
|
JOB_NUM=$( echo ${JOB_NAME} | sed -n -r 's/^.*_([0-9]+)$/\1/p' )
|
|
|
|
[ -z ${JOB_NUM} ] && die "JOB_NUM is bad"
|
|
|
|
|
|
|
|
# count number of the jobs
|
|
|
|
NUM_OF_JOBS=$( grep -c -E "^${JOB_PATTERN}_[0-9]+:$" "${IDF_PATH}/.gitlab-ci.yml" )
|
|
|
|
[ -z ${NUM_OF_JOBS} ] && die "NUM_OF_JOBS is bad"
|
|
|
|
|
|
|
|
# count number of examples
|
|
|
|
NUM_OF_EXAMPLES=$( find ${IDF_PATH}/examples/ -type f -name Makefile | wc -l )
|
|
|
|
[ -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)
|
|
|
|
START_NUM=$(( ${JOB_NUM} * ${NUM_OF_EX_PER_JOB} ))
|
|
|
|
[ -z ${START_NUM} ] && die "START_NUM is bad"
|
|
|
|
|
|
|
|
END_NUM=$(( (${JOB_NUM} + 1) * ${NUM_OF_EX_PER_JOB} ))
|
|
|
|
[ -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}")
|
|
|
|
|
2017-06-07 08:30:25 +00:00
|
|
|
echo "Building ${EXAMPLE_NAME} as ${ID}..."
|
|
|
|
mkdir -p "example_builds/${ID}"
|
|
|
|
cp -r "${EXAMPLE_DIR}" "example_builds/${ID}"
|
|
|
|
pushd "example_builds/${ID}/${EXAMPLE_NAME}"
|
2017-01-16 22:08:35 +00:00
|
|
|
# be stricter in the CI build than the default IDF settings
|
|
|
|
export EXTRA_CFLAGS="-Werror -Werror=deprecated-declarations"
|
|
|
|
export EXTRA_CXXFLAGS=${EXTRA_CFLAGS}
|
|
|
|
|
|
|
|
# build non-verbose first
|
2017-06-06 10:26:31 +00:00
|
|
|
local BUILDLOG=$(mktemp -t examplebuild.XXXX.log)
|
2017-01-16 22:08:35 +00:00
|
|
|
(
|
|
|
|
make clean defconfig
|
2017-06-07 08:30:25 +00:00
|
|
|
make all 2>&1 | tee "${BUILDLOG}"
|
2017-06-06 10:26:31 +00:00
|
|
|
) || { RESULT=$?; FAILED_EXAMPLES+=" ${EXAMPLE_NAME}"; make V=1; } # verbose output for errors
|
|
|
|
popd
|
|
|
|
|
|
|
|
if grep ": warning:" "${BUILDLOG}" 2>&1 >> "${LOG_WARNINGS}"; then
|
|
|
|
[ $RESULT -eq 0 ] && RESULT=$RESULT_WARNINGS
|
|
|
|
FAILED_EXAMPLES+=" ${EXAMPLE_NAME} (warnings)"
|
|
|
|
fi
|
|
|
|
|
2017-06-07 08:30:25 +00:00
|
|
|
grep -i error "${BUILDLOG}" 2>&1 >> "${LOG_WARNINGS}" || :
|
2017-06-06 10:26:31 +00:00
|
|
|
|
|
|
|
rm -f "${BUILDLOG}"
|
|
|
|
}
|
|
|
|
|
2017-06-07 08:30:25 +00:00
|
|
|
EXAMPLE_NUM=0
|
|
|
|
|
2017-06-06 10:26:31 +00:00
|
|
|
find ${IDF_PATH}/examples/ -type f -name Makefile | \
|
2017-06-07 08:30:25 +00:00
|
|
|
while read FN
|
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
|
|
|
|
echo ">>> example [ ${EXAMPLE_NUM} ] - $FN"
|
|
|
|
|
|
|
|
build_example "${EXAMPLE_NUM}" "${FN}"
|
|
|
|
|
|
|
|
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:"
|
|
|
|
# pattern is: not 'error.o' and not '-Werror'
|
2017-06-07 08:30:25 +00:00
|
|
|
grep -v "error.o\|\-Werror" -- "${LOG_WARNINGS}" || echo -e "\tNone"
|
2017-06-06 10:26:31 +00:00
|
|
|
rm -f "${LOG_WARNINGS}"
|
|
|
|
|
2016-12-06 18:39:56 +00:00
|
|
|
if [ $RESULT -eq $RESULT_WARNINGS ]; then
|
|
|
|
echo "Build would have passed, except for warnings."
|
|
|
|
fi
|
|
|
|
|
2016-12-30 05:13:07 +00:00
|
|
|
[ $RESULT -eq 0 ] || echo "Failed examples: $FAILED_EXAMPLES"
|
|
|
|
|
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
|