Skip to content

Commit 47a769b

Browse files
committed
WIP 2
1 parent 2bbb9e4 commit 47a769b

File tree

1 file changed

+69
-48
lines changed

1 file changed

+69
-48
lines changed

lib/cover.nix

Lines changed: 69 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,82 +12,103 @@ let
1212

1313
identifier = name + "-" + version;
1414

15+
toBashArray = arr: "(" + (lib.concatStringsSep " " arr) + ")";
16+
1517
in pkgs.runCommand (identifier + "-coverage-report")
1618
{ buildInputs = (with pkgs; [ ghc ]); }
1719
''
18-
findMixDir() {
19-
find $1 -iwholename "*/hpc/vanilla/mix" -exec find {} -maxdepth 1 -type d -iwholename "*/mix/*" \; -quit
20+
function markup() {
21+
local srcDir=$1
22+
local -n mixDs=$2
23+
local -n excludedModules=$3
24+
local destDir=$4
25+
local tixFile=$5
26+
27+
local hpcMarkupCmd=("hpc" "markup" "--srcdir=$srcDir" "--destdir=$destDir")
28+
for mixDir in "''${mixDs[@]}"; do
29+
hpcMarkupCmd+=("--hpcdir=$mixDir")
30+
done
31+
32+
for module in "''${excludedModules[@]}"; do
33+
hpcMarkupCmd+=("--exclude=$module")
34+
done
35+
36+
hpcMarkupCmd+=("$tixFile")
37+
38+
echo "''${hpcMarkupCmd[@]}"
39+
eval "''${hpcMarkupCmd[@]}"
40+
}
41+
42+
function sumTix() {
43+
local -n excludedModules=$1
44+
local -n tixFs=$2
45+
local outFile="$3"
46+
47+
echo "EXCLUDED ''${excludedModules[@]}"
48+
echo "EXCLUDED ''${tixFs[@]}"
49+
local hpcSumCmd=("hpc" "sum" "--union" "--output=$outFile")
50+
51+
for module in "''${excludedModules[@]}"; do
52+
hpcSumCmd+=("--exclude=$module")
53+
done
54+
55+
for tixFile in "''${tixFs[@]}"; do
56+
hpcSumCmd+=("$tixFile")
57+
done
58+
59+
echo "''${hpcSumCmd[@]}"
60+
eval "''${hpcSumCmd[@]}"
2061
}
2162
2263
mkdir -p $out/share/hpc/vanilla/mix/${identifier}
2364
mkdir -p $out/share/hpc/vanilla/tix/${identifier}
2465
mkdir -p $out/share/hpc/vanilla/html/${identifier}
2566
2667
local src=${library.src.outPath}
27-
28-
hpcMarkupCmdBase=("hpc" "markup" "--srcdir=$src")
29-
for drv in ${lib.concatStringsSep " " ([ library ] ++ testsAsList)}; do
30-
# Copy over mix files
31-
local mixDir=$(findMixDir $drv)
68+
local mixDirs=${toBashArray (map (drv: "${drv}/share/hpc/vanilla/mix") ([library] ++ testsAsList))}
69+
# Exclude test modules from tix file. The Main module is
70+
# hard-coded here because the Main module is not listed in
71+
# "$test.config.modules" (the plan.nix) but must be excluded.
72+
# Note that the name of the Main module file does not matter. So
73+
# a line in your cabal file such as:
74+
# main-is: Spec.hs
75+
# still generates a "Main.mix" file with the contents:
76+
# Mix "Spec.hs" ...
77+
# Hence we can hardcode the name "Main" here.
78+
local testModules=${toBashArray (["Main"] ++ (lib.foldl' (acc: test: acc ++ test.config.modules) [] testsAsList))}
79+
local totalTixFile="$out/share/hpc/vanilla/tix/${identifier}/${identifier}.tix"
80+
local markupOutDir="$out/share/hpc/vanilla/html/${identifier}"
81+
82+
echo "''${testModules[@]}"
83+
84+
# Copy over mix files verbatim
85+
for dir in $mixDirs; do
3286
if [ ! -z "$mixDir" ]; then
3387
cp -R "$mixDir" $out/share/hpc/vanilla/mix/
34-
35-
hpcMarkupCmdBase+=("--hpcdir=$mixDir")
3688
fi
3789
done
3890
3991
${lib.optionalString ((builtins.length testsAsList) > 0) ''
40-
# Exclude test modules from tix file. The Main module is
41-
# hard-coded here because the Main module is not listed in
42-
# "$test.config.modules" (the plan.nix) but must be excluded.
43-
# Note that the name of the Main module file does not matter. So
44-
# a line in your cabal file such as:
45-
# main-is: Spec.hs
46-
# still generates a "Main.mix" file with the contents:
47-
# Mix "Spec.hs" ...
48-
# Hence we can hardcode the name "Main" here.
49-
excludedModules=('Main')
50-
testModules="${with lib; concatStringsSep " " (foldl' (acc: test: acc ++ test.config.modules) [] testsAsList)}"
51-
for module in $testModules; do
52-
excludedModules+=("$module")
53-
done
54-
55-
hpcSumCmdBase=("hpc" "sum" "--union" "--output=$out/share/hpc/vanilla/tix/${identifier}/${identifier}.tix")
56-
for exclude in ''${excludedModules[@]}; do
57-
hpcSumCmdBase+=("--exclude=$exclude")
58-
hpcMarkupCmdBase+=("--exclude=$exclude")
59-
done
60-
61-
hpcMarkupCmdAll=("''${hpcMarkupCmdBase[@]}" "--destdir=$out/share/hpc/vanilla/html/${identifier}")
62-
63-
hpcSumCmd=()
92+
local tixFiles=()
6493
${lib.concatStringsSep "\n" (builtins.map (check: ''
6594
if [ -d "${check}/share/hpc/vanilla/tix" ]; then
6695
pushd ${check}/share/hpc/vanilla/tix
6796
68-
tixFileRel="$(find . -iwholename "*.tix" -type f -print -quit)"
97+
tixFile="$(find . -iwholename "*.tix" -type f -print -quit)"
6998
70-
mkdir -p $out/share/hpc/vanilla/tix/$(dirname $tixFileRel)
71-
cp $tixFileRel $out/share/hpc/vanilla/tix/$tixFileRel
99+
cp "$tixFile" $out/share/hpc/vanilla/tix/
72100
73-
# Output tix file with test modules excluded
74-
hpcSumCmd+=("$out/share/hpc/vanilla/tix/$tixFileRel")
101+
tixFiles+=("${check}/share/hpc/vanilla/tix/$tixFile")
75102
76103
popd
77104
fi
78105
'') checks)
79106
}
80107
81-
if (( "''${#hpcSumCmd[@]}" > 0 )); then
82-
hpcMarkupCmdAll+=("$out/share/hpc/tix/${identifier}/${identifier}.tix")
83-
84-
hpcSumCmd=("''${hpcSumCmdBase[@]}" "''${hpcSumCmd[@]}")
85-
echo "''${hpcSumCmd[@]}"
86-
eval "''${hpcSumCmd[@]}"
87-
88-
hpcMarkupCmdAll+=("$out/share/hpc/vanilla/tix/${identifier}/${identifier}.tix")
89-
echo "''${hpcMarkupCmdAll[@]}"
90-
eval "''${hpcMarkupCmdAll[@]}"
108+
if (( "''${#tixFiles[@]}" > 0 )); then
109+
sumTix testModules tixFiles "$totalTixFile"
110+
111+
markup "$src" mixDirs testModules "$markupOutDir" "$totalTixFile"
91112
fi
92113
''}
93114
''

0 commit comments

Comments
 (0)