forked from apache/nuttx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestbuild.sh
executable file
·459 lines (390 loc) · 10.6 KB
/
testbuild.sh
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
#!/usr/bin/env bash
# tools/testbuild.sh
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
WD=$(cd $(dirname $0) && cd .. && pwd)
nuttx=$WD/../nuttx
progname=$0
fail=0
APPSDIR=$WD/../apps
if [ -z $ARTIFACTDIR ]; then
ARTIFACTDIR=$WD/../buildartifacts
fi
MAKE_FLAGS=-k
EXTRA_FLAGS="EXTRAFLAGS="
MAKE=make
unset testfile
unset HOPTION
unset JOPTION
PRINTLISTONLY=0
GITCLEAN=0
SAVEARTIFACTS=0
CHECKCLEAN=1
CODECHECKER=0
RUN=0
case $(uname -s) in
Darwin*)
HOST=Darwin
;;
CYGWIN*)
HOST=Cygwin
;;
MINGW32*)
HOST=MinGw
;;
*)
# Assume linux as a fallback
HOST=Linux
;;
esac
function showusage {
echo ""
echo "USAGE: $progname [-l|m|c|g|n] [-d] [-e <extraflags>] [-x] [-j <ncpus>] [-a <appsdir>] [-t <topdir>] [-p] [-G] [--codechecker] <testlist-file>"
echo " $progname -h"
echo ""
echo "Where:"
echo " -l|m|c|g|n selects Linux (l), macOS (m), Cygwin (c),"
echo " MSYS/MSYS2 (g) or Windows native (n). Default Linux"
echo " -d enables script debug output"
echo " -e pass extra c/c++ flags such as -Wno-cpp via make command line"
echo " -x exit on build failures"
echo " -j <ncpus> passed on to make. Default: No -j make option."
echo " -a <appsdir> provides the relative path to the apps/ directory. Default ../apps"
echo " -t <topdir> provides the absolute path to top nuttx/ directory. Default ../nuttx"
echo " -p only print the list of configs without running any builds"
echo " -A store the build executable artifact in ARTIFACTDIR (defaults to ../buildartifacts"
echo " -C Skip tree cleanness check."
echo " -G Use \"git clean -xfdq\" instead of \"make distclean\" to clean the tree."
echo " This option may speed up the builds. However, note that:"
echo " * This assumes that your trees are git based."
echo " * This assumes that only nuttx and apps repos need to be cleaned."
echo " * If the tree has files not managed by git, they will be removed"
echo " as well."
echo " -R execute \"run\" script in the config directories if exists."
echo " -h will show this help test and terminate"
echo " --codechecker enables CodeChecker statically analyze the code."
echo " <testlist-file> selects the list of configurations to test. No default"
echo ""
echo "Your PATH variable must include the path to both the build tools and the"
echo "kconfig-frontends tools"
echo ""
exit 1
}
# Parse command line
while [ ! -z "$1" ]; do
case $1 in
-l | -m | -c | -g | -n )
HOPTION+=" $1"
;;
-d )
set -x
;;
-e )
shift
EXTRA_FLAGS+="$1"
;;
-x )
MAKE_FLAGS='--silent --no-print-directory'
set -e
;;
-a )
shift
APPSDIR="$1"
;;
-j )
shift
JOPTION="-j $1"
;;
-t )
shift
nuttx="$1"
;;
-p )
PRINTLISTONLY=1
;;
-G )
GITCLEAN=1
;;
-A )
SAVEARTIFACTS=1
;;
-C )
CHECKCLEAN=0
;;
-R )
RUN=1
;;
--codechecker )
CODECHECKER=1
;;
-h )
showusage
;;
* )
testfile="$1"
shift
break
;;
esac
shift
done
if [ ! -z "$1" ]; then
echo "ERROR: Garbage at the end of line"
showusage
fi
if [ -z "$testfile" ]; then
echo "ERROR: Missing test list file"
showusage
fi
if [ ! -r "$testfile" ]; then
echo "ERROR: No readable file exists at $testfile"
showusage
fi
if [ ! -d "$nuttx" ]; then
echo "ERROR: Expected to find nuttx/ at $nuttx"
showusage
fi
if [ ! -d $APPSDIR ]; then
echo "ERROR: No directory found at $APPSDIR"
exit 1
fi
export APPSDIR
testlist=`grep -v -E "^(-|#)" $testfile || true`
blacklist=`grep "^-" $testfile || true`
cd $nuttx || { echo "ERROR: failed to CD to $nuttx"; exit 1; }
function exportandimport {
# Do nothing until we finish to build the nuttx
if [ ! -f nuttx ]; then
return $fail
fi
# If CONFIG_BUILD_KERNEL=y does not exist in .config, do nothing
if ! grep CONFIG_BUILD_KERNEL=y .config 1>/dev/null; then
return $fail
fi
if ! ${MAKE} export ${JOPTION} 1>/dev/null; then
fail=1
return $fail
fi
pushd ../apps/
if ! ./tools/mkimport.sh -z -x ../nuttx/nuttx-export-*.tar.gz 1>/dev/null; then
fail=1
popd
return $fail
fi
if ! ${MAKE} import ${JOPTION} 1>/dev/null; then
fail=1
fi
popd
return $fail
}
function compressartifacts {
local target_path=$1
local target_name=$2
pushd $target_path >/dev/null
tar zcf ${target_name}.tar.gz ${target_name}
rm -rf ${target_name}
popd >/dev/null
}
function makefunc {
if ! ${MAKE} ${MAKE_FLAGS} "${EXTRA_FLAGS}" ${JOPTION} $@ 1>/dev/null; then
fail=1
else
exportandimport
fi
return $fail
}
function checkfunc {
build_cmd="${MAKE} ${MAKE_FLAGS} \"${EXTRA_FLAGS}\" ${JOPTION} 1>/dev/null"
local config_sub_path=$(echo "$config" | sed "s/:/\//")
local sub_target_name=${config_sub_path#$(dirname "${config_sub_path}")/}
local codechecker_dir=${ARTIFACTDIR}/codechecker_logs/${config_sub_path}
mkdir -p "${codechecker_dir}"
echo " Checking NuttX by Codechecker..."
CodeChecker check -b "${build_cmd}" -o "${codechecker_dir}/logs" -e sensitive --ctu
codecheck_ret=$?
echo " Storing analysis result to CodeChecker..."
echo " Generating HTML report..."
CodeChecker parse --export html --output "${codechecker_dir}/html" "${codechecker_dir}/logs" 1>/dev/null
echo " Compressing logs..."
compressartifacts "$(dirname "${codechecker_dir}")" "${sub_target_name}"
# If you need to stop CI, uncomment the following line.
# if [ $codecheck_ret -ne 0 ]; then
# fail=1
# fi
return $fail
}
# Clean up after the last build
function distclean {
echo " Cleaning..."
if [ -f .config ]; then
if [ ${GITCLEAN} -eq 1 ]; then
git -C $nuttx clean -xfdq
git -C $APPSDIR clean -xfdq
else
makefunc distclean
# Remove .version manually because this file is shipped with
# the release package and then distclean has to keep it
rm -f .version
# Ensure nuttx and apps directory in clean state even with --ignored
if [ ${CHECKCLEAN} -ne 0 ]; then
if [ -d $nuttx/.git ] || [ -d $APPSDIR/.git ]; then
if [[ -n $(git -C $nuttx status --ignored -s) ]]; then
git -C $nuttx status --ignored
fail=1
fi
if [[ -n $(git -C $APPSDIR status --ignored -s) ]]; then
git -C $APPSDIR status --ignored
fail=1
fi
fi
fi
fi
fi
return $fail
}
# Configure for the next build
function configure {
echo " Configuring..."
if ! ./tools/configure.sh ${HOPTION} $config ${JOPTION} 1>/dev/null; then
fail=1
fi
if [ "X$toolchain" != "X" ]; then
setting=`grep _TOOLCHAIN_ $nuttx/.config | grep -v CONFIG_ARCH_TOOLCHAIN_* | grep =y`
varname=`echo $setting | cut -d'=' -f1`
if [ ! -z "$varname" ]; then
echo " Disabling $varname"
kconfig-tweak --file $nuttx/.config -d $varname
fi
echo " Enabling $toolchain"
kconfig-tweak --file $nuttx/.config -e $toolchain
makefunc olddefconfig
fi
return $fail
}
# Perform the next build
function build {
echo " Building NuttX..."
if [ "${CODECHECKER}" -eq 1 ]; then
checkfunc
else
makefunc
fi
if [ ${SAVEARTIFACTS} -eq 1 ]; then
artifactconfigdir=$ARTIFACTDIR/$(echo $config | sed "s/:/\//")/
mkdir -p $artifactconfigdir
xargs -I "{}" cp "{}" $artifactconfigdir < $nuttx/nuttx.manifest
fi
return $fail
}
function refresh {
# Ensure defconfig in the canonical form
if ! ./tools/refresh.sh --silent $config; then
fail=1
fi
# Ensure nuttx and apps directory in clean state
if [ ${CHECKCLEAN} -ne 0 ]; then
if [ -d $nuttx/.git ] || [ -d $APPSDIR/.git ]; then
if [[ -n $(git -C $nuttx status -s) ]]; then
git -C $nuttx status
fail=1
fi
if [[ -n $(git -C $APPSDIR status -s) ]]; then
git -C $APPSDIR status
fail=1
fi
fi
fi
return $fail
}
function run {
if [ ${RUN} -ne 0 ]; then
run_script="$path/run"
if [ -x $run_script ]; then
echo " Running NuttX..."
if ! $run_script; then
fail=1
fi
fi
fi
return $fail
}
# Coordinate the steps for the next build test
function dotest {
echo "===================================================================================="
config=`echo $1 | cut -d',' -f1`
check=${HOST},${config/\//:}
skip=0
for re in $blacklist; do
if [[ "${check}" =~ ${re:1}$ ]]; then
echo "Skipping: $1"
skip=1
fi
done
echo "Configuration/Tool: $1"
if [ ${PRINTLISTONLY} -eq 1 ]; then
return
fi
# Parse the next line
configdir=`echo $config | cut -s -d':' -f2`
if [ -z "${configdir}" ]; then
configdir=`echo $config | cut -s -d'/' -f2`
if [ -z "${configdir}" ]; then
echo "ERROR: Malformed configuration: ${config}"
showusage
else
boarddir=`echo $config | cut -d'/' -f1`
fi
else
boarddir=`echo $config | cut -d':' -f1`
fi
path=$nuttx/boards/*/*/$boarddir/configs/$configdir
if [ ! -r $path/defconfig ]; then
echo "ERROR: no configuration found at $path"
showusage
fi
unset toolchain
if [ "X$config" != "X$1" ]; then
toolchain=`echo $1 | cut -d',' -f2`
if [ -z "$toolchain" ]; then
echo " Warning: no tool configuration"
fi
fi
# Perform the build test
echo "------------------------------------------------------------------------------------"
distclean
configure
if [ ${skip} -ne 1 ]; then
build
run
fi
refresh
}
# Perform the build test for each entry in the test list file
for line in $testlist; do
firstch=${line:0:1}
if [ "X$firstch" == "X/" ]; then
dir=`echo $line | cut -d',' -f1`
list=`find boards$dir -name defconfig | cut -d'/' -f4,6`
for i in ${list}; do
dotest $i${line/"$dir"/}
done
else
dotest $line
fi
done
echo "===================================================================================="
exit $fail