on iko/ghcjs-patch-master help sign in
Add `passthru.run` with wine support (#301)
9b10945Hamish Mackenzie
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 }:
2
2
3{ componentId
3{ componentId
4, component
4, component
@@ -117,6 +117,13 @@ let
117
117
118 exeExt = lib.optionalString stdenv.hostPlatform.isWindows ".exe";
118 exeExt = lib.optionalString stdenv.hostPlatform.isWindows ".exe";
119 testExecutable = "dist/build/${componentId.cname}/${componentId.cname}${exeExt}";
119 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}";
120
127
121in stdenv.lib.fix (drv:
128in stdenv.lib.fix (drv:
122
129
@@ -136,6 +143,9 @@ stdenv.mkDerivation ({
136 # The directory containing the haddock documentation.
143 # The directory containing the haddock documentation.
137 # `null' if no haddock documentation was built.
144 # `null' if no haddock documentation was built.
138 haddockDir = if doHaddock' then "${docdir drv.doc}/html" else null;
145 haddockDir = if doHaddock' then "${docdir drv.doc}/html" else null;
146+ run = runCommand (fullName + "-run") {} ''
147+ ${toString component.testWrapper} ${drv}/${installedExe} | tee $out
148+ '';
139 };
149 };
140
150
141 meta = {
151 meta = {
@@ -177,7 +187,7 @@ stdenv.mkDerivation ({
177 prePatch = if (cabalFile != null)
187 prePatch = if (cabalFile != null)
178 then ''cat ${cabalFile} > ${package.identifier.name}.cabal''
188 then ''cat ${cabalFile} > ${package.identifier.name}.cabal''
179 else lib.optionalString (cabal-generator == "hpack") ''
189 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
181 '';
191 '';
182
192
183 configurePhase = ''
193 configurePhase = ''
@@ -267,6 +277,21 @@ stdenv.mkDerivation ({
267 '')
277 '')
268 # In case `setup copy` did not creat this
278 # In case `setup copy` did not creat this
269 + (lib.optionalString enableSeparateDataOutput "mkdir -p $data")
279 + (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+ '')
270 }
295 }
271 runHook postInstall
296 runHook postInstall
272 '';
297 '';
lib/default.nix+8
@@ -58,8 +58,16 @@ with haskellLib;
58
58
59 isLibrary = componentId: componentId.ctype == "lib";
59 isLibrary = componentId: componentId.ctype == "lib";
60 isAll = componentId: componentId.ctype == "all";
60 isAll = componentId: componentId.ctype == "all";
61+ isExe = componentId: componentId.ctype == "exe";
61 isTest = componentId: componentId.ctype == "test";
62 isTest = componentId: componentId.ctype == "test";
62 isBenchmark = componentId: componentId.ctype == "bench";
63 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;
63
71
64 # Was there a reference to the package source in the `cabal.project` or `stack.yaml` file.
72 # Was there a reference to the package source in the `cabal.project` or `stack.yaml` file.
65 # This is used to make the default `packages` list for `shellFor`.
73 # This is used to make the default `packages` list for `shellFor`.
test/cabal-22/default.nix+6−6
@@ -20,8 +20,8 @@ in
20 printf "size of executable $exe is $size. \n" >& 2
20 printf "size of executable $exe is $size. \n" >& 2
21
21
22 # fixme: run on target platform when cross-compiled
22 # fixme: run on target platform when cross-compiled
23− printf "checking whether executable runs... " >& 2
23+ printf "checking whether executable rans... " >& 2
24− "$exe"
24+ cat ${packages.project.components.exes.project.run}
25
25
26 printf "checking that executable is dynamically linked to system libraries... " >& 2
26 printf "checking that executable is dynamically linked to system libraries... " >& 2
27 '' + optionalString stdenv.isLinux ''
27 '' + optionalString stdenv.isLinux ''
@@ -46,11 +46,11 @@ in
46 '') + ''
46 '') + ''
47 touch $out
47 touch $out
48
48
49− printf "checking whether benchmark runs... " >& 2
49+ printf "checking whether benchmark ran... " >& 2
50− ${packages.project.components.benchmarks.project-bench}/*/project-bench
50+ cat ${packages.project.components.benchmarks.project-bench.run}
51
51
52− printf "checking whether tests run... " >& 2
52+ printf "checking whether tests ran... " >& 2
53− ${packages.project.components.tests.unit}/*/unit
53+ cat ${packages.project.components.tests.unit.run}
54 '';
54 '';
55
55
56 meta.platforms = platforms.all;
56 meta.platforms = platforms.all;
test/exe-only/default.nix+4−4
@@ -16,14 +16,14 @@ in
16 name = "exe-only-test";
16 name = "exe-only-test";
17
17
18 buildCommand = ''
18 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}"
20
20
21 size=$(command stat --format '%s' "$exe")
21 size=$(command stat --format '%s' "$exe")
22 printf "size of executable $exe is $size. \n" >& 2
22 printf "size of executable $exe is $size. \n" >& 2
23
23
24 # fixme: run on target platform when cross-compiled
24 # fixme: run on target platform when cross-compiled
25− printf "checking whether executable runs... " >& 2
25+ printf "checking whether executable ran... " >& 2
26− $exe
26+ cat ${packages.exe-only.components.exes.exe-only.run}
27 '' + (if stdenv.hostPlatform.isMusl then ''
27 '' + (if stdenv.hostPlatform.isMusl then ''
28 printf "checking that executable is statically linked... " >& 2
28 printf "checking that executable is statically linked... " >& 2
29 (ldd $exe 2>&1 || true) | grep -i "not a"
29 (ldd $exe 2>&1 || true) | grep -i "not a"
@@ -36,7 +36,7 @@ in
36 '') + ''
36 '') + ''
37
37
38 printf "Checking that \"all\" component has the programs... " >& 2
38 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}"
40 test -f "$all_exe"
40 test -f "$all_exe"
41 echo "$all_exe" >& 2
41 echo "$all_exe" >& 2
42
42
test/stack-simple/default.nix+6−19
@@ -1,4 +1,4 @@
1−{ stdenv, mkStackPkgSet }:
1+{ stdenv, pkgs, mkStackPkgSet }:
2
2
3with stdenv.lib;
3with stdenv.lib;
4
4
@@ -13,23 +13,10 @@ let
13
13
14 packages = pkgSet.config.hsPkgs;
14 packages = pkgSet.config.hsPkgs;
15
15
16−in
16+in pkgs.recurseIntoAttrs {
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"
17+ stack-simple-exe = packages.stack-simple.components.exes.stack-simple-exe.run // {
22−
23− printf "checking whether executable runs... " >& 2
24− $exe
25−
26− touch $out
27− '';
28−
29− meta.platforms = platforms.all;
30−
31− passthru = {
32 # Attributes used for debugging with nix repl
18 # Attributes used for debugging with nix repl
33 inherit pkgSet packages;
19 inherit pkgSet packages;
34− };
20+ };
21+ stack-simple-test = packages.stack-simple.components.tests.stack-simple-test.run;
35− }
22+}