diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2017-08-14 14:34:12 -0400 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2017-08-14 14:44:32 -0400 |
commit | 3c9cf282bba0ccb12d5212563650d152730e7b9d (patch) | |
tree | df5ef0be351811d22e7f1c301e1eb300ac508826 /pkgs/build-support/cc-wrapper/cc-wrapper.sh | |
parent | 9eb901b70ddda39b714619804864f4d4c06a2edd (diff) | |
download | nixlib-3c9cf282bba0ccb12d5212563650d152730e7b9d.tar nixlib-3c9cf282bba0ccb12d5212563650d152730e7b9d.tar.gz nixlib-3c9cf282bba0ccb12d5212563650d152730e7b9d.tar.bz2 nixlib-3c9cf282bba0ccb12d5212563650d152730e7b9d.tar.lz nixlib-3c9cf282bba0ccb12d5212563650d152730e7b9d.tar.xz nixlib-3c9cf282bba0ccb12d5212563650d152730e7b9d.tar.zst nixlib-3c9cf282bba0ccb12d5212563650d152730e7b9d.zip |
cc-wrapper: Improve `set -u` compliance
Diffstat (limited to 'pkgs/build-support/cc-wrapper/cc-wrapper.sh')
-rw-r--r-- | pkgs/build-support/cc-wrapper/cc-wrapper.sh | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh index e5a3a5818519..1c654ea47567 100644 --- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh @@ -34,7 +34,7 @@ cppInclude=1 expandResponseParams "$@" declare -i n=0 nParams=${#params[@]} -while [ "$n" -lt "$nParams" ]; do +while (( "$n" < "$nParams" )); do p=${params[n]} p2=${params[n+1]:-} # handle `p` being last one if [ "$p" = -c ]; then @@ -83,7 +83,7 @@ if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "$NIX_STORE" ]]; then rest=() nParams=${#params[@]} declare -i n=0 - while [ "$n" -lt "$nParams" ]; do + while (( "$n" < "$nParams" )); do p=${params[n]} p2=${params[n+1]:-} # handle `p` being last one if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then @@ -101,21 +101,24 @@ if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "$NIX_STORE" ]]; then fi n+=1 done - params=("${rest[@]}") + # Old bash empty array hack + params=(${rest+"${rest[@]}"}) fi # Clear march/mtune=native -- they bring impurity. if [ "$NIX_@infixSalt@_ENFORCE_NO_NATIVE" = 1 ]; then rest=() - for p in "${params[@]}"; do + # Old bash empty array hack + for p in ${params+"${params[@]}"}; do if [[ "$p" = -m*=native ]]; then skip "$p" else rest+=("$p") fi done - params=("${rest[@]}") + # Old bash empty array hack + params=(${rest+"${rest[@]}"}) fi if [[ "$isCpp" = 1 ]]; then @@ -163,14 +166,13 @@ fi # Optionally print debug info. if [ -n "${NIX_DEBUG:-}" ]; then - set +u # Old bash workaround, see ld-wrapper for explanation. + # Old bash workaround, see ld-wrapper for explanation. echo "extra flags before to @prog@:" >&2 - printf " %q\n" "${extraBefore[@]}" >&2 + printf " %q\n" ${extraBefore+"${extraBefore[@]}"} >&2 echo "original flags to @prog@:" >&2 - printf " %q\n" "${params[@]}" >&2 + printf " %q\n" ${params+"${params[@]}"} >&2 echo "extra flags after to @prog@:" >&2 - printf " %q\n" "${extraAfter[@]}" >&2 - set -u + printf " %q\n" ${extraAfter+"${extraAfter[@]}"} >&2 fi if [ -n "$NIX_CC_WRAPPER_@infixSalt@_EXEC_HOOK" ]; then @@ -178,5 +180,8 @@ if [ -n "$NIX_CC_WRAPPER_@infixSalt@_EXEC_HOOK" ]; then fi PATH="$path_backup" -set +u # Old bash workaround, see above. -exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}" +# Old bash workaround, see above. +exec @prog@ \ + ${extraBefore+"${extraBefore[@]}"} \ + ${params+"${params[@]}"} \ + ${extraAfter+"${extraAfter[@]}"} |