cc-wrapper: Improve set -u
compliance
This commit is contained in:
parent
9eb901b70d
commit
3c9cf282bb
@ -34,7 +34,7 @@ cppInclude=1
|
|||||||
expandResponseParams "$@"
|
expandResponseParams "$@"
|
||||||
declare -i n=0
|
declare -i n=0
|
||||||
nParams=${#params[@]}
|
nParams=${#params[@]}
|
||||||
while [ "$n" -lt "$nParams" ]; do
|
while (( "$n" < "$nParams" )); do
|
||||||
p=${params[n]}
|
p=${params[n]}
|
||||||
p2=${params[n+1]:-} # handle `p` being last one
|
p2=${params[n+1]:-} # handle `p` being last one
|
||||||
if [ "$p" = -c ]; then
|
if [ "$p" = -c ]; then
|
||||||
@ -83,7 +83,7 @@ if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "$NIX_STORE" ]]; then
|
|||||||
rest=()
|
rest=()
|
||||||
nParams=${#params[@]}
|
nParams=${#params[@]}
|
||||||
declare -i n=0
|
declare -i n=0
|
||||||
while [ "$n" -lt "$nParams" ]; do
|
while (( "$n" < "$nParams" )); do
|
||||||
p=${params[n]}
|
p=${params[n]}
|
||||||
p2=${params[n+1]:-} # handle `p` being last one
|
p2=${params[n+1]:-} # handle `p` being last one
|
||||||
if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
|
if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
|
||||||
@ -101,21 +101,24 @@ if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "$NIX_STORE" ]]; then
|
|||||||
fi
|
fi
|
||||||
n+=1
|
n+=1
|
||||||
done
|
done
|
||||||
params=("${rest[@]}")
|
# Old bash empty array hack
|
||||||
|
params=(${rest+"${rest[@]}"})
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Clear march/mtune=native -- they bring impurity.
|
# Clear march/mtune=native -- they bring impurity.
|
||||||
if [ "$NIX_@infixSalt@_ENFORCE_NO_NATIVE" = 1 ]; then
|
if [ "$NIX_@infixSalt@_ENFORCE_NO_NATIVE" = 1 ]; then
|
||||||
rest=()
|
rest=()
|
||||||
for p in "${params[@]}"; do
|
# Old bash empty array hack
|
||||||
|
for p in ${params+"${params[@]}"}; do
|
||||||
if [[ "$p" = -m*=native ]]; then
|
if [[ "$p" = -m*=native ]]; then
|
||||||
skip "$p"
|
skip "$p"
|
||||||
else
|
else
|
||||||
rest+=("$p")
|
rest+=("$p")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
params=("${rest[@]}")
|
# Old bash empty array hack
|
||||||
|
params=(${rest+"${rest[@]}"})
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$isCpp" = 1 ]]; then
|
if [[ "$isCpp" = 1 ]]; then
|
||||||
@ -163,14 +166,13 @@ fi
|
|||||||
|
|
||||||
# Optionally print debug info.
|
# Optionally print debug info.
|
||||||
if [ -n "${NIX_DEBUG:-}" ]; then
|
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
|
echo "extra flags before to @prog@:" >&2
|
||||||
printf " %q\n" "${extraBefore[@]}" >&2
|
printf " %q\n" ${extraBefore+"${extraBefore[@]}"} >&2
|
||||||
echo "original flags to @prog@:" >&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
|
echo "extra flags after to @prog@:" >&2
|
||||||
printf " %q\n" "${extraAfter[@]}" >&2
|
printf " %q\n" ${extraAfter+"${extraAfter[@]}"} >&2
|
||||||
set -u
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$NIX_CC_WRAPPER_@infixSalt@_EXEC_HOOK" ]; then
|
if [ -n "$NIX_CC_WRAPPER_@infixSalt@_EXEC_HOOK" ]; then
|
||||||
@ -178,5 +180,8 @@ if [ -n "$NIX_CC_WRAPPER_@infixSalt@_EXEC_HOOK" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
PATH="$path_backup"
|
PATH="$path_backup"
|
||||||
set +u # Old bash workaround, see above.
|
# Old bash workaround, see above.
|
||||||
exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"
|
exec @prog@ \
|
||||||
|
${extraBefore+"${extraBefore[@]}"} \
|
||||||
|
${params+"${params[@]}"} \
|
||||||
|
${extraAfter+"${extraAfter[@]}"}
|
||||||
|
@ -28,7 +28,7 @@ if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "${NIX_STORE:-}"
|
|||||||
rest=()
|
rest=()
|
||||||
nParams=${#params[@]}
|
nParams=${#params[@]}
|
||||||
declare -i n=0
|
declare -i n=0
|
||||||
while [ "$n" -lt "$nParams" ]; do
|
while (( "$n" < "$nParams" )); do
|
||||||
p=${params[n]}
|
p=${params[n]}
|
||||||
p2=${params[n+1]:-} # handle `p` being last one
|
p2=${params[n+1]:-} # handle `p` being last one
|
||||||
if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
|
if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
|
||||||
@ -51,7 +51,8 @@ if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "${NIX_STORE:-}"
|
|||||||
fi
|
fi
|
||||||
n+=1
|
n+=1
|
||||||
done
|
done
|
||||||
params=("${rest[@]}")
|
# Old bash empty array hack
|
||||||
|
params=(${rest+"${rest[@]}"})
|
||||||
fi
|
fi
|
||||||
|
|
||||||
source @out@/nix-support/add-hardening.sh
|
source @out@/nix-support/add-hardening.sh
|
||||||
@ -73,11 +74,12 @@ relocatable=
|
|||||||
# Find all -L... switches for rpath, and relocatable flags for build id.
|
# Find all -L... switches for rpath, and relocatable flags for build id.
|
||||||
if [ "$NIX_@infixSalt@_DONT_SET_RPATH" != 1 ] || [ "$NIX_@infixSalt@_SET_BUILD_ID" = 1 ]; then
|
if [ "$NIX_@infixSalt@_DONT_SET_RPATH" != 1 ] || [ "$NIX_@infixSalt@_SET_BUILD_ID" = 1 ]; then
|
||||||
prev=
|
prev=
|
||||||
# Old bash thinks empty arrays are undefined, ugh, so temporarily disable
|
# Old bash thinks empty arrays are undefined, ugh.
|
||||||
# `set -u`.
|
for p in \
|
||||||
set +u
|
${extraBefore+"${extraBefore[@]}"} \
|
||||||
for p in "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"; do
|
${params+"${params[@]}"} \
|
||||||
set -u
|
${extraAfter+"${extraAfter[@]}"}
|
||||||
|
do
|
||||||
case "$prev" in
|
case "$prev" in
|
||||||
-L)
|
-L)
|
||||||
libDirs+=("$p")
|
libDirs+=("$p")
|
||||||
@ -155,14 +157,13 @@ fi
|
|||||||
|
|
||||||
# Optionally print debug info.
|
# Optionally print debug info.
|
||||||
if [ -n "${NIX_DEBUG:-}" ]; then
|
if [ -n "${NIX_DEBUG:-}" ]; then
|
||||||
set +u # Old bash workaround, see above.
|
# Old bash workaround, see above.
|
||||||
echo "extra flags before to @prog@:" >&2
|
echo "extra flags before to @prog@:" >&2
|
||||||
printf " %q\n" "${extraBefore[@]}" >&2
|
printf " %q\n" ${extraBefore+"${extraBefore[@]}"} >&2
|
||||||
echo "original flags to @prog@:" >&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
|
echo "extra flags after to @prog@:" >&2
|
||||||
printf " %q\n" "${extraAfter[@]}" >&2
|
printf " %q\n" ${extraAfter+"${extraAfter[@]}"} >&2
|
||||||
set -u
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$NIX_LD_WRAPPER_@infixSalt@_EXEC_HOOK" ]; then
|
if [ -n "$NIX_LD_WRAPPER_@infixSalt@_EXEC_HOOK" ]; then
|
||||||
@ -170,5 +171,8 @@ if [ -n "$NIX_LD_WRAPPER_@infixSalt@_EXEC_HOOK" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
PATH="$path_backup"
|
PATH="$path_backup"
|
||||||
set +u # Old bash workaround, see above.
|
# Old bash workaround, see above.
|
||||||
exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"
|
exec @prog@ \
|
||||||
|
${extraBefore+"${extraBefore[@]}"} \
|
||||||
|
${params+"${params[@]}"} \
|
||||||
|
${extraAfter+"${extraAfter[@]}"}
|
||||||
|
@ -24,7 +24,7 @@ badPath() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expandResponseParams() {
|
expandResponseParams() {
|
||||||
declare -g params=("$@")
|
declare -ga params=("$@")
|
||||||
local arg
|
local arg
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
if [[ "$arg" == @* ]]; then
|
if [[ "$arg" == @* ]]; then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user