mirror of
https://github.com/SebastianWendel/nixpkgs.git
synced 2024-09-21 21:09:00 +02:00
Merge pull request #49608 from matthewbauer/cross-patch-shebangs-2
Restore cross-patch-shebangs branch
This commit is contained in:
commit
c8aff96110
|
@ -5,10 +5,32 @@
|
||||||
# rewritten to /nix/store/<hash>/bin/python. Interpreters that are
|
# rewritten to /nix/store/<hash>/bin/python. Interpreters that are
|
||||||
# already in the store are left untouched.
|
# already in the store are left untouched.
|
||||||
|
|
||||||
fixupOutputHooks+=('if [ -z "$dontPatchShebangs" -a -e "$prefix" ]; then patchShebangs "$prefix"; fi')
|
fixupOutputHooks+=(patchShebangsAuto)
|
||||||
|
|
||||||
|
# Run patch shebangs on a directory.
|
||||||
|
# patchShebangs [--build | --host] directory
|
||||||
|
|
||||||
|
# Flags:
|
||||||
|
# --build : Lookup commands available at build-time
|
||||||
|
# --host : Lookup commands available at runtime
|
||||||
|
|
||||||
|
# Example use cases,
|
||||||
|
# $ patchShebangs --host /nix/store/...-hello-1.0/bin
|
||||||
|
# $ patchShebangs --build configure
|
||||||
|
|
||||||
patchShebangs() {
|
patchShebangs() {
|
||||||
|
local pathName
|
||||||
|
|
||||||
|
if [ "$1" = "--host" ]; then
|
||||||
|
pathName=HOST_PATH
|
||||||
|
shift
|
||||||
|
elif [ "$1" = "--build" ]; then
|
||||||
|
pathName=PATH
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
local dir="$1"
|
local dir="$1"
|
||||||
|
|
||||||
header "patching script interpreter paths in $dir"
|
header "patching script interpreter paths in $dir"
|
||||||
local f
|
local f
|
||||||
local oldPath
|
local oldPath
|
||||||
|
@ -27,6 +49,14 @@ patchShebangs() {
|
||||||
oldInterpreterLine=$(head -1 "$f" | tail -c+3)
|
oldInterpreterLine=$(head -1 "$f" | tail -c+3)
|
||||||
read -r oldPath arg0 args <<< "$oldInterpreterLine"
|
read -r oldPath arg0 args <<< "$oldInterpreterLine"
|
||||||
|
|
||||||
|
if [ -z "$pathName" ]; then
|
||||||
|
if [ -n "$strictDeps" ] && [[ "$f" = "$NIX_STORE"* ]]; then
|
||||||
|
pathName=HOST_PATH
|
||||||
|
else
|
||||||
|
pathName=PATH
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if $(echo "$oldPath" | grep -q "/bin/env$"); then
|
if $(echo "$oldPath" | grep -q "/bin/env$"); then
|
||||||
# Check for unsupported 'env' functionality:
|
# Check for unsupported 'env' functionality:
|
||||||
# - options: something starting with a '-'
|
# - options: something starting with a '-'
|
||||||
|
@ -35,14 +65,17 @@ patchShebangs() {
|
||||||
echo "$f: unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)"
|
echo "$f: unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
newPath="$(command -v "$arg0" || true)"
|
|
||||||
|
newPath="$(PATH="${!pathName}" command -v "$arg0" || true)"
|
||||||
else
|
else
|
||||||
if [ "$oldPath" = "" ]; then
|
if [ "$oldPath" = "" ]; then
|
||||||
# If no interpreter is specified linux will use /bin/sh. Set
|
# If no interpreter is specified linux will use /bin/sh. Set
|
||||||
# oldpath="/bin/sh" so that we get /nix/store/.../sh.
|
# oldpath="/bin/sh" so that we get /nix/store/.../sh.
|
||||||
oldPath="/bin/sh"
|
oldPath="/bin/sh"
|
||||||
fi
|
fi
|
||||||
newPath="$(command -v "$(basename "$oldPath")" || true)"
|
|
||||||
|
newPath="$(PATH="${!pathName}" command -v "$(basename "$oldPath")" || true)"
|
||||||
|
|
||||||
args="$arg0 $args"
|
args="$arg0 $args"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -65,3 +98,19 @@ patchShebangs() {
|
||||||
|
|
||||||
stopNest
|
stopNest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
patchShebangsAuto () {
|
||||||
|
if [ -z "$dontPatchShebangs" -a -e "$prefix" ]; then
|
||||||
|
|
||||||
|
if [ -z "${strictDeps-}"]; then
|
||||||
|
patchShebangs --build "$prefix"
|
||||||
|
# Dev output will end up being run on the build platform. An
|
||||||
|
# example case of this is sdl2-config. Otherwise, we can just
|
||||||
|
# use the runtime path (--host).
|
||||||
|
elif [ "$output" != out ] && [ "$output" = "${!outputDev}" ]; then
|
||||||
|
patchShebangs --build "$prefix"
|
||||||
|
else
|
||||||
|
patchShebangs --host "$prefix"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
|
@ -278,8 +278,8 @@ in rec {
|
||||||
# enables patchShebangs above. Unfortunately, patchShebangs ignores our $SHELL setting
|
# enables patchShebangs above. Unfortunately, patchShebangs ignores our $SHELL setting
|
||||||
# and instead goes by $PATH, which happens to contain bootstrapTools. So it goes and
|
# and instead goes by $PATH, which happens to contain bootstrapTools. So it goes and
|
||||||
# patches our shebangs back to point at bootstrapTools. This makes sure bash comes first.
|
# patches our shebangs back to point at bootstrapTools. This makes sure bash comes first.
|
||||||
extraNativeBuildInputs = with pkgs; [ xz pkgs.bash ];
|
extraNativeBuildInputs = with pkgs; [ xz ];
|
||||||
extraBuildInputs = [ pkgs.darwin.CF ];
|
extraBuildInputs = [ pkgs.darwin.CF pkgs.bash ];
|
||||||
libcxx = pkgs.libcxx;
|
libcxx = pkgs.libcxx;
|
||||||
|
|
||||||
extraPreHook = ''
|
extraPreHook = ''
|
||||||
|
@ -335,8 +335,8 @@ in rec {
|
||||||
};
|
};
|
||||||
in with prevStage; stageFun 4 prevStage {
|
in with prevStage; stageFun 4 prevStage {
|
||||||
shell = "${pkgs.bash}/bin/bash";
|
shell = "${pkgs.bash}/bin/bash";
|
||||||
extraNativeBuildInputs = with pkgs; [ xz pkgs.bash ];
|
extraNativeBuildInputs = with pkgs; [ xz ];
|
||||||
extraBuildInputs = [ pkgs.darwin.CF ];
|
extraBuildInputs = [ pkgs.darwin.CF pkgs.bash ];
|
||||||
libcxx = pkgs.libcxx;
|
libcxx = pkgs.libcxx;
|
||||||
|
|
||||||
extraPreHook = ''
|
extraPreHook = ''
|
||||||
|
|
|
@ -257,17 +257,9 @@ shopt -s nullglob
|
||||||
|
|
||||||
# Set up the initial path.
|
# Set up the initial path.
|
||||||
PATH=
|
PATH=
|
||||||
HOST_PATH=
|
|
||||||
for i in $initialPath; do
|
for i in $initialPath; do
|
||||||
if [ "$i" = / ]; then i=; fi
|
if [ "$i" = / ]; then i=; fi
|
||||||
addToSearchPath PATH "$i/bin"
|
addToSearchPath PATH "$i/bin"
|
||||||
|
|
||||||
# For backward compatibility, we add initial path to HOST_PATH so
|
|
||||||
# it can be used in auto patch-shebangs. Unfortunately this will
|
|
||||||
# not work with cross compilation.
|
|
||||||
if [ -z "${strictDeps-}" ]; then
|
|
||||||
addToSearchPath HOST_PATH "$i/bin"
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then
|
if (( "${NIX_DEBUG:-0}" >= 1 )); then
|
||||||
|
|
Loading…
Reference in a new issue