Merge pull request #211187 from Artturin/movetestpatchshenbag

This commit is contained in:
Artturi 2023-02-18 19:13:17 +02:00 committed by GitHub
commit 76844dfcfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 115 additions and 83 deletions

View File

@ -62,15 +62,21 @@ patchShebangs() {
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

View File

@ -63,8 +63,6 @@ with pkgs;
overriding = callPackage ./overriding.nix { };
patch-shebangs = callPackage ./patch-shebangs {};
texlive = callPackage ./texlive {};
cuda = callPackage ./cuda { };

View File

@ -1,70 +0,0 @@
{ 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
''

View File

@ -98,7 +98,7 @@ in
{
# 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 {
@ -158,7 +158,7 @@ in
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";

View File

@ -1,4 +1,4 @@
{ stdenv, pkgs }:
{ stdenv, pkgs, lib }:
# ordering should match defaultNativeBuildInputs
@ -91,7 +91,7 @@
'';
};
# 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" ''

View File

@ -0,0 +1,98 @@
{ 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
'';
}

View File

@ -82,7 +82,7 @@ let
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;
@ -127,7 +127,7 @@ let
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
@ -158,7 +158,7 @@ let
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
*/
];
};