substituteStream(): print warning if nothing done

This commit is contained in:
volth 2018-02-23 13:12:53 +00:00 committed by volth
parent f8701caafc
commit 5ff872aa24

@ -642,7 +642,8 @@ fi
substituteStream() { substituteStream() {
local var=$1 local var=$1
shift local description=$2
shift 2
while (( "$#" )); do while (( "$#" )); do
case "$1" in case "$1" in
@ -650,6 +651,14 @@ substituteStream() {
pattern="$2" pattern="$2"
replacement="$3" replacement="$3"
shift 3 shift 3
local savedvar
savedvar="${!var}"
eval "$var"'=${'"$var"'//"$pattern"/"$replacement"}'
if [ "$pattern" != "$replacement" ]; then
if [ "${!var}" == "$savedvar" ]; then
echo "substituteStream(): WARNING: pattern '$pattern' doesn't match anything in $description" >&2
fi
fi
;; ;;
--subst-var) --subst-var)
@ -662,11 +671,13 @@ substituteStream() {
fi fi
pattern="@$varName@" pattern="@$varName@"
replacement="${!varName}" replacement="${!varName}"
eval "$var"'=${'"$var"'//"$pattern"/"$replacement"}'
;; ;;
--subst-var-by) --subst-var-by)
pattern="@$2@" pattern="@$2@"
replacement="$3" replacement="$3"
eval "$var"'=${'"$var"'//"$pattern"/"$replacement"}'
shift 3 shift 3
;; ;;
@ -675,8 +686,6 @@ substituteStream() {
return 1 return 1
;; ;;
esac esac
eval "$var"'=${'"$var"'//"$pattern"/"$replacement"}'
done done
printf "%s" "${!var}" printf "%s" "${!var}"
@ -704,7 +713,7 @@ substitute() {
consumeEntire content < "$input" consumeEntire content < "$input"
if [ -e "$output" ]; then chmod +w "$output"; fi if [ -e "$output" ]; then chmod +w "$output"; fi
substituteStream content "$@" > "$output" substituteStream content "file '$input'" "$@" > "$output"
} }
substituteInPlace() { substituteInPlace() {
@ -726,7 +735,7 @@ substituteAllStream() {
local -a args=() local -a args=()
_allFlags _allFlags
substituteStream "$1" "${args[@]}" substituteStream "$1" "$2" "${args[@]}"
} }
# Substitute all environment variables that start with a lowercase character and # Substitute all environment variables that start with a lowercase character and
@ -1137,7 +1146,7 @@ fixupPhase() {
for hook in $setupHooks; do for hook in $setupHooks; do
local content local content
consumeEntire content < "$hook" consumeEntire content < "$hook"
substituteAllStream content >> "${!outputDev}/nix-support/setup-hook" substituteAllStream content "file '$hook'" >> "${!outputDev}/nix-support/setup-hook"
unset -v content unset -v content
done done
unset -v hook unset -v hook