on e94de40 help sign in
54 lines 1.6 kB history raw
1# Test a package set
2{ stdenv, util, haskell-nix, recurseIntoAttrs, haskellLib, testSrc, compiler-nix-name }:
4with stdenv.lib;
6let
7 project = haskell-nix.cabalProject' {
8 inherit compiler-nix-name;
9 src = testSrc "exe-only";
10 };
12 packages = project.hsPkgs;
14in recurseIntoAttrs {
15 ifdInputs = {
16 inherit (project) plan-nix;
17 };
18 run = stdenv.mkDerivation {
19 name = "exe-only-test";
21 buildCommand = ''
22 exe="${packages.exe-only.components.exes.exe-only}/bin/exe-only${stdenv.hostPlatform.extensions.executable}"
24 size=$(command stat --format '%s' "$exe")
25 printf "size of executable $exe is $size. \n" >& 2
27 # fixme: run on target platform when cross-compiled
28 printf "checking whether executable ran... " >& 2
29 cat ${haskellLib.check packages.exe-only.components.exes.exe-only}/test-stdout
30 '' +
31 # Aarch are statically linked and does not have ldd for these tests.
32 optionalString (!stdenv.hostPlatform.isAarch32 && !stdenv.hostPlatform.isAarch64) (
33 if stdenv.hostPlatform.isMusl then ''
34 printf "checking that executable is statically linked... " >& 2
35 (ldd $exe 2>&1 || true) | grep -i "not a"
36 '' else ''
37 printf "checking that executable is dynamically linked to system libraries... " >& 2
38 '' + optionalString stdenv.isLinux ''
39 ldd $exe | grep libpthread
40 '' + optionalString stdenv.isDarwin ''
41 otool -L $exe |grep .dylib
42 '') + ''
44 touch $out
45 '';
47 meta.platforms = platforms.all;
49 passthru = {
50 # Used for debugging with nix repl
51 inherit packages;
52 };
53 };