Merge pull request #175317 from ncfavier/makeBinaryWrapper-cross
makeBinaryWrapper: fix cross-compilation and add test
This commit is contained in:
commit
17e891b141
3 changed files with 58 additions and 28 deletions
|
@ -1,10 +1,11 @@
|
|||
{ stdenv
|
||||
, targetPackages
|
||||
, lib
|
||||
, makeSetupHook
|
||||
, dieHook
|
||||
, writeShellScript
|
||||
, tests
|
||||
, cc ? stdenv.cc
|
||||
, cc ? targetPackages.stdenv.cc
|
||||
, sanitizers ? []
|
||||
}:
|
||||
|
||||
|
@ -14,7 +15,7 @@ makeSetupHook {
|
|||
++ lib.optional (stdenv.isDarwin && stdenv.isAarch64) cc;
|
||||
|
||||
substitutions = {
|
||||
cc = "${cc}/bin/cc ${lib.escapeShellArgs (map (s: "-fsanitize=${s}") sanitizers)}";
|
||||
cc = "${cc}/bin/${cc.targetPrefix}cc ${lib.escapeShellArgs (map (s: "-fsanitize=${s}") sanitizers)}";
|
||||
|
||||
# Extract the function call used to create a binary wrapper from its embedded docstring
|
||||
passthru.extractCmd = writeShellScript "extract-binary-wrapper-cmd" ''
|
||||
|
|
23
pkgs/test/make-binary-wrapper/cross.nix
Normal file
23
pkgs/test/make-binary-wrapper/cross.nix
Normal file
|
@ -0,0 +1,23 @@
|
|||
{ stdenv
|
||||
, runCommand
|
||||
, makeBinaryWrapper
|
||||
, binutils
|
||||
, expectedArch ? stdenv.hostPlatform.parsed.cpu.name
|
||||
}:
|
||||
|
||||
runCommand "make-binary-wrapper-test-cross" {
|
||||
nativeBuildInputs = [
|
||||
makeBinaryWrapper
|
||||
binutils
|
||||
];
|
||||
inherit expectedArch;
|
||||
} ''
|
||||
touch prog
|
||||
chmod +x prog
|
||||
makeWrapper prog $out
|
||||
read -r _ arch < <($READELF --file-header $out | grep Machine:)
|
||||
if [[ ''${arch,,} != *"''${expectedArch,,}"* ]]; then
|
||||
echo "expected $expectedArch, got $arch"
|
||||
exit 1
|
||||
fi
|
||||
''
|
|
@ -1,12 +1,19 @@
|
|||
{ lib, coreutils, python3, gcc, writeText, writeScript, runCommand, makeBinaryWrapper }:
|
||||
{ lib
|
||||
, stdenv
|
||||
, pkgsCross
|
||||
, makeBinaryWrapper
|
||||
, writeText
|
||||
, runCommand
|
||||
, runCommandCC
|
||||
}:
|
||||
|
||||
let
|
||||
env = { buildInputs = [ makeBinaryWrapper ]; };
|
||||
envCheck = runCommand "envcheck" env ''
|
||||
${gcc}/bin/cc -Wall -Werror -Wpedantic -o $out ${./envcheck.c}
|
||||
env = { nativeBuildInputs = [ makeBinaryWrapper ]; };
|
||||
envCheck = runCommandCC "envcheck" env ''
|
||||
cc -Wall -Werror -Wpedantic -o $out ${./envcheck.c}
|
||||
'';
|
||||
makeGoldenTest = testname: runCommand "test-wrapper_${testname}" env ''
|
||||
mkdir -p ./tmp/foo
|
||||
makeGoldenTest = testname: runCommand "make-binary-wrapper-test-${testname}" env ''
|
||||
mkdir -p tmp/foo # for the chdir test
|
||||
|
||||
params=$(<"${./.}/${testname}.cmdline")
|
||||
eval "makeCWrapper /send/me/flags $params" > wrapper.c
|
||||
|
@ -32,24 +39,23 @@ let
|
|||
|
||||
cp wrapper.c $out
|
||||
'';
|
||||
tests = let
|
||||
names = [
|
||||
"add-flags"
|
||||
"argv0"
|
||||
"basic"
|
||||
"chdir"
|
||||
"combination"
|
||||
"env"
|
||||
"inherit-argv0"
|
||||
"invalid-env"
|
||||
"prefix"
|
||||
"suffix"
|
||||
"overlength-strings"
|
||||
];
|
||||
f = name: lib.nameValuePair name (makeGoldenTest name);
|
||||
in builtins.listToAttrs (builtins.map f names);
|
||||
in writeText "make-binary-wrapper-test" ''
|
||||
${lib.concatStringsSep "\n" (lib.mapAttrsToList (_: test: ''
|
||||
"${test.name}" "${test}"
|
||||
'') tests)}
|
||||
tests = lib.genAttrs [
|
||||
"add-flags"
|
||||
"argv0"
|
||||
"basic"
|
||||
"chdir"
|
||||
"combination"
|
||||
"env"
|
||||
"inherit-argv0"
|
||||
"invalid-env"
|
||||
"overlength-strings"
|
||||
"prefix"
|
||||
"suffix"
|
||||
] makeGoldenTest // lib.optionalAttrs (! stdenv.isDarwin) {
|
||||
cross = pkgsCross.aarch64-multiplatform.callPackage ./cross.nix { };
|
||||
};
|
||||
in
|
||||
|
||||
writeText "make-binary-wrapper-tests" ''
|
||||
${lib.concatStringsSep "\n" (builtins.attrValues tests)}
|
||||
'' // tests
|
||||
|
|
Loading…
Reference in a new issue