From 61cad61ebf40416dd9749f5a50b95f4ca12ce59f Mon Sep 17 00:00:00 2001 From: Thomas Tuegel Date: Sun, 30 Aug 2015 10:41:43 -0500 Subject: [PATCH] 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. --- pkgs/build-support/setup-hooks/make-wrapper.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/setup-hooks/make-wrapper.sh b/pkgs/build-support/setup-hooks/make-wrapper.sh index f474ff5e88ed..5150b4f0218a 100644 --- a/pkgs/build-support/setup-hooks/make-wrapper.sh +++ b/pkgs/build-support/setup-hooks/make-wrapper.sh @@ -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"' "$@" }