1
- #! /bin/bash
1
+ #! /usr/ bin/env bash
2
2
#
3
3
# Build all examples from the examples directory, out of tree to
4
4
# ensure they can run when copied to a new directory.
23
23
# -----------------------------------------------------------------------------
24
24
# Safety settings (see https://gist.github.com/ilg-ul/383869cbb01f61a51c4d).
25
25
26
- if [[ ! -z ${DEBUG } ]]
26
+ if [[ ! -z ${DEBUG_SHELL } ]]
27
27
then
28
28
set -x # Activate the expand mode if DEBUG is anything but empty.
29
29
fi
@@ -49,9 +49,6 @@ die() {
49
49
50
50
echo " build_examples running in ${PWD} "
51
51
52
- # only 0 or 1 arguments
53
- [ $# -le 1 ] || die " Have to run as $( basename $0 ) [<JOB_NAME>]"
54
-
55
52
export BATCH_BUILD=1
56
53
export V=0 # only build verbose if there's an error
57
54
@@ -62,41 +59,37 @@ FAILED_EXAMPLES=""
62
59
RESULT_ISSUES=22 # magic number result code for issues found
63
60
LOG_SUSPECTED=${LOG_PATH} /common_log.txt
64
61
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 )
65
65
66
- if [ $# -eq 0 ]
66
+ if [ -z " ${CI_NODE_TOTAL :- } " ]
67
67
then
68
68
START_NUM=0
69
+ if [ " ${1:- } " ]; then
70
+ START_NUM=$1
71
+ fi
69
72
END_NUM=999
70
73
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}
82
75
# 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}
85
77
86
78
# 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 )
88
80
[ -z ${NUM_OF_EXAMPLES} ] && die " NUM_OF_EXAMPLES is bad"
89
81
82
+
90
83
# separate intervals
91
84
# 57 / 5 == 12
92
85
NUM_OF_EX_PER_JOB=$(( (${NUM_OF_EXAMPLES} + ${NUM_OF_JOBS} - 1 ) / ${NUM_OF_JOBS} ))
93
86
[ -z ${NUM_OF_EX_PER_JOB} ] && die " NUM_OF_EX_PER_JOB is bad"
94
87
95
88
# 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} ))
97
90
[ -z ${START_NUM} ] && die " START_NUM is bad"
98
91
99
- END_NUM=$(( ( ${JOB_NUM} + 1 ) * ${NUM_OF_EX_PER_JOB} ))
92
+ END_NUM=$(( ${JOB_NUM} * ${NUM_OF_EX_PER_JOB} ))
100
93
[ -z ${END_NUM} ] && die " END_NUM is bad"
101
94
fi
102
95
@@ -109,45 +102,75 @@ build_example () {
109
102
local EXAMPLE_DIR=$( dirname " ${MAKE_FILE} " )
110
103
local EXAMPLE_NAME=$( basename " ${EXAMPLE_DIR} " )
111
104
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
+
112
116
echo " Building ${EXAMPLE_NAME} as ${ID} ..."
113
117
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} "
116
122
# 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
119
136
120
137
# build non-verbose first
121
138
local BUILDLOG=${LOG_PATH} /ex_${ID} _log.txt
122
139
touch ${BUILDLOG}
123
140
141
+ local FLASH_ARGS=build/download.config
142
+
124
143
make clean >> ${BUILDLOG} 2>&1 &&
125
144
make defconfig >> ${BUILDLOG} 2>&1 &&
126
145
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} ||
128
147
{
129
148
RESULT=$? ; FAILED_EXAMPLES+=" ${EXAMPLE_NAME} " ;
130
149
}
131
150
151
+ tail -n 1 ${FLASH_ARGS} .full > ${FLASH_ARGS} || :
152
+ test -s ${FLASH_ARGS} || die " Error: ${FLASH_ARGS} file is empty"
153
+
132
154
cat ${BUILDLOG}
133
155
popd
134
156
135
- grep -i " error\|warning" " ${BUILDLOG} " 2>&1 >> " ${LOG_SUSPECTED} " || :
157
+ grep -i " error\|warning\|command not found " " ${BUILDLOG} " 2>&1 >> " ${LOG_SUSPECTED} " || :
136
158
}
137
159
138
160
EXAMPLE_NUM=0
139
161
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}
142
166
do
143
167
if [[ $EXAMPLE_NUM -lt $START_NUM || $EXAMPLE_NUM -ge $END_NUM ]]
144
168
then
145
169
EXAMPLE_NUM=$(( $EXAMPLE_NUM + 1 ))
146
170
continue
147
171
fi
148
- echo " >>> example [ ${EXAMPLE_NUM} ] - $FN "
149
172
150
- build_example " ${EXAMPLE_NUM} " " ${FN } "
173
+ build_example " ${EXAMPLE_NUM} " " ${EXAMPLE_PATH } "
151
174
152
175
EXAMPLE_NUM=$(( $EXAMPLE_NUM + 1 ))
153
176
done
@@ -156,11 +179,21 @@ done
156
179
echo -e " \nFound issues:"
157
180
158
181
# 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
161
183
# "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} " \
164
197
&& RESULT=$RESULT_ISSUES \
165
198
|| echo -e " \tNone"
166
199
@@ -169,4 +202,4 @@ grep -v "error.[ochd]\|\ -Werror\|reassigning to symbol\|changes choice state" \
169
202
170
203
echo -e " \nReturn code = $RESULT "
171
204
172
- exit $RESULT
205
+ exit $RESULT
0 commit comments