diff options
author | Kait Lam <k@rina.fyi> | 2024-02-11 10:48:37 +1000 |
---|---|---|
committer | rina <k@rina.fyi> | 2024-02-11 10:48:37 +1000 |
commit | 355ab764b4b32e476eaf056009998408375f9961 (patch) | |
tree | df2db2315e532bccc908720fdaa8d186976ae9a5 /pkgs/stdenv/generic | |
parent | 687cda7b77938fba1a88d52726cc2403ac405980 (diff) |
stdenv: refactor of --replace-{quiet,warn,fail} logic
This is a small simplification of the control flow surrounding these cases. It should make it more obvious when each case happens, and also explicitly defines the current behaviour of --replace.
Diffstat (limited to 'pkgs/stdenv/generic')
-rw-r--r-- | pkgs/stdenv/generic/setup.sh | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index fa66cebfaf671..a150345d77b99 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -816,7 +816,7 @@ fi # Textual substitution functions. # only log once, due to max logging limit on hydra -_substituteStream_has_warned_replace_deprecation="" +_substituteStream_has_warned_replace_deprecation=false substituteStream() { local var=$1 @@ -824,24 +824,18 @@ substituteStream() { shift 2 while (( "$#" )); do - local is_required=1 - local is_quiet="" + local replace_mode="$1" case "$1" in - --replace-quiet) - is_quiet=1 - ;& --replace) # deprecated 2023-11-22 # this will either get removed, or switch to the behaviour of --replace-fail in the future - if [ -z "$is_quiet" ] && [ -z "$_substituteStream_has_warned_replace_deprecation" ]; then + if ! "$_substituteStream_has_warned_replace_deprecation"; then echo "substituteStream(): WARNING: '--replace' is deprecated, use --replace-{fail,warn,quiet}. ($description)" >&2 - _substituteStream_has_warned_replace_deprecation=1 + _substituteStream_has_warned_replace_deprecation=true fi + replace_mode='--replace-warn' ;& - --replace-warn) - is_required="" - ;& - --replace-fail) + --replace-quiet|--replace-warn|--replace-fail) pattern="$2" replacement="$3" shift 3 @@ -850,11 +844,9 @@ substituteStream() { eval "$var"'=${'"$var"'//"$pattern"/"$replacement"}' if [ "$pattern" != "$replacement" ]; then if [ "${!var}" == "$savedvar" ]; then - if [ -z "$is_required" ]; then - if [ -z "$is_quiet" ]; then - printf "substituteStream(): WARNING: pattern %q doesn't match anything in %s\n" "$pattern" "$description" >&2 - fi - else + if [ "$replace_mode" == --replace-warn ]; then + printf "substituteStream(): WARNING: pattern %q doesn't match anything in %s\n" "$pattern" "$description" >&2 + elif [ "$replace_mode" == --replace-fail ]; then printf "substituteStream(): ERROR: pattern %q doesn't match anything in %s\n" "$pattern" "$description" >&2 return 1 fi |