Skip to content

Commit 30f5b89

Browse files
committed
Improved handling of sketchbook location preference
- If a sketchbook location has not been defined then don't set the preference (use the default location) - Set the sketchbook location preference in set_sketchbook_folder if the IDE was already installed. This means the order that install_ide and set_sketchbook_folder are called in doesn't matter. - Functionalize the preference setting code to avoid duplicate code.
1 parent 5947435 commit 30f5b89

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

arduino-ci-script.sh

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ function set_sketchbook_folder()
146146
# Create the sketchbook folder if it doesn't already exist
147147
create_folder "$ARDUINO_CI_SCRIPT_SKETCHBOOK_FOLDER"
148148

149+
# Set sketchbook location preference if the IDE is already installed
150+
if [[ "$INSTALLED_IDE_VERSION_LIST_ARRAY" != "" ]]; then
151+
set_ide_preference "sketchbook.path=$ARDUINO_CI_SCRIPT_SKETCHBOOK_FOLDER"
152+
fi
153+
149154
disable_verbosity
150155
}
151156

@@ -222,26 +227,11 @@ function install_ide()
222227
mv $ARDUINO_CI_SCRIPT_VERBOSITY_OPTION "arduino-${downloadVersion}" "$ARDUINO_CI_SCRIPT_APPLICATION_FOLDER/arduino-${IDEversion}"
223228
done
224229

225-
# Temporarily install the latest IDE version
226-
install_ide_version "$NEWEST_INSTALLED_IDE_VERSION"
227-
228-
# Set the preferences
229-
# --pref option is only supported by Arduino IDE 1.5.6 and newer
230-
local -r unsupportedPrefOptionVersionsRegex="1.5.[0-5]"
231-
if ! [[ "$NEWEST_INSTALLED_IDE_VERSION" =~ $unsupportedPrefOptionVersionsRegex ]]; then
232-
# Create the sketchbook folder if it doesn't already exist. The location can't be set in preferences if the folder doesn't exist.
233-
create_folder "$ARDUINO_CI_SCRIPT_SKETCHBOOK_FOLDER"
230+
set_ide_preference "compiler.warning_level=all"
234231

235-
# --save-prefs was added in Arduino IDE 1.5.8
236-
local -r unsupportedSavePrefsOptionVersionsRegex="1.5.[6-7]"
237-
if ! [[ "$NEWEST_INSTALLED_IDE_VERSION" =~ $unsupportedSavePrefsOptionVersionsRegex ]]; then
238-
# shellcheck disable=SC2086
239-
eval ${ARDUINO_CI_SCRIPT_APPLICATION_FOLDER}/${ARDUINO_CI_SCRIPT_IDE_INSTALLATION_FOLDER}/arduino --pref compiler.warning_level=all --pref sketchbook.path="$ARDUINO_CI_SCRIPT_SKETCHBOOK_FOLDER" --save-prefs "$ARDUINO_CI_SCRIPT_VERBOSITY_REDIRECT"
240-
else
241-
# Arduino IDE 1.5.6 - 1.5.7 load the GUI if you only set preferences without doing a verify. So I am doing an unnecessary verification just to set the preferences in those versions. Definitely a hack but I prefer to keep the preferences setting code all here instead of cluttering build_sketch and this will pretty much never be used.
242-
# shellcheck disable=SC2086
243-
eval ${ARDUINO_CI_SCRIPT_APPLICATION_FOLDER}/${ARDUINO_CI_SCRIPT_IDE_INSTALLATION_FOLDER}/arduino --pref compiler.warning_level=all --pref sketchbook.path="$ARDUINO_CI_SCRIPT_SKETCHBOOK_FOLDER" --verify "${ARDUINO_CI_SCRIPT_APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "$ARDUINO_CI_SCRIPT_VERBOSITY_REDIRECT"
244-
fi
232+
# If a sketchbook location has been defined then set the location in the Arduino IDE preferences
233+
if [[ -d "$ARDUINO_CI_SCRIPT_SKETCHBOOK_FOLDER" ]]; then
234+
set_ide_preference "sketchbook.path=$ARDUINO_CI_SCRIPT_SKETCHBOOK_FOLDER"
245235
fi
246236

247237
# Return errexit to the default state
@@ -356,6 +346,29 @@ function determine_ide_version_extremes()
356346
}
357347

358348

349+
function set_ide_preference()
350+
{
351+
local -r preferenceString="$1"
352+
353+
# --pref option is only supported by Arduino IDE 1.5.6 and newer
354+
local -r unsupportedPrefOptionVersionsRegex="1.5.[0-5]"
355+
if ! [[ "$NEWEST_INSTALLED_IDE_VERSION" =~ $unsupportedPrefOptionVersionsRegex ]]; then
356+
install_ide_version "$NEWEST_INSTALLED_IDE_VERSION"
357+
358+
# --save-prefs was added in Arduino IDE 1.5.8
359+
local -r unsupportedSavePrefsOptionVersionsRegex="1.5.[6-7]"
360+
if ! [[ "$NEWEST_INSTALLED_IDE_VERSION" =~ $unsupportedSavePrefsOptionVersionsRegex ]]; then
361+
# shellcheck disable=SC2086
362+
eval ${ARDUINO_CI_SCRIPT_APPLICATION_FOLDER}/${ARDUINO_CI_SCRIPT_IDE_INSTALLATION_FOLDER}/arduino --pref "$preferenceString" --save-prefs "$ARDUINO_CI_SCRIPT_VERBOSITY_REDIRECT"
363+
else
364+
# Arduino IDE 1.5.6 - 1.5.7 load the GUI if you only set preferences without doing a verify. So I am doing an unnecessary verification just to set the preferences in those versions. Definitely a hack but I prefer to keep the preferences setting code all here instead of cluttering build_sketch and this will pretty much never be used.
365+
# shellcheck disable=SC2086
366+
eval ${ARDUINO_CI_SCRIPT_APPLICATION_FOLDER}/${ARDUINO_CI_SCRIPT_IDE_INSTALLATION_FOLDER}/arduino --pref "$preferenceString" --verify "${ARDUINO_CI_SCRIPT_APPLICATION_FOLDER}/arduino/examples/01.Basics/BareMinimum/BareMinimum.ino" "$ARDUINO_CI_SCRIPT_VERBOSITY_REDIRECT"
367+
fi
368+
fi
369+
}
370+
371+
359372
function install_ide_version()
360373
{
361374
local -r IDEversion="$1"

0 commit comments

Comments
 (0)