Skip to content

Commit

Permalink
haskell: add support for Haskell Program Coverage (HPC) to the generi…
Browse files Browse the repository at this point in the history
…c builder

A function is added to enable the generation of a HPC report. For example:

  pkgs.haskell.lib.doCoverage drv

will create a HPC report of the Haskell package drv in the directory:

  $out/share/hpc

Closes https://github.com/NixOS/nixpkgs/pull/22797/files.
  • Loading branch information
basvandijk authored and peti committed Feb 15, 2017
1 parent 35b2159 commit 8a92870
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkgs/development/haskell-modules/generic-builder.nix
Expand Up @@ -32,6 +32,7 @@
, jailbreak ? false
, license
, maintainers ? []
, doCoverage ? false
# TODO Do we care about haddock when cross-compiling?
, doHaddock ? !isCross && (!stdenv.isDarwin || stdenv.lib.versionAtLeast ghc.version "7.8")
, passthru ? {}
Expand Down Expand Up @@ -59,7 +60,7 @@ assert enableSplitObjs == null;

let

inherit (stdenv.lib) optional optionals optionalString versionOlder
inherit (stdenv.lib) optional optionals optionalString versionOlder versionAtLeast
concatStringsSep enableFeature optionalAttrs toUpper;

isGhcjs = ghc.isGhcjs or false;
Expand Down Expand Up @@ -111,10 +112,11 @@ let
(optionalString (enableSharedExecutables && stdenv.isDarwin) "--ghc-option=-optl=-Wl,-headerpad_max_install_names")
(optionalString enableParallelBuilding "--ghc-option=-j$NIX_BUILD_CORES")
(optionalString useCpphs "--with-cpphs=${cpphs}/bin/cpphs --ghc-options=-cpp --ghc-options=-pgmP${cpphs}/bin/cpphs --ghc-options=-optP--cpp")
(enableFeature (enableDeadCodeElimination && (stdenv.lib.versionAtLeast "8.0.1" ghc.version)) "split-objs")
(enableFeature (enableDeadCodeElimination && (versionAtLeast "8.0.1" ghc.version)) "split-objs")
(enableFeature enableLibraryProfiling "library-profiling")
(enableFeature enableExecutableProfiling (if versionOlder ghc.version "8" then "executable-profiling" else "profiling"))
(enableFeature enableSharedLibraries "shared")
(optionalString (versionAtLeast ghc.version "7.10") (enableFeature doCoverage "coverage"))
(optionalString (isGhcjs || versionOlder "7" ghc.version) (enableFeature enableStaticLibraries "library-vanilla"))
(optionalString (isGhcjs || versionOlder "7.4" ghc.version) (enableFeature enableSharedExecutables "executable-dynamic"))
(optionalString (isGhcjs || versionOlder "7" ghc.version) (enableFeature doCheck "tests"))
Expand Down Expand Up @@ -286,7 +288,7 @@ stdenv.mkDerivation ({
local pkgId=$( ${gnused}/bin/sed -n -e 's|^id: ||p' $packageConfFile )
mv $packageConfFile $packageConfDir/$pkgId.conf
''}
${optionalString doCoverage "mkdir -p $out/share && cp -r dist/hpc $out/share"}
${optionalString (enableSharedExecutables && isExecutable && !isGhcjs && stdenv.isDarwin && stdenv.lib.versionOlder ghc.version "7.10") ''
for exe in "$out/bin/"* ; do
install_name_tool -add_rpath "$out/lib/ghc-${ghc.version}/${pname}-${version}" "$exe"
Expand Down
3 changes: 3 additions & 0 deletions pkgs/development/haskell-modules/lib.nix
Expand Up @@ -8,6 +8,9 @@ rec {
overrideScope = scope: overrideCabal (drv.overrideScope scope) f;
};

doCoverage = drv: overrideCabal drv (drv: { doCoverage = true; });
dontCoverage = drv: overrideCabal drv (drv: { doCoverage = false; });

doHaddock = drv: overrideCabal drv (drv: { doHaddock = true; });
dontHaddock = drv: overrideCabal drv (drv: { doHaddock = false; });

Expand Down

0 comments on commit 8a92870

Please sign in to comment.