makeWrapper: implement --inherit-argv0

For symmetry/interoperability with makeBinaryWrapper. Implemented as
--argv0 '$0'
main
Naïm Favier 2 years ago
parent 8b79ef2cb6
commit 2ae69114a1
No known key found for this signature in database
GPG Key ID: 49B07322580B7EE2
  1. 2
      pkgs/applications/editors/neovim/utils.nix
  2. 5
      pkgs/applications/networking/browsers/firefox/wrapper.nix
  3. 4
      pkgs/applications/video/mpv/wrapper.nix
  4. 10
      pkgs/build-support/setup-hooks/make-binary-wrapper/make-binary-wrapper.sh
  5. 17
      pkgs/build-support/setup-hooks/make-wrapper.sh

@ -108,7 +108,7 @@ let
hostprog_check_table); hostprog_check_table);
in in
[ [
"--argv0" "$0" "--add-flags" (lib.escapeShellArgs flags) "--inherit-argv0" "--add-flags" (lib.escapeShellArgs flags)
] ++ lib.optionals withRuby [ ] ++ lib.optionals withRuby [
"--set" "GEM_HOME" "${rubyEnv}/${rubyEnv.ruby.gemPath}" "--set" "GEM_HOME" "${rubyEnv}/${rubyEnv.ruby.gemPath}"
] ++ lib.optionals (binPath != "") [ ] ++ lib.optionals (binPath != "") [

@ -237,10 +237,7 @@ let
parseMakeCWrapperCall() { parseMakeCWrapperCall() {
shift # makeCWrapper shift # makeCWrapper
oldExe=$1; shift oldExe=$1; shift
for arg do case $arg in oldWrapperArgs=("$@")
--inherit-argv0) oldWrapperArgs+=(--argv0 '$0');; # makeWrapper doesn't understand --inherit-argv0
*) oldWrapperArgs+=("$arg");;
esac done
} }
eval "parseMakeCWrapperCall ''${wrapperCmd//"${browser}"/"$out"}" eval "parseMakeCWrapperCall ''${wrapperCmd//"${browser}"/"$out"}"
rm "$executablePath" rm "$executablePath"

@ -32,7 +32,7 @@ let
# All arguments besides the input and output binaries (${mpv}/bin/mpv and # All arguments besides the input and output binaries (${mpv}/bin/mpv and
# $out/bin/mpv). These are used by the darwin specific makeWrapper call # $out/bin/mpv). These are used by the darwin specific makeWrapper call
# used to wrap $out/Applications/mpv.app/Contents/MacOS/mpv as well. # used to wrap $out/Applications/mpv.app/Contents/MacOS/mpv as well.
mostMakeWrapperArgs = lib.strings.escapeShellArgs ([ "--argv0" "'$0'" mostMakeWrapperArgs = lib.strings.escapeShellArgs ([ "--inherit-argv0"
# These are always needed (TODO: Explain why) # These are always needed (TODO: Explain why)
"--prefix" "LUA_CPATH" ";" "${mpv.luaEnv}/lib/lua/${mpv.lua.luaversion}/?.so" "--prefix" "LUA_CPATH" ";" "${mpv.luaEnv}/lib/lua/${mpv.lua.luaversion}/?.so"
"--prefix" "LUA_PATH" ";" "${mpv.luaEnv}/share/lua/${mpv.lua.luaversion}/?.lua" "--prefix" "LUA_PATH" ";" "${mpv.luaEnv}/share/lua/${mpv.lua.luaversion}/?.lua"
@ -53,7 +53,7 @@ let
)) ++ extraMakeWrapperArgs) )) ++ extraMakeWrapperArgs)
; ;
umpvWrapperArgs = lib.strings.escapeShellArgs ([ umpvWrapperArgs = lib.strings.escapeShellArgs ([
"--argv0" "'$0'" "--inherit-argv0"
"--set" "MPV" "${placeholder "out"}/bin/mpv" "--set" "MPV" "${placeholder "out"}/bin/mpv"
] ++ extraUmpvWrapperArgs) ] ++ extraUmpvWrapperArgs)
; ;

@ -15,17 +15,17 @@ assertExecutable() {
# makeWrapper EXECUTABLE OUT_PATH ARGS # makeWrapper EXECUTABLE OUT_PATH ARGS
# ARGS: # ARGS:
# --argv0 NAME : set name of executed process to NAME # --argv0 NAME : set the name of the executed process to NAME
# (otherwise it’s called …-wrapped) # (if unset or empty, defaults to EXECUTABLE)
# --inherit-argv0 : the executable inherits argv0 from the wrapper. # --inherit-argv0 : the executable inherits argv0 from the wrapper.
# (use instead of --argv0 '$0') # (use instead of --argv0 '$0')
# --set VAR VAL : add VAR with value VAL to the executable’s # --set VAR VAL : add VAR with value VAL to the executable's environment
# environment
# --set-default VAR VAL : like --set, but only adds VAR if not already set in # --set-default VAR VAL : like --set, but only adds VAR if not already set in
# the environment # the environment
# --unset VAR : remove VAR from the environment # --unset VAR : remove VAR from the environment
# --chdir DIR : change working directory (use instead of --run "cd DIR") # --chdir DIR : change working directory (use instead of --run "cd DIR")
# --add-flags FLAGS : add FLAGS to invocation of executable # --add-flags FLAGS : add FLAGS to invocation of executable
# TODO(@ncfavier): --append-flags
# --prefix ENV SEP VAL : suffix/prefix ENV with VAL, separated by SEP # --prefix ENV SEP VAL : suffix/prefix ENV with VAL, separated by SEP
# --suffix # --suffix
@ -65,8 +65,6 @@ wrapProgramBinary() {
hidden="${hidden}_" hidden="${hidden}_"
done done
mv "$prog" "$hidden" mv "$prog" "$hidden"
# Silence warning about unexpanded $0:
# shellcheck disable=SC2016
makeWrapper "$hidden" "$prog" --inherit-argv0 "${@:2}" makeWrapper "$hidden" "$prog" --inherit-argv0 "${@:2}"
} }

@ -11,16 +11,18 @@ assertExecutable() {
# makeWrapper EXECUTABLE OUT_PATH ARGS # makeWrapper EXECUTABLE OUT_PATH ARGS
# ARGS: # ARGS:
# --argv0 NAME : set name of executed process to NAME # --argv0 NAME : set the name of the executed process to NAME
# (otherwise it’s called …-wrapped) # (if unset or empty, defaults to EXECUTABLE)
# --set VAR VAL : add VAR with value VAL to the executable’s # --inherit-argv0 : the executable inherits argv0 from the wrapper.
# environment # (use instead of --argv0 '$0')
# --set VAR VAL : add VAR with value VAL to the executable's environment
# --set-default VAR VAL : like --set, but only adds VAR if not already set in # --set-default VAR VAL : like --set, but only adds VAR if not already set in
# the environment # the environment
# --unset VAR : remove VAR from the environment # --unset VAR : remove VAR from the environment
# --chdir DIR : change working directory (use instead of --run "cd DIR") # --chdir DIR : change working directory (use instead of --run "cd DIR")
# --run COMMAND : run command before the executable # --run COMMAND : run command before the executable
# --add-flags FLAGS : add FLAGS to invocation of executable # --add-flags FLAGS : add FLAGS to invocation of executable
# TODO(@ncfavier): --append-flags
# --prefix ENV SEP VAL : suffix/prefix ENV with VAL, separated by SEP # --prefix ENV SEP VAL : suffix/prefix ENV with VAL, separated by SEP
# --suffix # --suffix
@ -166,6 +168,9 @@ makeShellWrapper() {
elif [[ "$p" == "--argv0" ]]; then elif [[ "$p" == "--argv0" ]]; then
argv0="${params[$((n + 1))]}" argv0="${params[$((n + 1))]}"
n=$((n + 1)) n=$((n + 1))
elif [[ "$p" == "--inherit-argv0" ]]; then
# Whichever comes last of --argv0 and --inherit-argv0 wins
argv0='$0'
else else
die "makeWrapper doesn't understand the arg $p" die "makeWrapper doesn't understand the arg $p"
fi fi
@ -206,7 +211,5 @@ wrapProgramShell() {
hidden="${hidden}_" hidden="${hidden}_"
done done
mv "$prog" "$hidden" mv "$prog" "$hidden"
# Silence warning about unexpanded $0: makeWrapper "$hidden" "$prog" --inherit-argv0 "${@:2}"
# shellcheck disable=SC2016
makeWrapper "$hidden" "$prog" --argv0 '$0' "${@:2}"
} }

Loading…
Cancel
Save