Skip to content

Commit

Permalink
makeWrapper: accept --argv0 flag (/cc NixOS#9562)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ttuegel authored and vcunat committed Sep 1, 2015
1 parent 1464a4d commit 61cad61
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkgs/build-support/setup-hooks/make-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"

Expand Down Expand Up @@ -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
}
Expand All @@ -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"' "$@"
}

0 comments on commit 61cad61

Please sign in to comment.