Skip to content

Commit b1c3df2

Browse files
committed
Update sketch_utils.sh
1 parent f050ec8 commit b1c3df2

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

.github/scripts/sketch_utils.sh

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ 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+
;;
3034
* )
3135
break
3236
;;
@@ -140,6 +144,13 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
140144
build_dir="$HOME/.arduino/tests/$sketchname/build.tmp"
141145
fi
142146

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+
143154
mkdir -p "$ARDUINO_CACHE_DIR"
144155
for i in `seq 0 $(($len - 1))`
145156
do
@@ -164,13 +175,40 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
164175
--build-property "compiler.warning_flags.all=-Wall -Werror=all -Wextra" \
165176
--build-cache-path "$ARDUINO_CACHE_DIR" \
166177
--build-path "$build_dir" \
167-
$xtra_opts "${sketchdir}"
178+
$xtra_opts "${sketchdir}" \
179+
> $log_file
168180

169181
exit_status=$?
170182
if [ $exit_status -ne 0 ]; then
171183
echo ""ERROR: Compilation failed with error code $exit_status""
172184
exit $exit_status
173185
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+
174212
elif [ -f "$ide_path/arduino-builder" ]; then
175213
echo "Building $sketchname with arduino-builder and FQBN=$currfqbn"
176214
echo "Build path = $build_dir"
@@ -204,6 +242,7 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
204242
# $xtra_opts "${sketchdir}/${sketchname}.ino"
205243
fi
206244
done
245+
207246
unset fqbn
208247
unset xtra_opts
209248
unset options
@@ -340,8 +379,14 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
340379
echo "Start Sketch: $start_num"
341380
echo "End Sketch : $end_index"
342381

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+
343388
local sketchnum=0
344-
args+=" -ai $ide_path -au $user_path"
389+
args+=" -ai $ide_path -au $user_path -i $chunk_index"
345390
for sketch in $sketches; do
346391
local sketchdir=$(dirname $sketch)
347392
local sketchdirname=$(basename $sketchdir)
@@ -358,6 +403,15 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
358403
return $result
359404
fi
360405
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+
361415
return 0
362416
}
363417

0 commit comments

Comments
 (0)