Skip to content

Commit 943c938

Browse files
committed
Modify ci for parallel build examples
1 parent 68fd36b commit 943c938

File tree

2 files changed

+133
-50
lines changed

2 files changed

+133
-50
lines changed

.gitlab-ci.yml

+63-13
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,63 @@ before_script:
9494
- mkdir -p ${LOG_PATH}
9595
- ${ADF_PATH}/tools/ci/build_examples.sh "${CI_JOB_NAME}"
9696

97+
.build_examples_make: &build_examples_make
98+
<<: *build_template
99+
parallel: 4
100+
# This is a workaround for a rarely encountered issue with building examples in CI.
101+
# Probably related to building of Kconfig in 'make clean' stage
102+
retry: 1
103+
artifacts:
104+
when: always
105+
paths:
106+
- build_examples/*/*/*/build/*.bin
107+
- build_examples/*/*/*/sdkconfig
108+
- build_examples/*/*/*/build/*.elf
109+
- build_examples/*/*/*/build/*.map
110+
- build_examples/*/*/*/build/download.config
111+
- build_examples/*/*/*/build/bootloader/*.bin
112+
- build_examples/*/*/*/*/build/partition_table/*.bin
113+
- $LOG_PATH
114+
expire_in: 4 days
115+
variables:
116+
IDF_CI_BUILD: "1"
117+
LOG_PATH: "$CI_PROJECT_DIR/log_examples_make"
118+
# This is IDF CI limits
119+
# only:
120+
# # Here both 'variables' and 'refs' conditions are given. They are combined with "AND" logic.
121+
# variables:
122+
# - $BOT_TRIGGER_WITH_LABEL == null
123+
# - $BOT_LABEL_BUILD
124+
# - $BOT_LABEL_EXAMPLE_TEST
125+
# - $BOT_LABEL_REGULAR_TEST
126+
# - $BOT_LABEL_WEEKEND_TEST
127+
# refs:
128+
# - master
129+
# - /^release\/v/
130+
# - /^v\d+\.\d+(\.\d+)?($|-)/
131+
# - triggers
132+
# - schedules
133+
# - pipelines
134+
# - web
135+
script:
136+
# it's not possible to build 100% out-of-tree and have the "artifacts"
137+
# mechanism work, but this is the next best thing
138+
- rm -rf build_examples
139+
- mkdir build_examples
140+
- cd build_examples
141+
# build some of examples
142+
- mkdir -p ${LOG_PATH}
143+
144+
# enable pedantic flags for compilation
145+
- export PEDANTIC_CFLAGS="-Werror -Werror=deprecated-declarations -Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function"
146+
- export EXTRA_CFLAGS=${PEDANTIC_CFLAGS} && export EXTRA_CXXFLAGS=${EXTRA_CFLAGS}
147+
148+
- ${ADF_PATH}/tools/ci/build_examples.sh
149+
# Check if the tests demand Make built binaries. If not, delete them
150+
- if [ "$EXAMPLE_TEST_BUILD_SYSTEM" == "make" ]; then exit 0; fi
151+
- cd ..
152+
- rm -rf build_examples
153+
97154
# same as above, but for CMake
98155
.build_examples_cmake: &build_examples_cmake
99156
extends: .build_template
@@ -156,17 +213,8 @@ build_examples_v40_cmake:
156213
IDF_TARGET: esp32s2beta
157214
IDF_VERSION: release/v4.1
158215

159-
build_examples_00:
160-
<<: *build_examples_template
161-
162-
build_examples_01:
163-
<<: *build_examples_template
164-
165-
.build_examples_02:
166-
<<: *build_examples_template
167-
168-
.build_examples_03:
169-
<<: *build_examples_template
216+
build_examples_v33_make:
217+
<<: *build_examples_make
170218

171219
build_adf_test:
172220
<<: *build_template
@@ -231,7 +279,8 @@ assign_test:
231279
# we have a lot build example jobs. now we don't use dependencies, just download all artificats of build stage.
232280
dependencies:
233281
- build_adf_test
234-
- build_examples_00
282+
- build_examples_v33_make
283+
- build_examples_v40_cmake
235284
variables:
236285
TEST_FW_PATH: "$CI_PROJECT_DIR/general_test_framework"
237286
EXAMPLE_CONFIG_OUTPUT_PATH: "$CI_PROJECT_DIR/examples/test_configs"
@@ -254,7 +303,8 @@ assign_test:
254303
when: on_success
255304
dependencies:
256305
- assign_test
257-
- build_examples_00
306+
- build_examples_v33_make
307+
- build_examples_v40_cmake
258308
- build_adf_test
259309
artifacts:
260310
when: always

tools/ci/build_examples.sh

+70-37
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
#
33
# Build all examples from the examples directory, out of tree to
44
# ensure they can run when copied to a new directory.
@@ -23,7 +23,7 @@
2323
# -----------------------------------------------------------------------------
2424
# Safety settings (see https://gist.github.com/ilg-ul/383869cbb01f61a51c4d).
2525

26-
if [[ ! -z ${DEBUG} ]]
26+
if [[ ! -z ${DEBUG_SHELL} ]]
2727
then
2828
set -x # Activate the expand mode if DEBUG is anything but empty.
2929
fi
@@ -49,9 +49,6 @@ die() {
4949

5050
echo "build_examples running in ${PWD}"
5151

52-
# only 0 or 1 arguments
53-
[ $# -le 1 ] || die "Have to run as $(basename $0) [<JOB_NAME>]"
54-
5552
export BATCH_BUILD=1
5653
export V=0 # only build verbose if there's an error
5754

@@ -62,41 +59,37 @@ FAILED_EXAMPLES=""
6259
RESULT_ISSUES=22 # magic number result code for issues found
6360
LOG_SUSPECTED=${LOG_PATH}/common_log.txt
6461
touch ${LOG_SUSPECTED}
62+
SDKCONFIG_DEFAULTS_CI=sdkconfig.ci
63+
64+
EXAMPLE_PATHS=$( find ${ADF_PATH}/examples/ -type f -name Makefile | grep -v "/build_system/cmake/" | sort )
6565

66-
if [ $# -eq 0 ]
66+
if [ -z "${CI_NODE_TOTAL:-}" ]
6767
then
6868
START_NUM=0
69+
if [ "${1:-}" ]; then
70+
START_NUM=$1
71+
fi
6972
END_NUM=999
7073
else
71-
JOB_NAME=$1
72-
73-
# parse text prefix at the beginning of string 'some_your_text_NUM'
74-
# (will be 'some_your_text' without last '_')
75-
JOB_PATTERN=$( echo ${JOB_NAME} | sed -n -r 's/^(.*)_[0-9]+$/\1/p' )
76-
[ -z ${JOB_PATTERN} ] && die "JOB_PATTERN is bad"
77-
78-
# parse number 'NUM' at the end of string 'some_your_text_NUM'
79-
JOB_NUM=$( echo ${JOB_NAME} | sed -n -r 's/^.*_([0-9]+)$/\1/p' )
80-
[ -z ${JOB_NUM} ] && die "JOB_NUM is bad"
81-
74+
JOB_NUM=${CI_NODE_INDEX}
8275
# count number of the jobs
83-
NUM_OF_JOBS=$( grep -c -E "^${JOB_PATTERN}_[0-9]+:$" "${ADF_PATH}/.gitlab-ci.yml" )
84-
[ -z ${NUM_OF_JOBS} ] && die "NUM_OF_JOBS is bad"
76+
NUM_OF_JOBS=${CI_NODE_TOTAL}
8577

8678
# count number of examples
87-
NUM_OF_EXAMPLES=$( find ${ADF_PATH}/examples/ -type f -name Makefile | wc -l )
79+
NUM_OF_EXAMPLES=$( echo "${EXAMPLE_PATHS}" | wc -l )
8880
[ -z ${NUM_OF_EXAMPLES} ] && die "NUM_OF_EXAMPLES is bad"
8981

82+
9083
# separate intervals
9184
#57 / 5 == 12
9285
NUM_OF_EX_PER_JOB=$(( (${NUM_OF_EXAMPLES} + ${NUM_OF_JOBS} - 1) / ${NUM_OF_JOBS} ))
9386
[ -z ${NUM_OF_EX_PER_JOB} ] && die "NUM_OF_EX_PER_JOB is bad"
9487

9588
# ex.: [0; 12); [12; 24); [24; 36); [36; 48); [48; 60)
96-
START_NUM=$(( ${JOB_NUM} * ${NUM_OF_EX_PER_JOB} ))
89+
START_NUM=$(( (${JOB_NUM} - 1) * ${NUM_OF_EX_PER_JOB} ))
9790
[ -z ${START_NUM} ] && die "START_NUM is bad"
9891

99-
END_NUM=$(( (${JOB_NUM} + 1) * ${NUM_OF_EX_PER_JOB} ))
92+
END_NUM=$(( ${JOB_NUM} * ${NUM_OF_EX_PER_JOB} ))
10093
[ -z ${END_NUM} ] && die "END_NUM is bad"
10194
fi
10295

@@ -109,45 +102,75 @@ build_example () {
109102
local EXAMPLE_DIR=$(dirname "${MAKE_FILE}")
110103
local EXAMPLE_NAME=$(basename "${EXAMPLE_DIR}")
111104

105+
# Check if the example needs a different base directory.
106+
# Path of the Makefile relative to $IDF_PATH
107+
local MAKE_FILE_REL=${MAKE_FILE#"${IDF_PATH}/"}
108+
# Look for it in build_example_dirs.txt:
109+
local COPY_ROOT_REL=$(sed -n -E "s|${MAKE_FILE_REL}[[:space:]]+(.*)|\1|p" < ${IDF_PATH}/tools/ci/build_example_dirs.txt)
110+
if [[ -n "${COPY_ROOT_REL}" && -d "${IDF_PATH}/${COPY_ROOT_REL}/" ]]; then
111+
local COPY_ROOT=${IDF_PATH}/${COPY_ROOT_REL}
112+
else
113+
local COPY_ROOT=${EXAMPLE_DIR}
114+
fi
115+
112116
echo "Building ${EXAMPLE_NAME} as ${ID}..."
113117
mkdir -p "example_builds/${ID}"
114-
cp -r "${EXAMPLE_DIR}" "example_builds/${ID}"
115-
pushd "example_builds/${ID}/${EXAMPLE_NAME}"
118+
cp -r "${COPY_ROOT}" "example_builds/${ID}"
119+
local COPY_ROOT_PARENT=$(dirname ${COPY_ROOT})
120+
local EXAMPLE_DIR_REL=${EXAMPLE_DIR#"${COPY_ROOT_PARENT}"}
121+
pushd "example_builds/${ID}/${EXAMPLE_DIR_REL}"
116122
# be stricter in the CI build than the default IDF settings
117-
export EXTRA_CFLAGS="-Werror -Werror=deprecated-declarations"
118-
export EXTRA_CXXFLAGS=${EXTRA_CFLAGS}
123+
# export in CI script
124+
# export EXTRA_CFLAGS=${PEDANTIC_CFLAGS}
125+
# export EXTRA_CXXFLAGS=${PEDANTIC_CXXFLAGS}
126+
127+
# sdkconfig files are normally not checked into git, but may be present when
128+
# a developer runs this script locally
129+
rm -f sdkconfig
130+
131+
# If sdkconfig.ci file is present, append it to sdkconfig.defaults,
132+
# replacing environment variables
133+
if [[ -f "$SDKCONFIG_DEFAULTS_CI" ]]; then
134+
cat $SDKCONFIG_DEFAULTS_CI | $IDF_PATH/tools/ci/envsubst.py >> sdkconfig.defaults
135+
fi
119136

120137
# build non-verbose first
121138
local BUILDLOG=${LOG_PATH}/ex_${ID}_log.txt
122139
touch ${BUILDLOG}
123140

141+
local FLASH_ARGS=build/download.config
142+
124143
make clean >>${BUILDLOG} 2>&1 &&
125144
make defconfig >>${BUILDLOG} 2>&1 &&
126145
make all >>${BUILDLOG} 2>&1 &&
127-
( make print_flash_cmd | tail -n 1 >build/download.config ) >>${BUILDLOG} 2>&1 ||
146+
make print_flash_cmd >${FLASH_ARGS}.full 2>>${BUILDLOG} ||
128147
{
129148
RESULT=$?; FAILED_EXAMPLES+=" ${EXAMPLE_NAME}" ;
130149
}
131150

151+
tail -n 1 ${FLASH_ARGS}.full > ${FLASH_ARGS} || :
152+
test -s ${FLASH_ARGS} || die "Error: ${FLASH_ARGS} file is empty"
153+
132154
cat ${BUILDLOG}
133155
popd
134156

135-
grep -i "error\|warning" "${BUILDLOG}" 2>&1 >> "${LOG_SUSPECTED}" || :
157+
grep -i "error\|warning\|command not found" "${BUILDLOG}" 2>&1 >> "${LOG_SUSPECTED}" || :
136158
}
137159

138160
EXAMPLE_NUM=0
139161

140-
find ${ADF_PATH}/examples/ -type f -name Makefile | sort | \
141-
while read FN
162+
echo "Current job will build example ${START_NUM} - ${END_NUM}"
163+
echo "Current job will build example ${EXAMPLE_PATHS}"
164+
165+
for EXAMPLE_PATH in ${EXAMPLE_PATHS}
142166
do
143167
if [[ $EXAMPLE_NUM -lt $START_NUM || $EXAMPLE_NUM -ge $END_NUM ]]
144168
then
145169
EXAMPLE_NUM=$(( $EXAMPLE_NUM + 1 ))
146170
continue
147171
fi
148-
echo ">>> example [ ${EXAMPLE_NUM} ] - $FN"
149172

150-
build_example "${EXAMPLE_NUM}" "${FN}"
173+
build_example "${EXAMPLE_NUM}" "${EXAMPLE_PATH}"
151174

152175
EXAMPLE_NUM=$(( $EXAMPLE_NUM + 1 ))
153176
done
@@ -156,11 +179,21 @@ done
156179
echo -e "\nFound issues:"
157180

158181
# Ignore the next messages:
159-
# files end with error: "error.o" or "error.c" or "error.h" or "error.d"
160-
# "-Werror" in compiler's command line
182+
# "error.o" or "-Werror" in compiler's command line
161183
# "reassigning to symbol" or "changes choice state" in sdkconfig
162-
sort -u "${LOG_SUSPECTED}" | \
163-
grep -v "error.[ochd]\|\ -Werror\|reassigning to symbol\|changes choice state" \
184+
# 'Compiler and toochain versions is not supported' from make/project.mk
185+
IGNORE_WARNS="\
186+
library/error\.o\
187+
\|\ -Werror\
188+
\|.*error.*\.o\
189+
\|.*error.*\.d\
190+
\|reassigning to symbol\
191+
\|changes choice state\
192+
\|Compiler version is not supported\
193+
\|Toolchain version is not supported\
194+
"
195+
196+
sort -u "${LOG_SUSPECTED}" | grep -v "${IGNORE_WARNS}" \
164197
&& RESULT=$RESULT_ISSUES \
165198
|| echo -e "\tNone"
166199

@@ -169,4 +202,4 @@ grep -v "error.[ochd]\|\ -Werror\|reassigning to symbol\|changes choice state" \
169202

170203
echo -e "\nReturn code = $RESULT"
171204

172-
exit $RESULT
205+
exit $RESULT

0 commit comments

Comments
 (0)