1{ stdenv, lib, haskellLib, pkgs }:
3# Name of the coverage report, which should be unique
5# Library to check coverage of
7# List of check derivations that generate coverage
9# List of other libraries to include in the coverage report. The
10# default value if just the derivation provided as the `library`
11# argument. Use a larger list of libraries if you would like the tests
12# of one local package to generate coverage for another.
13, mixLibraries ? [library]
14# hack for project-less projects
15, ghc ? library.project.pkg-set.config.ghc.package
19 toBashArray = arr: "(" + (lib.concatStringsSep " " arr) + ")";
21 mixDir = l: "${l}/share/hpc/vanilla/mix/${l.identifier.name}-${l.identifier.version}";
22 mixDirs = map mixDir mixLibraries;
24 srcDirs = map (l: l.src.outPath) mixLibraries;
26in pkgs.runCommand (name + "-coverage-report")
27 ({nativeBuildInputs = [ (ghc.buildGHC or ghc) pkgs.buildPackages.zip ];
29 inherit name library checks;
31 # HPC will fail if the Haskell file contains non-ASCII characters,
32 # unless our locale is set correctly. This has been fixed, but we
33 # don't know what version of HPC we will be using, hence we should
34 # always use the workaround.
35 # https://gitlab.haskell.org/ghc/ghc/-/issues/17073
37 LC_ALL = "en_US.UTF-8";
38 } // lib.optionalAttrs (stdenv.buildPlatform.libc == "glibc") {
39 LOCALE_ARCHIVE = "${pkgs.buildPackages.glibcLocales}/lib/locale/locale-archive";
45 local -n includedModules=$3
49 local hpcMarkupCmd=("hpc" "markup" "--destdir=$destDir")
50 for srcDir in "''${srcDs[@]}"; do
51 hpcMarkupCmd+=("--srcdir=$srcDir")
54 for mixDir in "''${mixDs[@]}"; do
55 hpcMarkupCmd+=("--hpcdir=$mixDir")
58 for module in "''${includedModules[@]}"; do
59 hpcMarkupCmd+=("--include=$module")
62 hpcMarkupCmd+=("$tixFile")
64 echo "''${hpcMarkupCmd[@]}"
65 eval "''${hpcMarkupCmd[@]}"
69 local -n includedModules=$1
73 local hpcSumCmd=("hpc" "sum" "--union" "--output=$outFile")
75 for module in "''${includedModules[@]}"; do
76 hpcSumCmd+=("--include=$module")
79 for tixFile in "''${tixFs[@]}"; do
80 hpcSumCmd+=("$tixFile")
83 echo "''${hpcSumCmd[@]}"
84 eval "''${hpcSumCmd[@]}"
87 function findModules() {
92 mapfile -d $'\0' $1 < <(find ./ -type f \
93 -wholename "$pattern" -not -name "Paths*" \
94 -exec basename {} \; \
100 local mixDirs=${toBashArray mixDirs}
102 mkdir -p $out/nix-support
103 mkdir -p $out/share/hpc/vanilla/mix/${name}
104 mkdir -p $out/share/hpc/vanilla/tix/${name}
105 mkdir -p $out/share/hpc/vanilla/html/${name}
107 # Copy over mix files verbatim
108 for dir in "''${mixDirs[@]}"; do
109 if [ -d "$dir" ]; then
110 cp -R "$dir"/* $out/share/hpc/vanilla/mix/${name}
114 local srcDirs=${toBashArray srcDirs}
115 local allMixModules=()
116 local pkgMixModules=()
118 # The behaviour of stack coverage reports is to provide tix files
119 # that include coverage information for every local package, but
120 # to provide HTML reports that only include coverage info for the
121 # current package. We emulate the same behaviour here. If the user
122 # includes all local packages in the mix libraries argument, they
123 # will get a coverage report very similar to stack.
126 findModules allMixModules "$out/share/hpc/vanilla/mix/${name}" "*.mix"
127 # Only mix modules corresponding to this package
128 findModules pkgMixModules "$out/share/hpc/vanilla/mix/${name}" "*${name}*/*.mix"
132 ${lib.concatStringsSep "\n" (builtins.map (check: ''
133 if [ -d "${check}/share/hpc/vanilla/tix" ]; then
134 pushd ${check}/share/hpc/vanilla/tix
136 tixFile="$(find . -iwholename "*.tix" -type f -print -quit)"
137 local newTixFile=$out/share/hpc/vanilla/tix/${name}/"$tixFile"
139 mkdir -p "$(dirname $newTixFile)"
140 # Copy over the tix file verbatim
141 cp "$tixFile" "$newTixFile"
143 # Add the tix file to our list
144 tixFiles+=("$newTixFile")
146 # Create a coverage report for *just that test*
147 markup srcDirs mixDirs pkgMixModules "$out/share/hpc/vanilla/html/${name}/${check.exeName}/" "$newTixFile"
154 # Sum tix files to create a tix file with all relevant tix
155 # information and markup a HTML report from this info.
156 if (( "''${#tixFiles[@]}" > 0 )); then
157 local sumTixFile="$out/share/hpc/vanilla/tix/${name}/${name}.tix"
158 local markupOutDir="$out/share/hpc/vanilla/html/${name}"
160 # Sum all of our tix file, including modules from any local package
161 sumTix allMixModules tixFiles "$sumTixFile"
163 # Markup a HTML report, included modules from only this package
164 markup srcDirs mixDirs pkgMixModules "$markupOutDir" "$sumTixFile"
166 # Provide a HTML zipfile and Hydra links
167 ( cd "$markupOutDir" ; zip -r $out/share/hpc/vanilla/${name}-html.zip . )
168 echo "report coverage $markupOutDir/hpc_index.html" >> $out/nix-support/hydra-build-products
169 echo "file zip $out/share/hpc/vanilla/${name}-html.zip" >> $out/nix-support/hydra-build-products
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list