Skip to content
This repository was archived by the owner on Apr 1, 2022. It is now read-only.

Commit abcb285

Browse files
committed
Remove workaround in compile-examples action for platforms that don't fully report sizes
The issue of RAM use by global variables not being reported and flash being incorrectly reported by the Arduino SAMD Boards platform has been fixed in the 1.8.6 release. The issue remains for the Arduino SAM Boards platform, but it's not worth the added complexity just to improve size reporting for the Due.
1 parent 9d3ee6b commit abcb285

File tree

1 file changed

+8
-103
lines changed

1 file changed

+8
-103
lines changed

libraries/compile-examples/entrypoint.sh

Lines changed: 8 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,9 @@ readonly CORE="$(echo "$FQBN" | cut --delimiter=':' --fields=1,2)"
2525
# Additional Boards Manager URL
2626
readonly ADDITIONAL_URL="${FQBN_ARRAY[1]}"
2727

28-
# Get value from a key=value properties list file
29-
function get_property_value() {
30-
local -r filePath="$1"
31-
local -r key="$2"
32-
33-
local propertyValue
34-
propertyValue="$(grep --regex='^[[:blank:]]*'"$key"'[[:blank:]]*=' "$filePath" | cut --delimiter='=' --fields=2)"
35-
# Strip leading spaces
36-
propertyValue="${propertyValue#"${propertyValue%%[! ]*}"}"
37-
# Strip trailing spaces
38-
propertyValue="${propertyValue%"${propertyValue##*[! ]}"}"
39-
40-
echo "$propertyValue"
41-
}
42-
4328
function compile_example() {
4429
local -r examplePath="$1"
45-
arduino-cli compile --verbose --warnings all --fqbn "$FQBN" --output "${OUTPUT_FOLDER_PATH}/${OUTPUT_NAME}" "$examplePath" || {
30+
arduino-cli compile --verbose --warnings all --fqbn "$FQBN" "$examplePath" || {
4631
return $?
4732
}
4833
}
@@ -60,11 +45,11 @@ function check_sizes() {
6045
# Get the memory usage from the compilation output
6146
function compile_example_get_size_from_output() {
6247
local -r examplePath="$1"
63-
local compilationOutput
6448

6549
FLASH_SIZE=""
6650
RAM_SIZE=""
6751

52+
local compilationOutput
6853
compilationOutput=$(compile_example "$EXAMPLE" 2>&1)
6954
local -r compileExampleExitStatus=$?
7055
# Display the compilation output
@@ -91,50 +76,13 @@ function compile_example_get_size_from_output() {
9176
fi
9277
done <<<"$compilationOutput"
9378

94-
# Some hardware cores aren't configured to output RAM usage by global variables, but the flash usage should at least be in the output
79+
# Some platforms aren't configured to output RAM usage by global variables (e.g., Arduino SAM Boards), but the flash usage should at least be in the output
9580
if [[ "$FLASH_SIZE" == "" && "$RAM_SIZE" == "" ]]; then
9681
echo "::error::Something went wrong while while determining memory usage of the size-report-sketch"
9782
exit 1
9883
fi
9984
}
10085

101-
# Parse the compiler size command to determine memory usage
102-
function get_size_from_size_output() {
103-
local -r sizeOutput="$1"
104-
local -r sizeRegex="$2"
105-
106-
local -r sizeOutputLines="$(echo "$sizeOutput" | grep --perl-regexp --regex="$sizeRegex")"
107-
108-
local totalSize=0
109-
while read -r -a replyArray; do
110-
local replyValue="${replyArray[1]}"
111-
totalSize="$((totalSize + replyValue))"
112-
done <<<"$sizeOutputLines"
113-
114-
if [[ "$totalSize" == "" ]]; then
115-
echo "::error::Something went wrong while while determining memory usage of the size-report-sketch"
116-
exit 1
117-
fi
118-
119-
echo "$totalSize"
120-
}
121-
122-
# Use the compiler size command to determine memory usage
123-
function compile_example_get_size_from_size_cmd() {
124-
local -r examplePath="$1"
125-
126-
FLASH_SIZE=""
127-
RAM_SIZE=""
128-
129-
compile_example "$EXAMPLE" || {
130-
return $?
131-
}
132-
133-
local -r size_output="$("$COMPILER_SIZE_CMD_PATH" -A "${OUTPUT_FOLDER_PATH}/${OUTPUT_NAME}.elf")"
134-
FLASH_SIZE="$(get_size_from_size_output "$size_output" "$RECIPE_SIZE_REGEX")"
135-
RAM_SIZE="$(get_size_from_size_output "$size_output" "$RECIPE_SIZE_REGEX_DATA")"
136-
}
137-
13886
if [[ "$GITHUB_EVENT_NAME" != "pull_request" ]]; then
13987
ENABLE_SIZE_DELTAS_REPORT='false'
14088
fi
@@ -244,33 +192,6 @@ fi
244192
mkdir --parents "$HOME/Arduino/libraries"
245193
ln --symbolic "$PWD" "$HOME/Arduino/libraries/."
246194

247-
GET_SIZE_FROM_OUTPUT=true
248-
if [[ ("$ENABLE_SIZE_DELTAS_REPORT" == "true" || "$ENABLE_SIZE_TRENDS_REPORT" == "true") && ("$CORE" == "arduino:sam" || "$CORE" == "arduino:samd") ]]; then
249-
# arduino-cli doesn't report RAM usage for Arduino SAM Boards or Arduino SAMD Boards and doesn't include the data section in the flash usage report, so it's necessary to determine the sizes independently
250-
GET_SIZE_FROM_OUTPUT=false
251-
252-
DATA_DIRECTORY_PATH="$(arduino-cli config dump --format json | jq --raw-output '.directories.data')"
253-
DATA_DIRECTORY_PATH="${DATA_DIRECTORY_PATH//\"/}"
254-
255-
readonly VENDOR="$(echo "$FQBN" | cut --delimiter=':' --fields=1)"
256-
readonly ARCHITECTURE="$(echo "$FQBN" | cut --delimiter=':' --fields=2)"
257-
readonly PLATFORM_TXT_PATH="$(find "${DATA_DIRECTORY_PATH}/packages/${VENDOR}/hardware/${ARCHITECTURE}" -name platform.txt)"
258-
if [[ "$PLATFORM_TXT_PATH" == "" ]]; then
259-
echo "::error::Unable to find platform folder"
260-
exit 1
261-
fi
262-
263-
readonly COMPILER_SIZE_CMD="$(get_property_value "$PLATFORM_TXT_PATH" 'compiler\.size\.cmd')"
264-
readonly COMPILER_SIZE_CMD_PATH="$(find "$DATA_DIRECTORY_PATH/packages/$VENDOR/tools" -name "$COMPILER_SIZE_CMD")"
265-
if [[ "$COMPILER_SIZE_CMD_PATH" == "" ]]; then
266-
echo "::error::Unable to find compiler size tool"
267-
exit 1
268-
fi
269-
270-
readonly RECIPE_SIZE_REGEX='(?:\.text|\.data)\s+[0-9]'
271-
readonly RECIPE_SIZE_REGEX_DATA='(?:\.data|\.bss)\s+[0-9]'
272-
fi
273-
274195
if [[ "$ENABLE_SIZE_TRENDS_REPORT" == "true" ]]; then
275196
apt-get install --quiet=2 --assume-yes python3 >/dev/null || {
276197
echo "::error::Failed to install Python"
@@ -287,11 +208,6 @@ if [[ "$ENABLE_SIZE_TRENDS_REPORT" == "true" ]]; then
287208
}
288209
fi
289210

290-
# Create a folder for the compilation output files
291-
readonly OUTPUT_FOLDER_PATH="$(mktemp -d)"
292-
# The name of the output files. arduino-cli adds the file extensions.
293-
readonly OUTPUT_NAME='output'
294-
295211
# Find all the examples and loop build each
296212
readonly EXAMPLES="$(find "examples/" -name '*.ino' -print0 | xargs --null dirname | uniq)"
297213
if [[ "$EXAMPLES" == "" ]]; then
@@ -312,17 +228,10 @@ for EXAMPLE in $EXAMPLES; do
312228
# Do determine size
313229

314230
# Determine memory usage of the sketch at the tip of the pull request branch
315-
if [[ "$GET_SIZE_FROM_OUTPUT" == "true" ]]; then
316-
compile_example_get_size_from_output "$EXAMPLE" || {
317-
SCRIPT_EXIT_STATUS="$?"
318-
continue
319-
}
320-
else
321-
compile_example_get_size_from_size_cmd "$EXAMPLE" || {
322-
SCRIPT_EXIT_STATUS="$?"
323-
continue
324-
}
325-
fi
231+
compile_example_get_size_from_output "$EXAMPLE" || {
232+
SCRIPT_EXIT_STATUS="$?"
233+
continue
234+
}
326235
check_sizes
327236

328237
# Install Git
@@ -370,11 +279,7 @@ for EXAMPLE in $EXAMPLES; do
370279
}
371280

372281
# Compile the example sketch and get the sizes
373-
if [[ "$GET_SIZE_FROM_OUTPUT" == "true" ]]; then
374-
compile_example_get_size_from_output "$EXAMPLE"
375-
else
376-
compile_example_get_size_from_size_cmd "$EXAMPLE"
377-
fi
282+
compile_example_get_size_from_output "$EXAMPLE"
378283
check_sizes
379284

380285
if [[ "$CURRENT_FLASH_SIZE" == "$SIZE_NOT_APPLICABLE_INDICATOR" || "$FLASH_SIZE" == "$SIZE_NOT_APPLICABLE_INDICATOR" ]]; then

0 commit comments

Comments
 (0)