Skip to content

Commit c22c6b0

Browse files
committed
Revert to previous verbosity settings
The user may want to change the verbosity of .travis.yml output so I should not assume those settings. Instead store the values and revert to them before exiting the function. I removed the unnecessary calls to enable_verbosity and disable_verbosity in the private functions as verbosity control will already be handled in the public functions and extra calls will cause the loss of the saved verbosity values as well as changing the verbosity of the rest of the public function after the private function call.
1 parent e50820c commit c22c6b0

File tree

1 file changed

+21
-36
lines changed

1 file changed

+21
-36
lines changed

arduino-ci-script.sh

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -73,28 +73,27 @@ function set_script_verbosity()
7373
# Deprecated, use set_script_verbosity
7474
function set_verbose_script_output()
7575
{
76-
enable_verbosity
77-
78-
set_script_verbosity 1
79-
80-
disable_verbosity
76+
set_script_verbosity 1
8177
}
8278

8379

8480
# Deprecated, use set_script_verbosity
8581
function set_more_verbose_script_output()
8682
{
87-
enable_verbosity
88-
89-
set_script_verbosity 2
90-
91-
disable_verbosity
83+
set_script_verbosity 2
9284
}
9385

9486

9587
# Turn on verbosity based on the preferences set by set_script_verbosity
9688
function enable_verbosity()
9789
{
90+
# Store previous verbosity settings so they can be set back to their original values at the end of the function
91+
shopt -q -o verbose
92+
ARDUINO_CI_SCRIPT_PREVIOUS_VERBOSE_SETTING="$?"
93+
94+
shopt -q -o xtrace
95+
ARDUINO_CI_SCRIPT_PREVIOUS_XTRACE_SETTING="$?"
96+
9897
if [[ "$ARDUINO_CI_SCRIPT_VERBOSITY_LEVEL" -gt 0 ]]; then
9998
# "Print shell input lines as they are read."
10099
# https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
@@ -108,10 +107,20 @@ function enable_verbosity()
108107
}
109108

110109

110+
# Return verbosity settings to their previous values
111111
function disable_verbosity()
112112
{
113-
set +o verbose
114-
set +o xtrace
113+
if [[ "$ARDUINO_CI_SCRIPT_PREVIOUS_VERBOSE_SETTING" == "0" ]]; then
114+
set -o verbose
115+
else
116+
set +o verbose
117+
fi
118+
119+
if [[ "$ARDUINO_CI_SCRIPT_PREVIOUS_XTRACE_SETTING" == "0" ]]; then
120+
set -o xtrace
121+
else
122+
set +o xtrace
123+
fi
115124
}
116125

117126

@@ -141,12 +150,8 @@ function set_sketchbook_folder()
141150
# Deprecated
142151
function set_parameters()
143152
{
144-
enable_verbosity
145-
146153
set_application_folder "$1"
147154
set_sketchbook_folder "$2"
148-
149-
disable_verbosity
150155
}
151156

152157

@@ -243,8 +248,6 @@ function install_ide()
243248
# This function allows the same code to be shared by install_ide and build_sketch. The generated array is "returned" as a global named "$ARDUINO_CI_SCRIPT_GENERATED_IDE_VERSION_LIST_ARRAY"
244249
function generate_ide_version_list_array()
245250
{
246-
enable_verbosity
247-
248251
local baseIDEversionArray="$1"
249252
local startIDEversion="$2"
250253
local endIDEversion="$3"
@@ -319,17 +322,13 @@ function generate_ide_version_list_array()
319322
# Finish the list
320323
ARDUINO_CI_SCRIPT_GENERATED_IDE_VERSION_LIST_ARRAY="$ARDUINO_CI_SCRIPT_GENERATED_IDE_VERSION_LIST_ARRAY"')'
321324
fi
322-
323-
disable_verbosity
324325
}
325326

326327

327328
# Determine the oldest and newest (non-hourly unless hourly is the only version on the list) IDE version in the provided array
328329
# The determined versions are "returned" by setting the global variables "$ARDUINO_CI_SCRIPT_DETERMINED_OLDEST_IDE_VERSION" and "$ARDUINO_CI_SCRIPT_DETERMINED_NEWEST_IDE_VERSION"
329330
function determine_ide_version_extremes()
330331
{
331-
enable_verbosity
332-
333332
local baseIDEversionArray="$1"
334333

335334
# Reset the variables from any value they were assigned the last time the function was ran
@@ -347,21 +346,15 @@ function determine_ide_version_extremes()
347346
ARDUINO_CI_SCRIPT_DETERMINED_NEWEST_IDE_VERSION="$IDEversion"
348347
fi
349348
done
350-
351-
disable_verbosity
352349
}
353350

354351

355352
function install_ide_version()
356353
{
357-
enable_verbosity
358-
359354
local IDEversion="$1"
360355

361356
# Create a symbolic link so that the Arduino IDE can always be referenced from the same path no matter which version is being used.
362357
ln --symbolic --force $ARDUINO_CI_SCRIPT_VERBOSITY_OPTION "${ARDUINO_CI_SCRIPT_APPLICATION_FOLDER}/arduino-${IDEversion}" "${ARDUINO_CI_SCRIPT_APPLICATION_FOLDER}/${ARDUINO_CI_SCRIPT_IDE_INSTALLATION_FOLDER}"
363-
364-
disable_verbosity
365358
}
366359

367360

@@ -681,8 +674,6 @@ function build_this_sketch()
681674
# Fold this section of output in the Travis CI build log to make it easier to read
682675
echo -e "travis_fold:start:build_sketch"
683676

684-
enable_verbosity
685-
686677
local sketchName="$1"
687678
local boardID="$2"
688679
local IDEversion="$3"
@@ -762,8 +753,6 @@ function build_this_sketch()
762753
echo -e "travis_fold:end:build_sketch"
763754
# Add a useful message to the Travis CI build log
764755

765-
disable_verbosity
766-
767756
echo "arduino exit code: $arduinoExitCode"
768757

769758
return $buildThisSketchExitCode
@@ -908,14 +897,10 @@ curlDataHere
908897
# Leave a comment on the commit with a link to the report
909898
function comment_report_link()
910899
{
911-
enable_verbosity
912-
913900
local token="$1"
914901
local reportURL="$2"
915902

916903
eval curl $ARDUINO_CI_SCRIPT_VERBOSITY_OPTION --header "\"Authorization: token ${token}\"" --data \"{'\"'body'\"':'\"'Once completed, the job reports for Travis CI [build ${TRAVIS_BUILD_NUMBER}]\(https://travis-ci.org/${TRAVIS_REPO_SLUG}/builds/${TRAVIS_BUILD_ID}\) will be found at:\\n${reportURL}'\"'}\" "\"https://api.github.com/repos/${TRAVIS_REPO_SLUG}/commits/${TRAVIS_COMMIT}/comments\"" "$ARDUINO_CI_SCRIPT_VERBOSITY_REDIRECT"
917-
918-
disable_verbosity
919904
}
920905

921906

0 commit comments

Comments
 (0)