@@ -27,6 +27,10 @@ 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
+ ;;
30
34
* )
31
35
break
32
36
;;
@@ -140,6 +144,13 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
140
144
build_dir=" $HOME /.arduino/tests/$sketchname /build.tmp"
141
145
fi
142
146
147
+ echo " Chunk index = $chunk_index "
148
+
149
+ log_file=" $HOME /.arduino/cli_compile_output.txt"
150
+ sizes_file=" $GITHUB_WORKSPACE /cli_compile_$chunk_index .json"
151
+
152
+ echo " Sizes file = $sizes_file "
153
+
143
154
mkdir -p " $ARDUINO_CACHE_DIR "
144
155
for i in ` seq 0 $(( $len - 1 )) `
145
156
do
@@ -164,13 +175,40 @@ 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
+ > $log_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
+ # 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
188
+ flash_bytes=$( grep -oE ' Sketch uses ([0-9]+) bytes' $log_file | awk ' {print $3}' )
189
+ flash_percentage=$( grep -oE ' Sketch uses ([0-9]+) bytes \(([0-9]+)%\)' $log_file | awk ' {print $5}' | tr -d ' (%)' )
190
+ ram_bytes=$( grep -oE ' Global variables use ([0-9]+) bytes' $log_file | awk ' {print $4}' )
191
+ ram_percentage=$( grep -oE ' Global variables use ([0-9]+) bytes \(([0-9]+)%\)' $log_file | awk ' {print $6}' | tr -d ' (%)' )
192
+
193
+ # Extract the directory path excluding the filename
194
+ directory_path=$( dirname " $sketch " )
195
+ echo " Debug (sketch)- directory path = $directory_path "
196
+ # Define the constant part
197
+ constant_part=" /home/runner/Arduino/hardware/espressif/esp32/libraries/"
198
+ echo " Debug (sketch)- constant part = $constant_part "
199
+ # Extract the desired substring using sed
200
+ lib_sketch_name=$( echo " $directory_path " | sed " s|$constant_part ||" )
201
+ echo " Debug (sketch)- extracted path = $lib_sketch_name "
202
+ # append json file where key is fqbn, sketch name, sizes -> extracted values
203
+ echo " {\" name\" : \" $lib_sketch_name \" ,
204
+ \" sizes\" : [{
205
+ \" flash_bytes\" : $flash_bytes ,
206
+ \" flash_percentage\" : $flash_percentage ,
207
+ \" ram_bytes\" : $ram_bytes ,
208
+ \" ram_percentage\" : $ram_percentage
209
+ }]
210
+ }," >> " $sizes_file "
211
+
174
212
elif [ -f " $ide_path /arduino-builder" ]; then
175
213
echo " Building $sketchname with arduino-builder and FQBN=$currfqbn "
176
214
echo " Build path = $build_dir "
@@ -204,6 +242,7 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
204
242
# $xtra_opts "${sketchdir}/${sketchname}.ino"
205
243
fi
206
244
done
245
+
207
246
unset fqbn
208
247
unset xtra_opts
209
248
unset options
@@ -340,8 +379,14 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
340
379
echo " Start Sketch: $start_num "
341
380
echo " End Sketch : $end_index "
342
381
382
+ sizes_file=" $GITHUB_WORKSPACE /cli_compile_$chunk_index .json"
383
+ # echo board,target and start of sketches to sizes_file json
384
+ echo " { \" board\" : \" $fqbn \" ,
385
+ \" target\" : \" $target \" ,
386
+ \" sketches\" : [" >> " $sizes_file "
387
+
343
388
local sketchnum=0
344
- args+=" -ai $ide_path -au $user_path "
389
+ args+=" -ai $ide_path -au $user_path -i $chunk_index "
345
390
for sketch in $sketches ; do
346
391
local sketchdir=$( dirname $sketch )
347
392
local sketchdirname=$( basename $sketchdir )
@@ -358,6 +403,15 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
358
403
return $result
359
404
fi
360
405
done
406
+ echo " Debug (sketch)- removing last comma from the last JSON object"
407
+ if [ $i -eq $(( $len - 1 )) ]; then
408
+ sed -i ' $ s/.$//' " $sizes_file "
409
+ fi
410
+ # echo end of sketches sizes_file json
411
+ echo " ]" >> " $sizes_file "
412
+ # echo end of board sizes_file json
413
+ echo " }," >> " $sizes_file "
414
+
361
415
return 0
362
416
}
363
417
0 commit comments