Skip to content

Commit d48dc62

Browse files
committed
Update sketch_utils.sh
1 parent bb422a2 commit d48dc62

File tree

1 file changed

+48
-41
lines changed

1 file changed

+48
-41
lines changed

.github/scripts/sketch_utils.sh

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
3131
shift
3232
chunk_index=$1
3333
;;
34+
-l )
35+
shift
36+
log_compilation=$1
37+
;;
3438
* )
3539
break
3640
;;
@@ -144,13 +148,9 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
144148
build_dir="$HOME/.arduino/tests/$sketchname/build.tmp"
145149
fi
146150

147-
echo "Chunk index = $chunk_index"
148-
149-
log_file="$HOME/.arduino/cli_compile_output.txt"
151+
output_file="$HOME/.arduino/cli_compile_output.txt"
150152
sizes_file="$GITHUB_WORKSPACE/cli_compile_$chunk_index.json"
151153

152-
echo "Sizes file = $sizes_file"
153-
154154
mkdir -p "$ARDUINO_CACHE_DIR"
155155
for i in `seq 0 $(($len - 1))`
156156
do
@@ -176,38 +176,37 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
176176
--build-cache-path "$ARDUINO_CACHE_DIR" \
177177
--build-path "$build_dir" \
178178
$xtra_opts "${sketchdir}" \
179-
> $log_file
179+
> $output_file
180180

181181
exit_status=$?
182182
if [ $exit_status -ne 0 ]; then
183183
echo ""ERROR: Compilation failed with error code $exit_status""
184184
exit $exit_status
185185
fi
186186

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"
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
211210

212211
elif [ -f "$ide_path/arduino-builder" ]; then
213212
echo "Building $sketchname with arduino-builder and FQBN=$currfqbn"
@@ -384,13 +383,18 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
384383
echo "End Sketch : $end_index"
385384

386385
sizes_file="$GITHUB_WORKSPACE/cli_compile_$chunk_index.json"
387-
#echo board,target and start of sketches to sizes_file json
388-
echo "{ \"board\": \"$fqbn\",
389-
\"target\": \"$target\",
390-
\"sketches\": [" >> "$sizes_file"
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
391392

392393
local sketchnum=0
393394
args+=" -ai $ide_path -au $user_path -i $chunk_index"
395+
if [ $log_compilation ]; then
396+
args+=" -l $log_compilation"
397+
fi
394398
for sketch in $sketches; do
395399
local sketchdir=$(dirname $sketch)
396400
local sketchdirname=$(basename $sketchdir)
@@ -407,14 +411,17 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
407411
return $result
408412
fi
409413
done
410-
echo "Debug (sketch)- removing last comma from the last JSON object"
411-
if [ $i -eq $(($len - 1)) ]; then
412-
sed -i '$ s/.$//' "$sizes_file"
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"
413424
fi
414-
#echo end of sketches sizes_file json
415-
echo "]" >> "$sizes_file"
416-
#echo end of board sizes_file json
417-
echo "}," >> "$sizes_file"
418425

419426
return 0
420427
}

0 commit comments

Comments
 (0)