@@ -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 }:
3{ componentId
3{ componentId
@@ -117,6 +117,13 @@ let
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
126+ installedExe = "${installedExeDir}/${componentId.cname}${exeExt}";
121in stdenv.lib.fix (drv:
128in stdenv.lib.fix (drv:
@@ -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
@@ -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
183 configurePhase = ''
193 configurePhase = ''
@@ -267,6 +277,21 @@ stdenv.mkDerivation ({
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} \;
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} \;
271 runHook postInstall
296 runHook postInstall