makeWrapper: accept --argv0 flag (/cc #9562)

By default `makeWrapper` will not set argv[0] (this is a reversion to
the old default behavior). Based on the breakage we have seen from
changing the default, this is what most people want. The `wrapProgram`
function will send `--argv0 '"$0"'` to `makeWrapper`, i.e. it will
continue to pass-through the argv[0] that the wrapper is called with.
This commit is contained in:
Thomas Tuegel 2015-08-30 10:41:43 -05:00 committed by Vladimír Čunát
parent 1464a4de57
commit 61cad61ebf

View File

@ -2,7 +2,7 @@ makeWrapper() {
local original=$1
local wrapper=$2
local params varName value command separator n fileNames
local flagsBefore flags
local argv0 flagsBefore flags
mkdir -p "$(dirname $wrapper)"
@ -68,11 +68,17 @@ makeWrapper() {
n=$((n + 1))
flagsBefore="$flagsBefore $flags"
fi
if test "$p" = "--argv0"; then
argv0=${params[$((n + 1))]}
n=$((n + 1))
fi
done
# Note: extraFlagsArray is an array containing additional flags
# that may be set by --run actions.
echo exec -a '"$0"' "$original" $flagsBefore '"${extraFlagsArray[@]}"' '"$@"' >> $wrapper
echo exec ${argv0:+-a $argv0} "$original" \
$flagsBefore '"${extraFlagsArray[@]}"' '"$@"' >> $wrapper
chmod +x $wrapper
}
@ -98,5 +104,5 @@ wrapProgram() {
local prog="$1"
local hidden="$(dirname "$prog")/.$(basename "$prog")"-wrapped
mv $prog $hidden
makeWrapper $hidden $prog "$@"
makeWrapper $hidden $prog --argv0 '"$0"' "$@"
}