From bdcb2f31731d72b23694a81f65d560a031a95af7 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Fri, 13 Dec 2019 14:03:27 +0100 Subject: [PATCH 1/4] fix error message formats --- travis/utils.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/travis/utils.sh b/travis/utils.sh index a35c7db..e767f46 100644 --- a/travis/utils.sh +++ b/travis/utils.sh @@ -40,7 +40,7 @@ source_set() { local found=0 if [ -z "${SETUP_DIRS}" ] then - echo "${ANSI_RED}Search path for setup files (SETUP_PATH) is empty${ANSI_RESET}" + echo -e "${ANSI_RED}Search path for setup files (SETUP_PATH) is empty${ANSI_RESET}" [ "$UTILS_UNITTEST" ] || exit 1 fi for set_dir in ${SETUP_DIRS} @@ -77,7 +77,7 @@ source_set() { done if [ $found -eq 0 ] then - echo "${ANSI_RED}Setup file $set_file.set does not exist in SETUP_DIRS search path ($SETUP_DIRS)${ANSI_RESET}" + echo -e "${ANSI_RED}Setup file $set_file.set does not exist in SETUP_DIRS search path ($SETUP_DIRS)${ANSI_RESET}" [ "$UTILS_UNITTEST" ] || exit 1 fi } @@ -147,7 +147,7 @@ add_dependency() { # determine if $DEP points to a valid release or branch if ! git ls-remote --quiet --exit-code --refs $repourl "$TAG" > /dev/null 2>&1 then - echo "${ANSI_RED}$TAG is neither a tag nor a branch name for $DEP ($repourl)${ANSI_RESET}" + echo -e "${ANSI_RED}$TAG is neither a tag nor a branch name for $DEP ($repourl)${ANSI_RESET}" [ "$UTILS_UNITTEST" ] || exit 1 fi @@ -191,7 +191,7 @@ add_dependency() { echo "Running hook $hook in $CACHEDIR/$dirname-$TAG" ( cd $CACHEDIR/$dirname-$TAG; "$curdir/$hook" ) else - echo "${ANSI_RED}Hook script $hook is not executable or does not exist.${ANSI_RESET}" + echo -e "${ANSI_RED}Hook script $hook is not executable or does not exist.${ANSI_RESET}" exit 1 fi fi From c7aca7cd7393736e23f90135e747256f00922b09 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Fri, 13 Dec 2019 14:39:53 +0100 Subject: [PATCH 2/4] implement die function --- travis/utils.sh | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/travis/utils.sh b/travis/utils.sh index e767f46..ce1bbd9 100644 --- a/travis/utils.sh +++ b/travis/utils.sh @@ -29,6 +29,11 @@ fold_end() { echo -en "travis_fold:end:$1\\r" } +die() { + echo -e "${ANSI_RED}$1${ANSI_RESET}" + [ "$UTILS_UNITTEST" ] || exit 1 +} + # source_set(settings) # # Source a settings file (extension .set) found in the SETUP_DIRS path @@ -38,11 +43,7 @@ source_set() { local set_file=${1//[$'\r']} local set_dir local found=0 - if [ -z "${SETUP_DIRS}" ] - then - echo -e "${ANSI_RED}Search path for setup files (SETUP_PATH) is empty${ANSI_RESET}" - [ "$UTILS_UNITTEST" ] || exit 1 - fi + [ "${SETUP_DIRS}" ] || die "Search path for setup files (SETUP_PATH) is empty" for set_dir in ${SETUP_DIRS} do if [ -e $set_dir/$set_file.set ] @@ -75,11 +76,7 @@ source_set() { break fi done - if [ $found -eq 0 ] - then - echo -e "${ANSI_RED}Setup file $set_file.set does not exist in SETUP_DIRS search path ($SETUP_DIRS)${ANSI_RESET}" - [ "$UTILS_UNITTEST" ] || exit 1 - fi + [ $found -ne 0 ] || die "Setup file $set_file.set does not exist in SETUP_DIRS search path ($SETUP_DIRS)" } # update_release_local(varname, place) @@ -145,11 +142,8 @@ add_dependency() { [ "$recursive" != "0" -a "$recursive" != "no" ] && recurse="--recursive" # determine if $DEP points to a valid release or branch - if ! git ls-remote --quiet --exit-code --refs $repourl "$TAG" > /dev/null 2>&1 - then - echo -e "${ANSI_RED}$TAG is neither a tag nor a branch name for $DEP ($repourl)${ANSI_RESET}" - [ "$UTILS_UNITTEST" ] || exit 1 - fi + git ls-remote --quiet --exit-code --refs $repourl "$TAG" > /dev/null 2>&1 || + die "$TAG is neither a tag nor a branch name for $DEP ($repourl)" if [ -e $CACHEDIR/$dirname-$TAG ] then @@ -191,8 +185,7 @@ add_dependency() { echo "Running hook $hook in $CACHEDIR/$dirname-$TAG" ( cd $CACHEDIR/$dirname-$TAG; "$curdir/$hook" ) else - echo -e "${ANSI_RED}Hook script $hook is not executable or does not exist.${ANSI_RESET}" - exit 1 + die "Hook script $hook is not executable or does not exist." fi fi HEAD=$(cd "$CACHEDIR/$dirname-$TAG" && git log -n1 --pretty=format:%H) From 487d8eb287ae0186f7067f30201ba167746e44bf Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Fri, 13 Dec 2019 14:58:57 +0100 Subject: [PATCH 3/4] refer to user variable, not internal variable in error message --- travis/prepare.sh | 2 -- travis/utils.sh | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/travis/prepare.sh b/travis/prepare.sh index e0d81b9..b804c1f 100755 --- a/travis/prepare.sh +++ b/travis/prepare.sh @@ -7,8 +7,6 @@ set -e # Perl version of "readlink -f" (which MacOS does not provide) readlinkf() { perl -MCwd -e 'print Cwd::abs_path shift' "$1"; } -SETUP_DIRS=$(echo $SETUP_PATH | tr ":" "\n") - SCRIPTDIR=$(dirname $(readlinkf $0)) CURDIR="$PWD" CACHEDIR="$HOME/.cache" diff --git a/travis/utils.sh b/travis/utils.sh index ce1bbd9..cb00f8c 100644 --- a/travis/utils.sh +++ b/travis/utils.sh @@ -36,15 +36,15 @@ die() { # source_set(settings) # -# Source a settings file (extension .set) found in the SETUP_DIRS path +# Source a settings file (extension .set) found in SETUP_PATH # May be called recursively (from within a settings file) declare -a SEEN_SETUPS source_set() { local set_file=${1//[$'\r']} local set_dir local found=0 - [ "${SETUP_DIRS}" ] || die "Search path for setup files (SETUP_PATH) is empty" - for set_dir in ${SETUP_DIRS} + [ "${SETUP_PATH}" ] || die "Search path for setup files (SETUP_PATH) is empty" + for set_dir in $(echo $SETUP_PATH | tr ":" "\n") do if [ -e $set_dir/$set_file.set ] then @@ -76,7 +76,7 @@ source_set() { break fi done - [ $found -ne 0 ] || die "Setup file $set_file.set does not exist in SETUP_DIRS search path ($SETUP_DIRS)" + [ $found -ne 0 ] || die "Setup file $set_file.set does not exist in SETUP_PATH search path ($SETUP_PATH)" } # update_release_local(varname, place) From d4ab170b3caba44853685b75ded7ddd99f574463 Mon Sep 17 00:00:00 2001 From: Dirk Zimoch Date: Mon, 16 Dec 2019 08:44:43 +0100 Subject: [PATCH 4/4] avoid 'tr' calls to improve performance a bit --- travis-test.sh | 4 ++-- travis/prepare.sh | 17 +++++++++++++++-- travis/utils.sh | 6 +++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/travis-test.sh b/travis-test.sh index a1190ef..a433c69 100755 --- a/travis-test.sh +++ b/travis-test.sh @@ -27,7 +27,7 @@ fn_exists() { repo_exists() { DEP=$1 - dep_lc=$(echo $DEP | tr 'A-Z' 'a-z') + dep_lc=${DEP,,} eval dirname=\${${DEP}_DIRNAME:=${dep_lc}} eval reponame=\${${DEP}_REPONAME:=${dep_lc}} eval repourl=\${${DEP}_REPOURL:="https://github.com/\${${DEP}_REPOOWNER:=${REPOOWNER:-epics-modules}}/${reponame}.git"} @@ -35,7 +35,7 @@ repo_exists() { git ls-remote --quiet --heads --exit-code $repourl > /dev/null 2>&1 } -SETUP_DIRS=$(echo $SETUP_PATH | tr ":" "\n") +SETUP_DIRS=${SETUP_PATH//:/ } SCRIPTDIR=$(dirname $(readlinkf $0))/travis CURDIR="$PWD" diff --git a/travis/prepare.sh b/travis/prepare.sh index b804c1f..e2464e0 100755 --- a/travis/prepare.sh +++ b/travis/prepare.sh @@ -1,6 +1,17 @@ #!/bin/bash set -e +if [ "$TRAVIS_OS_NAME" == "osx" -a "$BASH_VERSINFO" -lt 4 ] +then + brew install bash + if [ $(/usr/local/bin/bash -c 'echo $BASH_VERSINFO') -lt 4 ] + then + echo "Failed to install a recent bash" >&2 + exit 1 + fi + exec /usr/local/bin/bash $0 "$@" +fi + # Set VV in .travis.yml to make scripts verbose [ "$VV" ] && set -x @@ -14,6 +25,8 @@ CACHEDIR="$HOME/.cache" # source functions . $SCRIPTDIR/utils.sh +echo -e "${ANSI_YELLOW}Using bash version $BASH_VERSION${ANSI_RESET}" + # Load settings # ------------- @@ -34,7 +47,7 @@ fold_start check.out.dependencies "Checking/cloning dependencies" for mod in BASE $MODULES do - mod_uc=$(echo $mod | tr 'a-z' 'A-Z') + mod_uc=${mod^^} eval add_dependency $mod_uc \${${mod_uc}:=master} done [ -e ./configure ] && cp ${CACHEDIR}/RELEASE.local ./configure/RELEASE.local @@ -190,7 +203,7 @@ echo "Module Tag Binaries Commit" echo "-----------------------------------------------------------------------------------" for mod in base $MODULES do - mod_uc=$(echo $mod | tr 'a-z' 'A-Z') + mod_uc=${mod^^} eval tag=\${${mod_uc}} eval dir=${CACHEDIR}/\${${mod_uc}_DIRNAME}-$tag echo "$modules_to_compile" | grep -q "$dir" && stat="rebuilt" || stat="from cache" diff --git a/travis/utils.sh b/travis/utils.sh index cb00f8c..10efb76 100644 --- a/travis/utils.sh +++ b/travis/utils.sh @@ -44,7 +44,7 @@ source_set() { local set_dir local found=0 [ "${SETUP_PATH}" ] || die "Search path for setup files (SETUP_PATH) is empty" - for set_dir in $(echo $SETUP_PATH | tr ":" "\n") + for set_dir in ${SETUP_PATH//:/ } do if [ -e $set_dir/$set_file.set ] then @@ -132,13 +132,13 @@ add_dependency() { curdir="$PWD" DEP=$1 TAG=$2 - dep_lc=$(echo $DEP | tr 'A-Z' 'a-z') + dep_lc=${DEP,,} eval dirname=\${${DEP}_DIRNAME:=${dep_lc}} eval reponame=\${${DEP}_REPONAME:=${dep_lc}} eval repourl=\${${DEP}_REPOURL:="https://github.com/\${${DEP}_REPOOWNER:=${REPOOWNER:-epics-modules}}/${reponame}.git"} eval varname=\${${DEP}_VARNAME:=${DEP}} eval recursive=\${${DEP}_RECURSIVE:=1} - recursive=$(echo $recursive | tr 'A-Z' 'a-z') + recursive=${recursive,,} [ "$recursive" != "0" -a "$recursive" != "no" ] && recurse="--recursive" # determine if $DEP points to a valid release or branch