mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-17 23:36:17 +01:00
makeWrapper: Die on unsupported arguments
Previously, makeWrapper would accept arguments it didn't recognize, potentially allowing argument misspellings or broken callers. Now, makeWrapper dies with a backtrace if it is called incorrectly. Also changes `wrapProgram` so that it doesn't pass through the first argument twice --- this was tripping up the argument checking.
This commit is contained in:
parent
12354b8eb5
commit
ece5387b09
1 changed files with 11 additions and 23 deletions
|
@ -32,26 +32,20 @@ makeWrapper() {
|
|||
for ((n = 2; n < ${#params[*]}; n += 1)); do
|
||||
p="${params[$n]}"
|
||||
|
||||
if test "$p" = "--set"; then
|
||||
if [[ "$p" == "--set" ]]; then
|
||||
varName="${params[$((n + 1))]}"
|
||||
value="${params[$((n + 2))]}"
|
||||
n=$((n + 2))
|
||||
echo "export $varName=\"$value\"" >> "$wrapper"
|
||||
fi
|
||||
|
||||
if test "$p" = "--unset"; then
|
||||
elif [[ "$p" == "--unset" ]]; then
|
||||
varName="${params[$((n + 1))]}"
|
||||
n=$((n + 1))
|
||||
echo "unset $varName" >> "$wrapper"
|
||||
fi
|
||||
|
||||
if test "$p" = "--run"; then
|
||||
elif [[ "$p" == "--run" ]]; then
|
||||
command="${params[$((n + 1))]}"
|
||||
n=$((n + 1))
|
||||
echo "$command" >> "$wrapper"
|
||||
fi
|
||||
|
||||
if test "$p" = "--suffix" -o "$p" = "--prefix"; then
|
||||
elif [[ ("$p" == "--suffix") || ("$p" == "--prefix") ]]; then
|
||||
varName="${params[$((n + 1))]}"
|
||||
separator="${params[$((n + 2))]}"
|
||||
value="${params[$((n + 3))]}"
|
||||
|
@ -63,9 +57,7 @@ makeWrapper() {
|
|||
echo "export $varName=$value\${$varName:+$separator}\$$varName" >> "$wrapper"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "$p" = "--suffix-each"; then
|
||||
elif [[ "$p" == "--suffix-each" ]]; then
|
||||
varName="${params[$((n + 1))]}"
|
||||
separator="${params[$((n + 2))]}"
|
||||
values="${params[$((n + 3))]}"
|
||||
|
@ -73,9 +65,7 @@ makeWrapper() {
|
|||
for value in $values; do
|
||||
echo "export $varName=\$$varName\${$varName:+$separator}$value" >> "$wrapper"
|
||||
done
|
||||
fi
|
||||
|
||||
if test "$p" = "--suffix-contents" -o "$p" = "--prefix-contents"; then
|
||||
elif [[ ("$p" == "--suffix-contents") || ("$p" == "--prefix-contents") ]]; then
|
||||
varName="${params[$((n + 1))]}"
|
||||
separator="${params[$((n + 2))]}"
|
||||
fileNames="${params[$((n + 3))]}"
|
||||
|
@ -87,17 +77,15 @@ makeWrapper() {
|
|||
echo "export $varName=$(cat "$fileName")\${$varName:+$separator}\$$varName" >> "$wrapper"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if test "$p" = "--add-flags"; then
|
||||
elif [[ "$p" == "--add-flags" ]]; then
|
||||
flags="${params[$((n + 1))]}"
|
||||
n=$((n + 1))
|
||||
flagsBefore="$flagsBefore $flags"
|
||||
fi
|
||||
|
||||
if test "$p" = "--argv0"; then
|
||||
elif [[ "$p" == "--argv0" ]]; then
|
||||
argv0="${params[$((n + 1))]}"
|
||||
n=$((n + 1))
|
||||
else
|
||||
die "makeWrapper doesn't understand the arg $p"
|
||||
fi
|
||||
done
|
||||
|
||||
|
@ -138,5 +126,5 @@ wrapProgram() {
|
|||
mv "$prog" "$hidden"
|
||||
# Silence warning about unexpanded $0:
|
||||
# shellcheck disable=SC2016
|
||||
makeWrapper "$hidden" "$prog" --argv0 '$0' "$@"
|
||||
makeWrapper "$hidden" "$prog" --argv0 '$0' "${@:2}"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue