From 82d962639beea04fc7c7f25cd9ab4965b3b38a77 Mon Sep 17 00:00:00 2001 From: Ralph Lange Date: Tue, 10 Dec 2019 14:30:07 +0100 Subject: [PATCH] Load setup files instead of sourcing them - needed for same setup files to work on Windows (where PowerShell is used instead of bash) - removes ugly bashism to allow overriding from .travis.yml - adds a proper (yet small) syntax Also adds tests for the new syntax and updates the README. --- README.md | 21 ++++++++++++--------- test00.set | 4 ++-- test01.set | 4 ++-- test02.set | 10 ++++++++++ test03.set | 4 ++++ travis-test.sh | 17 ++++++++++++++--- travis/build.sh | 2 +- travis/prepare.sh | 2 +- travis/utils.sh | 27 +++++++++++++++++++++++++-- 9 files changed, 71 insertions(+), 20 deletions(-) create mode 100644 test02.set create mode 100644 test03.set diff --git a/README.md b/README.md index d33d79d..f17e85b 100644 --- a/README.md +++ b/README.md @@ -71,15 +71,15 @@ example. E.g., a setup file `stable.set` specifying ``` - MODULES="sncseq asyn" + MODULES=sncseq asyn - BASE=${BASE:-R3.15.6} - ASYN=${ASYN:-R4-34} - SNCSEQ=${SNCSEQ:-R2-2-7} + BASE=R3.15.6 + ASYN=R4-34 + SNCSEQ=R2-2-7 ``` will compile against the EPICS Base release 3.15.6, the Sequencer release 2.2.7 and release 4.34 of asyn. - (The `${VAR:-default}` form allows overriding from `.travis.yml`.) + (Any settings can be overridden from `.travis.yml`.) 4. Create a configuration for the CI service by copying one of the examples provided in the service specific subdirectory @@ -106,14 +106,19 @@ latest released versions and one for the development branches. ## Setup File Syntax -Setup files are sourced by the bash scripts. They are found by searching +Setup files are loaded by the bash scripts. They are found by searching the locations in `SETUP_PATH` (space or colon separated list of directories, relative to your module's root directory). -Setup files can include other setup files by calling `source_set ` +Setup files can include other setup files by calling `include ` (omitting the `.set` extension of the setup file). The configured `SETUP_PATH` is searched for the include. +Any `VAR=value` setting of a variable is only executed if `VAR` is unset or +empty. That way any settings can be overridden by settings in `.travis.yml`. + +Empty lines or lines starting with `#` are ignored. + `MODULES=""` should list the dependencies (software modules) by using their well-known slugs, separated by spaces. EPICS Base (slug: `base`) will always be a dependency and will be added and @@ -132,8 +137,6 @@ be a *tag* name (in that case the module is checked out into Travis' cache system) or a *branch* name (in that case the module is always checked out and recompiled as part of the job). [default: `master`] -(Use the `${VAR:-default}` form to allow overriding from `.travis.yml`.) - `FOO_REPONAME=` Set the name of the remote repository as `.git`. [default is the slug in lower case: `foo`] diff --git a/test00.set b/test00.set index 3117275..116ce67 100644 --- a/test00.set +++ b/test00.set @@ -1,3 +1,3 @@ -MODULES="" +MODULES= -BASE=${BASE:-R3.15.6} +BASE=R3.15.6 diff --git a/test01.set b/test01.set index 8399d50..0260e61 100644 --- a/test01.set +++ b/test01.set @@ -1,4 +1,4 @@ MODULES="sncseq" -BASE=${BASE:-7.0} -SNCSEQ=${SNCSEQ:-R2-2-7} +BASE=7.0 +SNCSEQ=R2-2-7 diff --git a/test02.set b/test02.set new file mode 100644 index 0000000..9a250ea --- /dev/null +++ b/test02.set @@ -0,0 +1,10 @@ +# a comment, then an empty line + + # a comment that is indented +BASE=foo +# include an existing file +include test01 + +FOO=bar +FOO2=bar bar2 + FOO3=bar bar2 diff --git a/test03.set b/test03.set new file mode 100644 index 0000000..7c5bab7 --- /dev/null +++ b/test03.set @@ -0,0 +1,4 @@ +# Check for avoiding multiple includions + +include test01 +include test01 diff --git a/travis-test.sh b/travis-test.sh index e2bcd57..a1190ef 100755 --- a/travis-test.sh +++ b/travis-test.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Module ci-scripts unit tests @@ -62,9 +62,20 @@ fn_exists add_dependency || die "function add_dependency missing from SCRIPTDIR/ SETUP_DIRS= source_set test01 | grep -q "(SETUP_PATH) is empty" || die "empty search path not detected" source_set xxdoesnotexistxx | grep -q "does not exist" || die "missing setup file not detected" source_set test01 | grep -q "Loading setup file" || die "test01 setup file not found" -BASE=foo +unset SEEN_SETUPS +export BASE=foo source_set test01 -[ "$BASE" = "foo" ] || die "preset module (BASE) version does not override test01 setup file" +[ "$BASE" = "foo" ] || die "preset module BASE version does not override test01 setup file (expected foo got $BASE)" +unset SEEN_SETUPS +BASE= +source_set test02 +[ "$BASE" = "foo" ] || die "BASE set in test02 does not override included test01 setup file (expected foo got $BASE)" +[ "$FOO" = "bar" ] || die "Setting of single word does not work" +[ "$FOO2" = "bar bar2" ] || die "Setting of multiple words does not work" +[ "$FOO3" = "bar bar2" ] || die "Indented setting of multiple words does not work" +[ "$SNCSEQ" = "R2-2-7" ] || die "Setup test01 was not included" +unset SEEN_SETUPS +source_set test03 | grep -q "Ignoring already included setup file" || die "test01 setup file included twice" # test default settings file ###################################################################### diff --git a/travis/build.sh b/travis/build.sh index 98052d0..c6817f5 100755 --- a/travis/build.sh +++ b/travis/build.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e # Set VV in .travis.yml to make scripts verbose diff --git a/travis/prepare.sh b/travis/prepare.sh index e4770e2..54075e9 100755 --- a/travis/prepare.sh +++ b/travis/prepare.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e # Set VV in .travis.yml to make scripts verbose diff --git a/travis/utils.sh b/travis/utils.sh index 884cf74..4ff375b 100644 --- a/travis/utils.sh +++ b/travis/utils.sh @@ -33,8 +33,9 @@ fold_end() { # # Source a settings file (extension .set) found in the SETUP_DIRS path # May be called recursively (from within a settings file) +declare -a SEEN_SETUPS source_set() { - local set_file=$1 + local set_file=${1//[$'\r']} local set_dir local found=0 if [ -z "${SETUP_DIRS}" ] @@ -46,8 +47,30 @@ source_set() { do if [ -e $set_dir/$set_file.set ] then + if [[ " ${SEEN_SETUPS[@]} " =~ " $set_dir/$set_file.set " ]] + then + echo "Ignoring already included setup file $set_dir/$set_file.set" + return + fi + SEEN_SETUPS+=($set_dir/$set_file.set) echo "Loading setup file $set_dir/$set_file.set" - . $set_dir/$set_file.set + local line + while read -r line + do + [ -z "$line" ] && continue + echo $line | grep -q "^#" && continue + if echo $line | grep -q "^include\W" + then + source_set $(echo $line | awk '{ print $2 }') + continue + fi + if echo "$line" | grep -q "^\w\+=" + then + IFS== read var value <<< "${line//[$'\r']}" + value=$(sed "s/^\(\"\)\(.*\)\1\$/\2/g" <<< "$value") # remove surrounding quotes + eval [ "\${$var}" ] || eval "$var=\$value" + fi + done < $set_dir/$set_file.set found=1 break fi