Merge pull request #211187 from Artturin/movetestpatchshenbag


Artturi 76844dfc f488b617

Changed files
+115 -83
pkgs
build-support
setup-hooks
test
top-level
+10 -4
pkgs/build-support/setup-hooks/patch-shebangs.sh
···
fi
if [[ "$oldPath" == *"/bin/env" ]]; then
+
if [[ $arg0 == "-S" ]]; then
+
arg0=${args%% *}
+
args=${args#* }
+
newPath="$(PATH="${!pathName}" command -v "env" || true)"
+
args="-S $(PATH="${!pathName}" command -v "$arg0" || true) $args"
+
# Check for unsupported 'env' functionality:
-
# - options: something starting with a '-'
+
# - options: something starting with a '-' besides '-S'
# - environment variables: foo=bar
-
if [[ $arg0 == "-"* || $arg0 == *"="* ]]; then
+
elif [[ $arg0 == "-"* || $arg0 == *"="* ]]; then
echo "$f: unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)" >&2
exit 1
+
else
+
newPath="$(PATH="${!pathName}" command -v "$arg0" || true)"
fi
-
-
newPath="$(PATH="${!pathName}" command -v "$arg0" || true)"
else
if [[ -z $oldPath ]]; then
# If no interpreter is specified linux will use /bin/sh. Set
-2
pkgs/test/default.nix
···
overriding = callPackage ./overriding.nix { };
-
patch-shebangs = callPackage ./patch-shebangs {};
-
texlive = callPackage ./texlive {};
cuda = callPackage ./cuda { };
-70
pkgs/test/patch-shebangs/default.nix
···
-
{ lib, stdenv, runCommand }:
-
-
let
-
tests = {
-
bad-shebang = stdenv.mkDerivation {
-
name = "bad-shebang";
-
dontUnpack = true;
-
installPhase = ''
-
mkdir -p $out/bin
-
echo "#!/bin/sh" > $out/bin/test
-
echo "echo -n hello" >> $out/bin/test
-
chmod +x $out/bin/test
-
'';
-
passthru = {
-
assertion = "grep -v '^#!/bin/sh' $out/bin/test > /dev/null";
-
};
-
};
-
-
ignores-nix-store = stdenv.mkDerivation {
-
name = "ignores-nix-store";
-
dontUnpack = true;
-
installPhase = ''
-
mkdir -p $out/bin
-
echo "#!$NIX_STORE/path/to/sh" > $out/bin/test
-
echo "echo -n hello" >> $out/bin/test
-
chmod +x $out/bin/test
-
'';
-
passthru = {
-
assertion = "grep \"^#!$NIX_STORE/path/to/sh\" $out/bin/test > /dev/null";
-
};
-
};
-
};
-
in runCommand "patch-shebangs-test" {
-
passthru = { inherit (tests) bad-shebang ignores-nix-store; };
-
meta.platforms = lib.platforms.all;
-
} ''
-
validate() {
-
local name=$1
-
local testout=$2
-
local assertion=$3
-
-
echo -n "... $name: " >&2
-
-
local rc=0
-
(out=$testout eval "$assertion") || rc=1
-
-
if [ "$rc" -eq 0 ]; then
-
echo "yes" >&2
-
else
-
echo "no" >&2
-
fi
-
-
return "$rc"
-
}
-
-
echo "checking whether patchShebangs works properly... ">&2
-
-
fail=
-
${lib.concatStringsSep "\n" (lib.mapAttrsToList (_: test: ''
-
validate "${test.name}" "${test}" ${lib.escapeShellArg test.assertion} || fail=1
-
'') tests)}
-
-
if [ "$fail" ]; then
-
echo "failed"
-
exit 1
-
else
-
echo "succeeded"
-
touch $out
-
fi
-
''
+2 -2
pkgs/test/stdenv/default.nix
···
{
# tests for hooks in `stdenv.defaultNativeBuildInputs`
-
hooks = lib.recurseIntoAttrs (import ./hooks.nix { stdenv = bootStdenv; pkgs = earlyPkgs; });
+
hooks = lib.recurseIntoAttrs (import ./hooks.nix { stdenv = bootStdenv; pkgs = earlyPkgs; inherit lib; });
outputs-no-out = runCommand "outputs-no-out-assert" {
result = testers.testBuildFailure (stdenv.mkDerivation {
···
structuredAttrsByDefault = lib.recurseIntoAttrs {
-
hooks = lib.recurseIntoAttrs (import ./hooks.nix { stdenv = bootStdenvStructuredAttrsByDefault; pkgs = earlyPkgs; });
+
hooks = lib.recurseIntoAttrs (import ./hooks.nix { stdenv = bootStdenvStructuredAttrsByDefault; pkgs = earlyPkgs; inherit lib; });
test-cc-wrapper-substitutions = ccWrapperSubstitutionsTest {
name = "test-cc-wrapper-substitutions-structuredAttrsByDefault";
+2 -2
pkgs/test/stdenv/hooks.nix
···
-
{ stdenv, pkgs }:
+
{ stdenv, pkgs, lib }:
# ordering should match defaultNativeBuildInputs
···
'';
};
# TODO: add multiple-outputs
-
# TODO: move patch-shebangs test from pkgs/test/patch-shebangs/default.nix to here
+
patch-shebangs = import ./patch-shebangs.nix { inherit stdenv lib pkgs; };
prune-libtool-files =
let
libFoo = pkgs.writeText "libFoo" ''
+98
pkgs/test/stdenv/patch-shebangs.nix
···
+
{ lib, stdenv, pkgs }:
+
+
# since the tests are using a early stdenv, the stdenv will have dontPatchShebangs=1, so it has to be unset
+
# https://github.com/NixOS/nixpkgs/blob/768a982bfc9d29a6bd3beb963ed4b054451ce3d0/pkgs/stdenv/linux/default.nix#L148-L153
+
+
# strictDeps has to be disabled because the shell isn't in buildInputs
+
+
let
+
tests = {
+
bad-shebang = stdenv.mkDerivation {
+
name = "bad-shebang";
+
strictDeps = false;
+
dontUnpack = true;
+
installPhase = ''
+
mkdir -p $out/bin
+
echo "#!/bin/bash" > $out/bin/test
+
echo "echo -n hello" >> $out/bin/test
+
chmod +x $out/bin/test
+
dontPatchShebangs=
+
'';
+
passthru = {
+
assertion = "grep '^#!${stdenv.shell}' $out/bin/test > /dev/null";
+
};
+
};
+
+
ignores-nix-store = stdenv.mkDerivation {
+
name = "ignores-nix-store";
+
strictDeps = false;
+
dontUnpack = true;
+
installPhase = ''
+
mkdir -p $out/bin
+
echo "#!$NIX_STORE/path/to/bash" > $out/bin/test
+
echo "echo -n hello" >> $out/bin/test
+
chmod +x $out/bin/test
+
dontPatchShebangs=
+
'';
+
passthru = {
+
assertion = "grep \"^#!$NIX_STORE/path/to/bash\" $out/bin/test > /dev/null";
+
};
+
};
+
+
split-string = stdenv.mkDerivation {
+
name = "split-string";
+
strictDeps = false;
+
dontUnpack = true;
+
installPhase = ''
+
mkdir -p $out/bin
+
echo "#!/usr/bin/env -S bash --posix" > $out/bin/test
+
echo "echo -n hello" >> $out/bin/test
+
chmod +x $out/bin/test
+
dontPatchShebangs=
+
'';
+
passthru = {
+
assertion = "grep -v '^#!${pkgs.coreutils}/bin/env -S ${stdenv.shell} --posix' $out/bin/test > /dev/null";
+
};
+
};
+
+
};
+
in
+
stdenv.mkDerivation {
+
name = "test-patch-shebangs";
+
passthru = { inherit (tests) bad-shebang ignores-nix-store split-string; };
+
buildCommand = ''
+
validate() {
+
local name=$1
+
local testout=$2
+
local assertion=$3
+
+
echo -n "... $name: " >&2
+
+
local rc=0
+
(out=$testout eval "$assertion") || rc=1
+
+
if [ "$rc" -eq 0 ]; then
+
echo "yes" >&2
+
else
+
echo "no" >&2
+
fi
+
+
return "$rc"
+
}
+
+
echo "checking whether patchShebangs works properly... ">&2
+
+
fail=
+
${lib.concatStringsSep "\n" (lib.mapAttrsToList (_: test: ''
+
validate "${test.name}" "${test}" ${lib.escapeShellArg test.assertion} || fail=1
+
'') tests)}
+
+
if [ "$fail" ]; then
+
echo "failed"
+
exit 1
+
else
+
echo "succeeded"
+
touch $out
+
fi
+
'';
+
}
+3 -3
pkgs/top-level/release.nix
···
jobs.tests.cc-wrapper-libcxx.x86_64-darwin
jobs.tests.stdenv-inputs.x86_64-darwin
jobs.tests.macOSSierraShared.x86_64-darwin
-
jobs.tests.patch-shebangs.x86_64-darwin
+
jobs.tests.stdenv.hooks.patch-shebangs.x86_64-darwin
*/
];
} else null;
···
jobs.tests.cc-multilib-gcc.x86_64-linux
jobs.tests.cc-multilib-clang.x86_64-linux
jobs.tests.stdenv-inputs.x86_64-linux
-
jobs.tests.patch-shebangs.x86_64-linux
+
jobs.tests.stdenv.hooks.patch-shebangs.x86_64-linux
*/
]
# FIXME: reintroduce aarch64-darwin after this builds again
···
jobs.tests.cc-wrapper-libcxx-6.x86_64-darwin
jobs.tests.stdenv-inputs.x86_64-darwin
jobs.tests.macOSSierraShared.x86_64-darwin
-
jobs.tests.patch-shebangs.x86_64-darwin
+
jobs.tests.stdenv.hooks.patch-shebangs.x86_64-darwin
*/
];
};