on iko/ghcjs-patch-master help sign in
Add `passthru.run` with wine support (#301)

This can be used to run tests, executables or benchmarks. Instead of building drv build drv.run and the result should be the output of stdout.

commit9b10945d98d3a8d53ef7e0c47af789261c289012 authorHamish Mackenzie <Hamish.Mackenzie@iohk.io> dateMon 11 Nov 2019, 23:38 (7 years ago) parent8d1ba98
5 files changed+51−31
builder/comp-builder.nix+27−2 lib/default.nix+8 test/cabal-22/default.nix+6−6 test/exe-only/default.nix+4−4 test/stack-simple/default.nix+6−19
builder/comp-builder.nix+27−2
@@ -1,4 +1,4 @@
1−{ stdenv, buildPackages, ghc, lib, pkgconfig, gobject-introspection ? null, haskellLib, makeConfigFiles, ghcForComponent, hsPkgs }:
1+{ stdenv, buildPackages, ghc, lib, pkgconfig, gobject-introspection ? null, haskellLib, makeConfigFiles, ghcForComponent, hsPkgs, runCommand, libffi, gmp }:
22
33{ componentId
44, component
@@ -117,6 +117,13 @@ let
117117
118118 exeExt = lib.optionalString stdenv.hostPlatform.isWindows ".exe";
119119 testExecutable = "dist/build/${componentId.cname}/${componentId.cname}${exeExt}";
120+ # exe components are in /bin, but test and benchmarks are not. Perhaps to avoid
121+ # them being from being added to the PATH when the all component added to an env.
122+ # TODO revist this to find out why and document or maybe change this.
123+ installedExeDir = if haskellLib.isTest componentId || haskellLib.isBenchmark componentId
124+ then name
125+ else "bin";
126+ installedExe = "${installedExeDir}/${componentId.cname}${exeExt}";
120127
121128in stdenv.lib.fix (drv:
122129
@@ -136,6 +143,9 @@ stdenv.mkDerivation ({
136143 # The directory containing the haddock documentation.
137144 # `null' if no haddock documentation was built.
138145 haddockDir = if doHaddock' then "${docdir drv.doc}/html" else null;
146+ run = runCommand (fullName + "-run") {} ''
147+ ${toString component.testWrapper} ${drv}/${installedExe} | tee $out
148+ '';
139149 };
140150
141151 meta = {
@@ -177,7 +187,7 @@ stdenv.mkDerivation ({
177187 prePatch = if (cabalFile != null)
178188 then ''cat ${cabalFile} > ${package.identifier.name}.cabal''
179189 else lib.optionalString (cabal-generator == "hpack") ''
180− ${hsPkgs.hpack.components.exes.hpack}/bin/hpack
190+ ${buildPackages.haskell-nix.haskellPackages.hpack.components.exes.hpack}/bin/hpack
181191 '';
182192
183193 configurePhase = ''
@@ -267,6 +277,21 @@ stdenv.mkDerivation ({
267277 '')
268278 # In case `setup copy` did not creat this
269279 + (lib.optionalString enableSeparateDataOutput "mkdir -p $data")
280+ + (lib.optionalString (stdenv.hostPlatform.isWindows && (haskellLib.mayHaveExecutable componentId)) ''
281+ echo "Copying libffi and gmp .dlls ..."
282+ for p in ${lib.concatStringsSep " " [ libffi gmp ]}; do
283+ find "$p" -iname '*.dll' -exec cp {} $out/${installedExeDir} \;
284+ done
285+ # copy all .dlls into the local directory.
286+ # we ask ghc-pkg for *all* dynamic-library-dirs and then iterate over the unique set
287+ # to copy over dlls as needed.
288+ echo "Copying library dependencies..."
289+ for libdir in $(x86_64-pc-mingw32-ghc-pkg --package-db=$packageConfDir field "*" dynamic-library-dirs --simple-output|xargs|sed 's/ /\n/g'|sort -u); do
290+ if [ -d "$libdir" ]; then
291+ find "$libdir" -iname '*.dll' -exec cp {} $out/${installedExeDir} \;
292+ fi
293+ done
294+ '')
270295 }
271296 runHook postInstall
272297 '';
lib/default.nix+8
@@ -58,8 +58,16 @@ with haskellLib;
5858
5959 isLibrary = componentId: componentId.ctype == "lib";
6060 isAll = componentId: componentId.ctype == "all";
61+ isExe = componentId: componentId.ctype == "exe";
6162 isTest = componentId: componentId.ctype == "test";
6263 isBenchmark = componentId: componentId.ctype == "bench";
64+ isExecutableType = componentId:
65+ isExe componentId
66+ || isTest componentId
67+ || isBenchmark componentId;
68+ mayHaveExecutable = componentId:
69+ isExecutableType componentId
70+ || isAll componentId;
6371
6472 # Was there a reference to the package source in the `cabal.project` or `stack.yaml` file.
6573 # This is used to make the default `packages` list for `shellFor`.
test/cabal-22/default.nix+6−6
@@ -20,8 +20,8 @@ in
2020 printf "size of executable $exe is $size. \n" >& 2
2121
2222 # fixme: run on target platform when cross-compiled
23− printf "checking whether executable runs... " >& 2
24− "$exe"
23+ printf "checking whether executable rans... " >& 2
24+ cat ${packages.project.components.exes.project.run}
2525
2626 printf "checking that executable is dynamically linked to system libraries... " >& 2
2727 '' + optionalString stdenv.isLinux ''
@@ -46,11 +46,11 @@ in
4646 '') + ''
4747 touch $out
4848
49− printf "checking whether benchmark runs... " >& 2
50− ${packages.project.components.benchmarks.project-bench}/*/project-bench
49+ printf "checking whether benchmark ran... " >& 2
50+ cat ${packages.project.components.benchmarks.project-bench.run}
5151
52− printf "checking whether tests run... " >& 2
53− ${packages.project.components.tests.unit}/*/unit
52+ printf "checking whether tests ran... " >& 2
53+ cat ${packages.project.components.tests.unit.run}
5454 '';
5555
5656 meta.platforms = platforms.all;
test/exe-only/default.nix+4−4
@@ -16,14 +16,14 @@ in
1616 name = "exe-only-test";
1717
1818 buildCommand = ''
19− exe="${packages.exe-only.components.exes.exe-only}/bin/exe-only"
19+ exe="${packages.exe-only.components.exes.exe-only}/bin/exe-only${stdenv.hostPlatform.extensions.executable}"
2020
2121 size=$(command stat --format '%s' "$exe")
2222 printf "size of executable $exe is $size. \n" >& 2
2323
2424 # fixme: run on target platform when cross-compiled
25− printf "checking whether executable runs... " >& 2
26− $exe
25+ printf "checking whether executable ran... " >& 2
26+ cat ${packages.exe-only.components.exes.exe-only.run}
2727 '' + (if stdenv.hostPlatform.isMusl then ''
2828 printf "checking that executable is statically linked... " >& 2
2929 (ldd $exe 2>&1 || true) | grep -i "not a"
@@ -36,7 +36,7 @@ in
3636 '') + ''
3737
3838 printf "Checking that \"all\" component has the programs... " >& 2
39− all_exe="${packages.exe-only.components.all}/bin/exe-only"
39+ all_exe="${packages.exe-only.components.all}/bin/exe-only${stdenv.hostPlatform.extensions.executable}"
4040 test -f "$all_exe"
4141 echo "$all_exe" >& 2
4242
test/stack-simple/default.nix+6−19
@@ -1,4 +1,4 @@
1−{ stdenv, mkStackPkgSet }:
1+{ stdenv, pkgs, mkStackPkgSet }:
22
33with stdenv.lib;
44
@@ -13,23 +13,10 @@ let
1313
1414 packages = pkgSet.config.hsPkgs;
1515
16−in
17− stdenv.mkDerivation {
18− name = "stack-simple-test";
19−
20− buildCommand = ''
21− exe="${packages.stack-simple.components.exes.stack-simple-exe}/bin/stack-simple-exe"
22−
23− printf "checking whether executable runs... " >& 2
24− $exe
25−
26− touch $out
27− '';
28−
29− meta.platforms = platforms.all;
30−
31− passthru = {
16+in pkgs.recurseIntoAttrs {
17+ stack-simple-exe = packages.stack-simple.components.exes.stack-simple-exe.run // {
3218 # Attributes used for debugging with nix repl
3319 inherit pkgSet packages;
34− };
35− }
20+ };
21+ stack-simple-test = packages.stack-simple.components.tests.stack-simple-test.run;
22+}