Skip to content

Commit 8502cea

Browse files
committed
.github/scripts: Add multiple parameters to the build and test scripts in case a customization is required.
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
1 parent bd83727 commit 8502cea

File tree

5 files changed

+229
-108
lines changed

5 files changed

+229
-108
lines changed

.github/scripts/on-push.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ function build(){
1414
local BUILD_SKETCH="${SCRIPTS_DIR}/sketch_utils.sh build"
1515
local BUILD_SKETCHES="${SCRIPTS_DIR}/sketch_utils.sh chunk_build"
1616

17-
local args="$ARDUINO_IDE_PATH $ARDUINO_USR_PATH"
17+
local args="-ai $ARDUINO_IDE_PATH -au $ARDUINO_USR_PATH"
1818

19-
args+=" \"$fqbn\""
19+
args+=" -fqbn $fqbn"
2020

2121
if [ "$OS_IS_LINUX" == "1" ]; then
22-
args+=" $target"
2322
args+=" $ARDUINO_ESP32_PATH/libraries"
2423
args+=" $chunk_index $chunks_cnt"
2524
${BUILD_SKETCHES} ${args}
@@ -29,11 +28,12 @@ function build(){
2928
local preprocessor_version=`ls "$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/"`
3029
win_opts="-prefs=runtime.tools.ctags.path=$ARDUINO_IDE_PATH/tools-builder/ctags/$ctags_version
3130
-prefs=runtime.tools.arduino-preprocessor.path=$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/$preprocessor_version"
32-
args+=" ${win_opts}"
31+
args+="-w \"${win_opts}\""
3332
fi
3433

3534
for sketch in ${sketches}; do
36-
${BUILD_SKETCH} ${args} ${sketch}
35+
args+=" -s $sketch"
36+
${BUILD_SKETCH} ${args}
3737
done
3838
fi
3939
}
@@ -82,7 +82,7 @@ if [ "$BUILD_PIO" -eq 0 ]; then
8282
build "esp32s3" $FQBN_ESP32S3 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32
8383
build "esp32s2" $FQBN_ESP32S2 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32XX
8484
build "esp32c3" $FQBN_ESP32C3 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32XX
85-
build "esp32" $FQBN_ESP32 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32
85+
build "esp32" $FQBN_ESP32 $CHUNK_INDEX $CHUNKS_CNT $SKETCHES_ESP32
8686
else
8787
source ${SCRIPTS_DIR}/install-platformio-esp32.sh
8888
# PlatformIO ESP32 Test

.github/scripts/sketch_utils.sh

Lines changed: 189 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,141 @@
11
#!/bin/bash
22

3-
function build_sketch(){ # build_sketch <ide_path> <user_path> <fqbn> <path-to-ino> [extra-options]
4-
if [ "$#" -lt 4 ]; then
5-
echo "ERROR: Illegal number of parameters"
6-
echo "USAGE: ${0} build <ide_path> <user_path> <fqbn> <path-to-ino> [extra-options]"
7-
return 1
3+
function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [extra-options]
4+
# Options default values
5+
6+
local fm_opt="qio"
7+
local ff_opt="80"
8+
local fs_opt="4M"
9+
local partition_opt="huge_app"
10+
11+
local options=0
12+
13+
while [ ! -z "$1" ]; do
14+
case "$1" in
15+
-ai )
16+
shift
17+
ide_path=$1
18+
;;
19+
-au )
20+
shift
21+
user_path=$1
22+
;;
23+
-t )
24+
shift
25+
target=$1
26+
;;
27+
-s )
28+
shift
29+
sketchdir=$1
30+
;;
31+
-w )
32+
shift
33+
win_opts=$1
34+
;;
35+
-fqbn )
36+
shift
37+
fqbn=$1
38+
;;
39+
-ff )
40+
shift
41+
ff_opt=$1
42+
options=1
43+
;;
44+
-fm )
45+
shift
46+
fm_opt=$1
47+
options=1
48+
;;
49+
-fs )
50+
shift
51+
fs_opt=$1
52+
options=1
53+
;;
54+
* )
55+
break
56+
;;
57+
esac
58+
shift
59+
done
60+
61+
xtra_opts=$*
62+
63+
if [ -z $sketchdir ]; then
64+
echo "ERROR: Sketch directory not provided"
65+
echo "$USAGE"
66+
exit 1
867
fi
968

10-
local ide_path=$1
11-
local usr_path=$2
12-
local fqbn=$3
13-
local sketch=$4
14-
local xtra_opts=$5
15-
local win_opts=$6
69+
# No FQBN was passed, try to get it from other options
70+
71+
if [ -z $fqbn ]; then
72+
if [ -z $target ]; then
73+
echo "ERROR: Unspecified chip"
74+
echo "$USAGE"
75+
exit 1
76+
fi
77+
78+
# Select the common part of the FQBN based on the target. The rest will be
79+
# appended depending on the passed options.
80+
81+
case "$target" in
82+
"esp32") fqbn="espressif:esp32:esp32:"
83+
;;
84+
"esp32s2") fqbn="espressif:esp32:esp32s2:"
85+
;;
86+
"esp32c3") fqbn="espressif:esp32:esp32c3:"
87+
;;
88+
"esp32s3") fqbn="espressif:esp32:esp32s3:"
89+
;;
90+
esac
91+
92+
# The options are either stored in the test directory, for a per test
93+
# customization or passed as parameters. Command line options take
94+
# precedence. Note that the following logic also falls to the default
95+
# parameters if no arguments were passed and no file was found.
96+
97+
if [ $options -eq 0 ] && [ -f $sketchdir/cfg ]; then
98+
opts=`cat $sketchdir/cfg`
99+
else
100+
partition="PartitionScheme=$partition_opt"
101+
ff="FlashFreq=$ff_opt"
102+
fm="FlashMode=$fm_opt"
103+
fs="FlashSize=$fs_opt"
104+
opts=$fm,$ff,$fs,$partition
105+
fi
106+
107+
fqbn+=$opts
108+
fi
109+
110+
echo $fqbn
111+
112+
if [ -z $fqbn ]; then
113+
echo "No FQBN passed or unvalid chip: $target"
114+
exit 1
115+
fi
16116

17117
ARDUINO_CACHE_DIR="$HOME/.arduino/cache.tmp"
18118
if [ -z "$ARDUINO_BUILD_DIR" ]; then
19-
build_dir="$(dirname $sketch)/build"
119+
build_dir="$sketchdir/build"
20120
else
21121
build_dir="$ARDUINO_BUILD_DIR"
22122
fi
23123

24-
echo $sketch
25-
26124
rm -rf "$build_dir"
27125
mkdir -p "$build_dir"
28126
mkdir -p "$ARDUINO_CACHE_DIR"
29127
$ide_path/arduino-builder -compile -logger=human -core-api-version=10810 \
30-
-fqbn=$fqbn \
128+
-fqbn=\"$fqbn\" \
31129
-warnings="all" \
32130
-tools "$ide_path/tools-builder" \
33131
-tools "$ide_path/tools" \
34132
-built-in-libraries "$ide_path/libraries" \
35133
-hardware "$ide_path/hardware" \
36-
-hardware "$usr_path/hardware" \
37-
-libraries "$usr_path/libraries" \
134+
-hardware "$user_path/hardware" \
135+
-libraries "$user_path/libraries" \
38136
-build-cache "$ARDUINO_CACHE_DIR" \
39137
-build-path "$build_dir" \
40-
$win_opts $xtra_opts "$sketch"
138+
$win_opts $xtra_opts "${sketchdir}/$(basename ${sketchdir}).ino"
41139
}
42140

43141
function count_sketches(){ # count_sketches <path> [target]
@@ -73,29 +171,63 @@ function count_sketches(){ # count_sketches <path> [target]
73171
return $sketchnum
74172
}
75173

76-
function build_sketches(){ # build_sketches <ide_path> <user_path> <fqbn> <target> <path> <chunk> <total-chunks> [extra-options]
77-
local ide_path=$1
78-
local usr_path=$2
79-
local fqbn=$3
80-
local target=$4
81-
local path=$5
82-
local chunk_idex=$6
83-
local chunks_num=$7
84-
local xtra_opts=$8
85-
86-
if [ "$#" -lt 7 ]; then
87-
echo "ERROR: Illegal number of parameters"
88-
echo "USAGE: ${0} chunk_build <ide_path> <user_path> <fqbn> <target> <path> [<chunk> <total-chunks>] [extra-options]"
89-
return 1
174+
function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <path> <chunk> <total-chunks> [extra-options]
175+
176+
local args=""
177+
while [ ! -z "$1" ]; do
178+
case $1 in
179+
-ai )
180+
shift
181+
ide_path=$1
182+
;;
183+
-au )
184+
shift
185+
user_path=$1
186+
;;
187+
-t )
188+
shift
189+
target=$1
190+
args+=" -t $target"
191+
;;
192+
-fqbn )
193+
shift
194+
fqbn=$1
195+
args+=" -fqbn $fqbn"
196+
;;
197+
-p )
198+
shift
199+
path=$1
200+
;;
201+
-i )
202+
shift
203+
chunk_index=$1
204+
;;
205+
-m )
206+
shift
207+
chunk_max=$1
208+
;;
209+
* )
210+
break
211+
;;
212+
esac
213+
shift
214+
done
215+
216+
local xtra_opts=$*
217+
218+
if [ -z $chunk_index ] || [ -z $chunk_max ]; then
219+
echo "ERROR: Invalid chunk paramters"
220+
echo "$USAGE"
221+
exit 1
90222
fi
91223

92-
if [ "$chunks_num" -le 0 ]; then
224+
if [ "$chunk_max" -le 0 ]; then
93225
echo "ERROR: Chunks count must be positive number"
94226
return 1
95227
fi
96-
if [ "$chunk_idex" -ge "$chunks_num" ] && [ "$chunks_num" -ge 2 ]; then
97-
echo "ERROR: Chunk index must be less than chunks count"
98-
return 1
228+
229+
if [ "$chunk_index" -gt "$chunk_max" ] && [ "$chunk_max" -ge 2 ]; then
230+
chunk_index=$chunk_max
99231
fi
100232

101233
set +e
@@ -105,51 +237,52 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <fqbn> <targe
105237
local sketches=$(cat sketches.txt)
106238
rm -rf sketches.txt
107239

108-
local chunk_size=$(( $sketchcount / $chunks_num ))
109-
local all_chunks=$(( $chunks_num * $chunk_size ))
240+
local chunk_size=$(( $sketchcount / $chunk_max ))
241+
local all_chunks=$(( $chunk_max * $chunk_size ))
110242
if [ "$all_chunks" -lt "$sketchcount" ]; then
111243
chunk_size=$(( $chunk_size + 1 ))
112244
fi
113245

114246
local start_index=0
115247
local end_index=0
116-
if [ "$chunk_idex" -ge "$chunks_num" ]; then
117-
start_index=$chunk_idex
248+
if [ "$chunk_index" -ge "$chunk_max" ]; then
249+
start_index=$chunk_index
118250
end_index=$sketchcount
119251
else
120-
start_index=$(( $chunk_idex * $chunk_size ))
252+
start_index=$(( $chunk_index * $chunk_size ))
121253
if [ "$sketchcount" -le "$start_index" ]; then
122254
echo "Skipping job"
123255
return 0
124256
fi
125257

126-
end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size ))
258+
end_index=$(( $(( $chunk_index + 1 )) * $chunk_size ))
127259
if [ "$end_index" -gt "$sketchcount" ]; then
128260
end_index=$sketchcount
129261
fi
130262
fi
131263

132264
local start_num=$(( $start_index + 1 ))
133265
echo "Found $sketchcount Sketches for target '$target'";
134-
echo "Chunk Index : $chunk_idex"
135-
echo "Chunk Count : $chunks_num"
266+
echo "Chunk Index : $chunk_index"
267+
echo "Chunk Count : $chunk_max"
136268
echo "Chunk Size : $chunk_size"
137269
echo "Start Sketch: $start_num"
138270
echo "End Sketch : $end_index"
139271

140272
local sketchnum=0
273+
args+=" -ai $ide_path -au $user_path"
141274
for sketch in $sketches; do
142275
local sketchdir=$(dirname $sketch)
143276
local sketchdirname=$(basename $sketchdir)
144-
local sketchname=$(basename $sketch)
145277
sketchnum=$(($sketchnum + 1))
146278
if [ "$sketchnum" -le "$start_index" ] \
147279
|| [ "$sketchnum" -gt "$end_index" ]; then
148280
continue
149281
fi
150282
echo ""
151283
echo "Building Sketch Index $(($sketchnum - 1)) - $sketchdirname"
152-
build_sketch "$ide_path" "$usr_path" "$fqbn" "$sketch" "$xtra_opts"
284+
args+=" -s $sketchdir $xtra_opts"
285+
build_sketch $args
153286
local result=$?
154287
if [ $result -ne 0 ]; then
155288
return $result
@@ -169,24 +302,21 @@ Available commands:
169302
cmd=$1
170303
shift
171304
if [ -z $cmd ]; then
172-
echo "ERROR: No command supplied"
173-
echo "$USAGE"
174-
exit 2
305+
echo "ERROR: No command supplied"
306+
echo "$USAGE"
307+
exit 2
175308
fi
176309

177310
case "$cmd" in
178-
"count")
179-
count_sketches $*
311+
"count") count_sketches $*
180312
;;
181-
"build")
182-
build_sketch $*
313+
"build") build_sketch $*
183314
;;
184-
"chunk_build")
185-
build_sketches $*
315+
"chunk_build") build_sketches $*
186316
;;
187-
*)
188-
echo "ERROR: Unrecognized command"
189-
echo "$USAGE"
190-
exit 2
317+
*)
318+
echo "ERROR: Unrecognized command"
319+
echo "$USAGE"
320+
exit 2
191321
esac
192322

0 commit comments

Comments
 (0)