@@ -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 '';