about summary refs log tree commit diff
path: root/pkgs/test
diff options
context:
space:
mode:
authorRick van Schijndel <Mindavi@users.noreply.github.com>2022-06-02 22:27:14 +0200
committerGitHub <noreply@github.com>2022-06-02 22:27:14 +0200
commit17e891b141ca8e599ebf6443d0870a67dd98f94f (patch)
tree5eaa96c8ab010177f2db5d6c1890e3505719a14f /pkgs/test
parent994a8a9588ff2d3269093b5a755d1030e9586a54 (diff)
parenteef2c762ce19c8cf7172b319a7f4cd5555b5f289 (diff)
downloadnixlib-17e891b141ca8e599ebf6443d0870a67dd98f94f.tar
nixlib-17e891b141ca8e599ebf6443d0870a67dd98f94f.tar.gz
nixlib-17e891b141ca8e599ebf6443d0870a67dd98f94f.tar.bz2
nixlib-17e891b141ca8e599ebf6443d0870a67dd98f94f.tar.lz
nixlib-17e891b141ca8e599ebf6443d0870a67dd98f94f.tar.xz
nixlib-17e891b141ca8e599ebf6443d0870a67dd98f94f.tar.zst
nixlib-17e891b141ca8e599ebf6443d0870a67dd98f94f.zip
Merge pull request #175317 from ncfavier/makeBinaryWrapper-cross
makeBinaryWrapper: fix cross-compilation and add test
Diffstat (limited to 'pkgs/test')
-rw-r--r--pkgs/test/make-binary-wrapper/cross.nix23
-rw-r--r--pkgs/test/make-binary-wrapper/default.nix58
2 files changed, 55 insertions, 26 deletions
diff --git a/pkgs/test/make-binary-wrapper/cross.nix b/pkgs/test/make-binary-wrapper/cross.nix
new file mode 100644
index 000000000000..36758086b92b
--- /dev/null
+++ b/pkgs/test/make-binary-wrapper/cross.nix
@@ -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
+''
diff --git a/pkgs/test/make-binary-wrapper/default.nix b/pkgs/test/make-binary-wrapper/default.nix
index 2d3389c4a012..afc2b41ff5a7 100644
--- a/pkgs/test/make-binary-wrapper/default.nix
+++ b/pkgs/test/make-binary-wrapper/default.nix
@@ -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