@@ -27,6 +27,14 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
2727 shift
2828 sketchdir=$1
2929 ;;
30+ -i )
31+ shift
32+ chunk_index=$1
33+ ;;
34+ -l )
35+ shift
36+ log_compilation=$1
37+ ;;
3038 * )
3139 break
3240 ;;
@@ -127,6 +135,9 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
127135 build_dir=" $HOME /.arduino/tests/$sketchname /build.tmp"
128136 fi
129137
138+ output_file=" $HOME /.arduino/cli_compile_output.txt"
139+ sizes_file=" $GITHUB_WORKSPACE /cli_compile_$chunk_index .json"
140+
130141 mkdir -p " $ARDUINO_CACHE_DIR "
131142 for i in ` seq 0 $(( $len - 1 )) `
132143 do
@@ -151,7 +162,40 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
151162 --build-property " compiler.warning_flags.all=-Wall -Werror=all -Wextra" \
152163 --build-cache-path " $ARDUINO_CACHE_DIR " \
153164 --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+
155199 elif [ -f " $ide_path /arduino-builder" ]; then
156200 echo " Building $sketchname with arduino-builder and FQBN=$currfqbn "
157201 echo " Build path = $build_dir "
@@ -253,6 +297,10 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
253297 shift
254298 chunk_max=$1
255299 ;;
300+ -l )
301+ shift
302+ log_compilation=$1
303+ ;;
256304 * )
257305 break
258306 ;;
@@ -316,8 +364,19 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
316364 echo " Start Sketch: $start_num "
317365 echo " End Sketch : $end_index "
318366
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+
319375 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
321380 for sketch in $sketches ; do
322381 local sketchdir=$( dirname $sketch )
323382 local sketchdirname=$( basename $sketchdir )
@@ -334,6 +393,18 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
334393 return $result
335394 fi
336395 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+
337408 return 0
338409}
339410
0 commit comments