@@ -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
;;
@@ -127,6 +135,9 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
127
135
build_dir=" $HOME /.arduino/tests/$sketchname /build.tmp"
128
136
fi
129
137
138
+ output_file=" $HOME /.arduino/cli_compile_output.txt"
139
+ sizes_file=" $GITHUB_WORKSPACE /cli_compile_$chunk_index .json"
140
+
130
141
mkdir -p " $ARDUINO_CACHE_DIR "
131
142
for i in ` seq 0 $(( $len - 1 )) `
132
143
do
@@ -151,7 +162,40 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
151
162
--build-property " compiler.warning_flags.all=-Wall -Werror=all -Wextra" \
152
163
--build-cache-path " $ARDUINO_CACHE_DIR " \
153
164
--build-path " $build_dir " \
154
- $xtra_opts " ${sketchdir} "
165
+ $xtra_opts " ${sketchdir} " \
166
+ > $output_file
167
+
168
+ exit_status=$?
169
+ if [ $exit_status -ne 0 ]; then
170
+ echo " " ERROR: Compilation failed with error code $exit_status " "
171
+ exit $exit_status
172
+ fi
173
+
174
+ if [ $log_compilation ]; then
175
+ # 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
176
+ flash_bytes=$( grep -oE ' Sketch uses ([0-9]+) bytes' $output_file | awk ' {print $3}' )
177
+ flash_percentage=$( grep -oE ' Sketch uses ([0-9]+) bytes \(([0-9]+)%\)' $output_file | awk ' {print $5}' | tr -d ' (%)' )
178
+ ram_bytes=$( grep -oE ' Global variables use ([0-9]+) bytes' $output_file | awk ' {print $4}' )
179
+ ram_percentage=$( grep -oE ' Global variables use ([0-9]+) bytes \(([0-9]+)%\)' $output_file | awk ' {print $6}' | tr -d ' (%)' )
180
+
181
+ # Extract the directory path excluding the filename
182
+ directory_path=$( dirname " $sketch " )
183
+ # Define the constant part
184
+ constant_part=" /home/runner/Arduino/hardware/espressif/esp32/libraries/"
185
+ # Extract the desired substring using sed
186
+ lib_sketch_name=$( echo " $directory_path " | sed " s|$constant_part ||" )
187
+ # append json file where key is fqbn, sketch name, sizes -> extracted values
188
+ echo " {\" name\" : \" $lib_sketch_name \" ,
189
+ \" sizes\" : [{
190
+ \" flash_bytes\" : $flash_bytes ,
191
+ \" flash_percentage\" : $flash_percentage ,
192
+ \" ram_bytes\" : $ram_bytes ,
193
+ \" ram_percentage\" : $ram_percentage
194
+ }]
195
+ }," >> " $sizes_file "
196
+ fi
197
+
198
+
155
199
elif [ -f " $ide_path /arduino-builder" ]; then
156
200
echo " Building $sketchname with arduino-builder and FQBN=$currfqbn "
157
201
echo " Build path = $build_dir "
@@ -253,6 +297,10 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
253
297
shift
254
298
chunk_max=$1
255
299
;;
300
+ -l )
301
+ shift
302
+ log_compilation=$1
303
+ ;;
256
304
* )
257
305
break
258
306
;;
@@ -316,8 +364,19 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
316
364
echo " Start Sketch: $start_num "
317
365
echo " End Sketch : $end_index "
318
366
367
+ sizes_file=" $GITHUB_WORKSPACE /cli_compile_$chunk_index .json"
368
+ if [ $log_compilation ]; then
369
+ # echo board,target and start of sketches to sizes_file json
370
+ echo " { \" board\" : \" $fqbn \" ,
371
+ \" target\" : \" $target \" ,
372
+ \" sketches\" : [" >> " $sizes_file "
373
+ fi
374
+
319
375
local sketchnum=0
320
- args+=" -ai $ide_path -au $user_path "
376
+ args+=" -ai $ide_path -au $user_path -i $chunk_index "
377
+ if [ $log_compilation ]; then
378
+ args+=" -l $log_compilation "
379
+ fi
321
380
for sketch in $sketches ; do
322
381
local sketchdir=$( dirname $sketch )
323
382
local sketchdirname=$( basename $sketchdir )
@@ -334,6 +393,18 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
334
393
return $result
335
394
fi
336
395
done
396
+
397
+ if [ $log_compilation ]; then
398
+ # remove last comma from json
399
+ if [ $i -eq $(( $len - 1 )) ]; then
400
+ sed -i ' $ s/.$//' " $sizes_file "
401
+ fi
402
+ # echo end of sketches sizes_file json
403
+ echo " ]" >> " $sizes_file "
404
+ # echo end of board sizes_file json
405
+ echo " }," >> " $sizes_file "
406
+ fi
407
+
337
408
return 0
338
409
}
339
410
0 commit comments