forked from barebox/barebox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MAKEALL
executable file
·397 lines (334 loc) · 8.15 KB
/
MAKEALL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
#!/usr/bin/env bash
#
# SPDX-License-Identifier: GPL-2.0-only
# Keep track of the number of builds and errors
nb_warnings=0
warnings_list=""
nb_errors=0
errors_list=""
test_errors_list=""
nb_defconfigs=0
nb_tests=0
nb_tests_failed=0
exitcode=0
time_start=$(date +%s)
filename=$(basename $0)
#-----------------------------------------------------------------------
usage() {
echo "Usage: ${filename} [OPTION]..."
echo "Barebox MAKEALL tools."
echo ""
echo "it's allow you to compile specific defconfig or ARCH or all"
echo "as"
echo ""
echo "CROSS_COMPILE=arm-linux- ARCH=arm ./MAKEALL at91sam9263ek_defconfig"
echo "CROSS_COMPILE=arm-linux- ARCH=arm ./MAKEALL"
echo ""
echo "The cross-compiler can be specify via"
echo " CROSS_COMPILE default"
echo " CROSS_COMPILE_<arch> arch default"
echo " CROSS_COMPILE_<target> defconfig specific"
echo ""
echo "it will be evaluated in the invert order"
echo ""
echo "or via config"
echo ""
echo "you can specify it via env CONFIG or option -c (overwrite env)"
echo ""
echo "CONFIG=./MAKEALL.cfg ARCH=arm ./MAKEALL at91sam9263ek_defconfig"
echo "CONFIG=./MAKEALL.cfg ARCH=arm ./MAKEALL"
echo ""
echo "and for all"
echo ""
echo "CONFIG=./MAKEALL.cfg ./MAKEALL"
echo ""
echo "you can specify via env or option"
echo "env option"
echo "ARCH -a arch"
echo "CONFIG -c config"
echo "JOBS -j jobs"
echo "BUILDDIR -O build dir"
echo "LOGDIR -l log dir"
echo "REGEX -e regex"
echo "KCONFIG_ADD -k kconfig fragment"
echo "INCREMENTAL -i"
echo ""
}
stats() {
echo ""
echo "--------------------- SUMMARY ----------------------------"
echo "defconfigs compiled: ${nb_defconfigs}"
if [ ${nb_errors} -gt 0 ] ; then
echo -e "\tdefconfigs with errors: ${nb_errors} (${errors_list} )"
fi
if [ ${nb_warnings} -gt 0 ] ; then
echo -e "\tdefconfigs with warnings: ${nb_warnings} (${warnings_list} )"
fi
if [ ${nb_tests} -gt 0 ]; then
echo "defconfigs tested: ${nb_tests}"
if [ "${nb_tests_failed}" -gt 0 ]; then
echo -e "\tdefconfigs with errors: ${nb_tests_failed} (${test_errors_list} )"
fi
fi
time_stop=$(date +%s)
time_diff=$((${time_stop} - ${time_start}))
printf "Total time spent: %4is\n" ${time_diff}
echo "----------------------------------------------------------"
exit ${exitcode}
}
check_pipe_status() {
for i in "${PIPESTATUS[@]}"
do
[ $i -gt 0 ] && return 1
done
return 0
}
do_build_target() {
local arch=$1
local target=$2
local target_time_start=$(date +%s)
local log_report="${LOGDIR}/${target}/report.log"
local log_err="${LOGDIR}/${target}/errors.log"
local err=0
[ "$INCREMENTAL" != "1" ] && rm -rf "${BUILDDIR}"
mkdir -p "${LOGDIR}/${target}"
MAKE="make -j${JOBS} ARCH=${arch} O=${BUILDDIR}"
${MAKE} ${target} &>/dev/null
if [ ${arch} = "arm" ]; then
grep -q "CONFIG_ARM64=y" ${BUILDDIR}/.config
if [ $? = 0 ]; then
arch=arm64
fi
fi
tmp=$(echo "${target}" | tr - _)
cross_compile=$(eval echo '$CROSS_COMPILE_'${tmp})
cross_compile_set=$(eval echo '${CROSS_COMPILE_'${tmp}'+set}')
if [ "${cross_compile_set}" = "" ]
then
cross_compile=$(eval echo '$CROSS_COMPILE_'${arch})
cross_compile_set=$(eval echo '${CROSS_COMPILE_'${arch}'+set}')
if [ "${cross_compile_set}" = "" ]
then
cross_compile=${CROSS_COMPILE}
fi
fi
printf "Building ${arch} ${target} \n" >&2 | tee -a "${log_report}"
MAKE="${MAKE} CROSS_COMPILE=${cross_compile}"
${MAKE} ${target} 2>&1 > "${log_report}" | tee "${log_err}"
for i in ${KCONFIG_ADD}; do
./scripts/kconfig/merge_config.sh -m -O \
${BUILDDIR} ${BUILDDIR}/.config $i \
2>&1 > "${log_report}" | tee "${log_err}"
done
${MAKE} olddefconfig 2>&1 > "${log_report}" | tee "${log_err}"
check_pipe_status
configure_result="$?"
printf "Configure: " | tee -a "${log_report}"
if [ "$configure_result" = "0" ]; then
printf "OK \n" | tee -a "${log_report}"
${MAKE} -s 2>&1 >> "${log_report}" | tee -a "${log_err}"
check_pipe_status
compile_result="$?"
printf "Compile: " ${target} | tee -a "${log_report}"
if [ "$compile_result" = "0" ]; then
printf "OK \n" | tee -a "${log_report}"
else
printf "FAILED \n" | tee -a "${log_report}"
nb_errors=$((nb_errors + 1))
errors_list="${errors_list} ${target}"
err=1
exitcode=1
fi
else
printf "FAILED \n" | tee -a "${log_report}"
printf "Compile: ------ \n" | tee -a "${log_report}"
err=1
exitcode=1
fi
if [ -s "${log_err}" ] ; then
nb_warnings=$((nb_warnings + 1))
warnings_list="${warnings_list} ${target}"
else
rm "${log_err}"
fi
nb_defconfigs=$((nb_defconfigs + 1))
target_time_stop=$(date +%s)
target_time_diff=$((${target_time_stop} - ${target_time_start}))
printf "Compiled in %4is\n" ${target_time_diff} | tee -a "${log_report}"
return $err
}
if command -v labgrid-pytest >/dev/null; then
alias pytest=labgrid-pytest
fi
do_test_target() {
local yaml=$1
local target=$2
shift 2
local target_time_start=$(date +%s)
local log_report="${LOGDIR}/${target}/report.log"
local err=0
LG_BUILDDIR=$BUILDDIR pytest --lg-env $yaml "$@" 2>&1 >> "${log_report}"
check_pipe_status
compile_result="$?"
printf "Test: " ${yaml} | tee -a "${log_report}"
if [ "$compile_result" = "0" ]; then
printf "OK \n" | tee -a "${log_report}"
else
printf "FAILED \n" | tee -a "${log_report}"
nb_tests_failed=$((nb_tests_failed + 1))
test_errors_list="${test_errors_list} ${yaml}"
exitcode=1
err=1
fi
nb_tests=$((nb_tests + 1))
target_time_stop=$(date +%s)
target_time_diff=$((${target_time_stop} - ${target_time_start}))
printf "Tested in %4is\n" ${target_time_diff} | tee -a "${log_report}"
return $err
}
do_build() {
local arch=$1
local regex=$2
configs=$(find arch/${arch}/configs -name "${regex}_defconfig" | sort)
for i in ${configs}; do
local target=$(basename $i)
do_build_target ${arch} ${target}
done
}
do_build_all() {
local build_target=0
for i in arch/*
do
local arch=$(basename $i)
if [ -d $i ]
then
do_build ${arch} "*"
build_target=$((build_target + 1))
fi
done
return $build_target
}
while getopts "hc:j:O:l:a:e:k:i" Option
do
case $Option in
a )
ARCH=${OPTARG}
;;
c )
CONFIG=${OPTARG}
;;
j )
JOBS=${OPTARG}
;;
l )
LOGDIR=${OPTARG}
;;
O )
BUILDDIR=${OPTARG}
;;
e )
REGEX=${OPTARG}
;;
k )
KCONFIG_ADD="${KCONFIG_ADD} ${OPTARG}"
;;
i )
INCREMENTAL=1
;;
h )
usage
exit 0
;;
esac
done
shift $((OPTIND - 1))
if [ ! "${JOBS}" ] ; then
#linux, BSD, MacOS
nb_cpu=`getconf _NPROCESSORS_ONLN`
if [ $? -gt 0 ]
then
nb_cpu=1
fi
JOBS=$((${nb_cpu} * 2))
fi
if [ ! "${LOGDIR}" ]
then
LOGDIR="log"
fi
if [ ! "${BUILDDIR}" ]
then
BUILDDIR="makeall_builddir"
fi
if [ "${CONFIG}" ]
then
basedir=$(dirname ${CONFIG})
if [ ! "${basedir}" ] || [ "${basedir}" = "." ]
then
CONFIG="./${CONFIG}"
fi
. "${CONFIG}"
fi
[ -d "${LOGDIR}" ] || mkdir ${LOGDIR} || exit 1
if [ ! "${REGEX}" ]
then
REGEX="*"
fi
if [ $# -eq 0 ]
then
if [ ! "${ARCH}" ] || [ ! -d arch/${ARCH} ]
then
do_build_all
if [ $? -eq 0 ]
then
echo "You need to specify the ARCH or CROSS_COMPILE_<arch> or CROSS_COMPILE_<target> in your config file"
usage
exit 1
fi
exit 0
fi
do_build ${ARCH} "${REGEX}"
else
declare -a configs=()
declare -a pytest_opts=()
for i in $*; do
if [[ "$i" = "-"* ]] || [ ${#pytest_opts[@]} -gt 0 ]; then
pytest_opts+=($i)
continue;
fi
skip=0
# test/*/ may contain local symlinks, so resolve them
for j in "${configs[@]}"; do
if [ "$i" = "$j" ]; then
skip=1
break
fi
# drop duplicates, e.g. via globbing in directory with symlinks
if [[ $i =~ / && $j =~ / &&
"$(readlink -f $i)" == "$(readlink -f $j)" ]]; then
skip=1
break
fi
done
if [ $skip = 1 ]; then
continue;
fi
configs+=($i)
done
for i in "${configs[@]}"; do
config=$i
if [[ $i =~ ^.*/([^/]+)/([^@]*@|)([^.]+).yaml$ ]]; then
arch=${BASH_REMATCH[1]}
defconfig=${BASH_REMATCH[3]}
do_build_target $arch $defconfig
if [ $? -eq 0 ]; then
do_test_target $config $defconfig "${pytest_opts[@]}"
else
echo "Skipping test due to failed build"
fi
else
do_build_target ${ARCH} $config
fi
done
fi
stats
exit ${nb_errors}