@@ -27,6 +27,14 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
27
27
shift
28
28
sketchdir=$1
29
29
;;
30
+ -i )
31
+ shift
32
+ chunk_index=$1
33
+ ;;
34
+ -l )
35
+ shift
36
+ log_compilation=$1
37
+ ;;
30
38
* )
31
39
break
32
40
;;
@@ -140,6 +148,9 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
140
148
build_dir=" $HOME /.arduino/tests/$sketchname /build.tmp"
141
149
fi
142
150
151
+ output_file=" $HOME /.arduino/cli_compile_output.txt"
152
+ sizes_file=" $GITHUB_WORKSPACE /cli_compile_$chunk_index .json"
153
+
143
154
mkdir -p " $ARDUINO_CACHE_DIR "
144
155
for i in ` seq 0 $(( $len - 1 )) `
145
156
do
@@ -164,13 +175,39 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
164
175
--build-property " compiler.warning_flags.all=-Wall -Werror=all -Wextra" \
165
176
--build-cache-path " $ARDUINO_CACHE_DIR " \
166
177
--build-path " $build_dir " \
167
- $xtra_opts " ${sketchdir} "
178
+ $xtra_opts " ${sketchdir} " \
179
+ > $output_file
168
180
169
181
exit_status=$?
170
182
if [ $exit_status -ne 0 ]; then
171
183
echo " " ERROR: Compilation failed with error code $exit_status " "
172
184
exit $exit_status
173
185
fi
186
+
187
+ if [ $log_compilation ]; then
188
+ # Extract the program storage space and dynamic memory usage in bytes and percentage in separate variables from the output, just the value without the string
189
+ flash_bytes=$( grep -oE ' Sketch uses ([0-9]+) bytes' $output_file | awk ' {print $3}' )
190
+ flash_percentage=$( grep -oE ' Sketch uses ([0-9]+) bytes \(([0-9]+)%\)' $output_file | awk ' {print $5}' | tr -d ' (%)' )
191
+ ram_bytes=$( grep -oE ' Global variables use ([0-9]+) bytes' $output_file | awk ' {print $4}' )
192
+ ram_percentage=$( grep -oE ' Global variables use ([0-9]+) bytes \(([0-9]+)%\)' $output_file | awk ' {print $6}' | tr -d ' (%)' )
193
+
194
+ # Extract the directory path excluding the filename
195
+ directory_path=$( dirname " $sketch " )
196
+ # Define the constant part
197
+ constant_part=" /home/runner/Arduino/hardware/espressif/esp32/libraries/"
198
+ # Extract the desired substring using sed
199
+ lib_sketch_name=$( echo " $directory_path " | sed " s|$constant_part ||" )
200
+ # append json file where key is fqbn, sketch name, sizes -> extracted values
201
+ echo " {\" name\" : \" $lib_sketch_name \" ,
202
+ \" sizes\" : [{
203
+ \" flash_bytes\" : $flash_bytes ,
204
+ \" flash_percentage\" : $flash_percentage ,
205
+ \" ram_bytes\" : $ram_bytes ,
206
+ \" ram_percentage\" : $ram_percentage
207
+ }]
208
+ }," >> " $sizes_file "
209
+ fi
210
+
174
211
elif [ -f " $ide_path /arduino-builder" ]; then
175
212
echo " Building $sketchname with arduino-builder and FQBN=$currfqbn "
176
213
echo " Build path = $build_dir "
@@ -204,6 +241,7 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
204
241
# $xtra_opts "${sketchdir}/${sketchname}.ino"
205
242
fi
206
243
done
244
+
207
245
unset fqbn
208
246
unset xtra_opts
209
247
unset options
@@ -277,6 +315,10 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
277
315
shift
278
316
chunk_max=$1
279
317
;;
318
+ -l )
319
+ shift
320
+ log_compilation=$1
321
+ ;;
280
322
* )
281
323
break
282
324
;;
@@ -340,8 +382,19 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
340
382
echo " Start Sketch: $start_num "
341
383
echo " End Sketch : $end_index "
342
384
385
+ sizes_file=" $GITHUB_WORKSPACE /cli_compile_$chunk_index .json"
386
+ if [ $log_compilation ]; then
387
+ # echo board,target and start of sketches to sizes_file json
388
+ echo " { \" board\" : \" $fqbn \" ,
389
+ \" target\" : \" $target \" ,
390
+ \" sketches\" : [" >> " $sizes_file "
391
+ fi
392
+
343
393
local sketchnum=0
344
- args+=" -ai $ide_path -au $user_path "
394
+ args+=" -ai $ide_path -au $user_path -i $chunk_index "
395
+ if [ $log_compilation ]; then
396
+ args+=" -l $log_compilation "
397
+ fi
345
398
for sketch in $sketches ; do
346
399
local sketchdir=$( dirname $sketch )
347
400
local sketchdirname=$( basename $sketchdir )
@@ -358,6 +411,18 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
358
411
return $result
359
412
fi
360
413
done
414
+
415
+ if [ $log_compilation ]; then
416
+ # remove last comma from json
417
+ if [ $i -eq $(( $len - 1 )) ]; then
418
+ sed -i ' $ s/.$//' " $sizes_file "
419
+ fi
420
+ # echo end of sketches sizes_file json
421
+ echo " ]" >> " $sizes_file "
422
+ # echo end of board sizes_file json
423
+ echo " }," >> " $sizes_file "
424
+ fi
425
+
361
426
return 0
362
427
}
363
428
@@ -389,4 +454,3 @@ case "$cmd" in
389
454
echo " $USAGE "
390
455
exit 2
391
456
esac
392
-
0 commit comments