summary refs log tree commit diff
path: root/pkgs/build-support/libredirect/default.nix
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2018-11-12 10:48:15 +0100
committeraszlig <aszlig@nix.build>2018-11-12 11:02:54 +0100
commit34dd1c68f877912290fcad4bb8d4d3c0035ef5e6 (patch)
tree5a5158cf92e21ec9eb7a199e8fd8898667f654c2 /pkgs/build-support/libredirect/default.nix
parentba1fddb31535c5721cf2c3913e704f0b258f656b (diff)
downloadnixpkgs-34dd1c68f877912290fcad4bb8d4d3c0035ef5e6.tar
nixpkgs-34dd1c68f877912290fcad4bb8d4d3c0035ef5e6.tar.gz
nixpkgs-34dd1c68f877912290fcad4bb8d4d3c0035ef5e6.tar.bz2
nixpkgs-34dd1c68f877912290fcad4bb8d4d3c0035ef5e6.tar.lz
nixpkgs-34dd1c68f877912290fcad4bb8d4d3c0035ef5e6.tar.xz
nixpkgs-34dd1c68f877912290fcad4bb8d4d3c0035ef5e6.tar.zst
nixpkgs-34dd1c68f877912290fcad4bb8d4d3c0035ef5e6.zip
libredirect: Add a small test
This is just a sanity check on whether the library correctly wraps the
syscalls and it's using the "true" executable for posix_spawn() and
execv().

The installCheckPhase is not executed if we are cross-compiling, so this
shouldn't break cross-compilation.

One thing I'm not actually sure is whether ${coreutils}/bin/true is
universally available on all the platforms, nor whether all the
functions we use in the test are available, but we can still fix that
after we've found out about that.

Signed-off-by: aszlig <aszlig@nix.build>
Diffstat (limited to 'pkgs/build-support/libredirect/default.nix')
-rw-r--r--pkgs/build-support/libredirect/default.nix22
1 files changed, 20 insertions, 2 deletions
diff --git a/pkgs/build-support/libredirect/default.nix b/pkgs/build-support/libredirect/default.nix
index fec659ff5fd..09a3da6729a 100644
--- a/pkgs/build-support/libredirect/default.nix
+++ b/pkgs/build-support/libredirect/default.nix
@@ -1,21 +1,39 @@
-{ stdenv }:
+{ stdenv, coreutils }:
 
 stdenv.mkDerivation {
   name = "libredirect-0";
 
-  unpackPhase = "cp ${./libredirect.c} libredirect.c";
+  unpackPhase = ''
+    cp ${./libredirect.c} libredirect.c
+    cp ${./test.c} test.c
+  '';
 
   shlibext = stdenv.targetPlatform.extensions.sharedLibrary;
 
   buildPhase = ''
     $CC -Wall -std=c99 -O3 -shared libredirect.c \
       -o "libredirect$shlibext" -fPIC -ldl
+
+    if [ -n "$doInstallCheck" ]; then
+      $CC -Wall -std=c99 -O3 test.c -o test
+    fi
   '';
 
   installPhase = ''
     install -vD "libredirect$shlibext" "$out/lib/libredirect$shlibext"
   '';
 
+  doInstallCheck = true;
+
+  installCheckPhase = if stdenv.isDarwin then ''
+    NIX_REDIRECTS="/foo/bar/test=${coreutils}/bin/true" \
+    DYLD_INSERT_LIBRARIES="$out/lib/libredirect$shlibext" \
+    DYLD_FORCE_FLAT_NAMESPACE=1 ./test
+  '' else ''
+    NIX_REDIRECTS="/foo/bar/test=${coreutils}/bin/true" \
+    LD_PRELOAD="$out/lib/libredirect$shlibext" ./test
+  '';
+
   meta = {
     platforms = stdenv.lib.platforms.unix;
     description = "An LD_PRELOAD library to intercept and rewrite the paths in glibc calls";