|
12 | 12 |
|
13 | 13 | identifier = name + "-" + version;
|
14 | 14 |
|
| 15 | + toBashArray = arr: "(" + (lib.concatStringsSep " " arr) + ")"; |
| 16 | + |
15 | 17 | in pkgs.runCommand (identifier + "-coverage-report")
|
16 | 18 | { buildInputs = (with pkgs; [ ghc ]); }
|
17 | 19 | ''
|
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[@]}" |
20 | 61 | }
|
21 | 62 |
|
22 | 63 | mkdir -p $out/share/hpc/vanilla/mix/${identifier}
|
23 | 64 | mkdir -p $out/share/hpc/vanilla/tix/${identifier}
|
24 | 65 | mkdir -p $out/share/hpc/vanilla/html/${identifier}
|
25 | 66 |
|
26 | 67 | 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 |
32 | 86 | if [ ! -z "$mixDir" ]; then
|
33 | 87 | cp -R "$mixDir" $out/share/hpc/vanilla/mix/
|
34 |
| -
|
35 |
| - hpcMarkupCmdBase+=("--hpcdir=$mixDir") |
36 | 88 | fi
|
37 | 89 | done
|
38 | 90 |
|
39 | 91 | ${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=() |
64 | 93 | ${lib.concatStringsSep "\n" (builtins.map (check: ''
|
65 | 94 | if [ -d "${check}/share/hpc/vanilla/tix" ]; then
|
66 | 95 | pushd ${check}/share/hpc/vanilla/tix
|
67 | 96 |
|
68 |
| - tixFileRel="$(find . -iwholename "*.tix" -type f -print -quit)" |
| 97 | + tixFile="$(find . -iwholename "*.tix" -type f -print -quit)" |
69 | 98 |
|
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/ |
72 | 100 |
|
73 |
| - # Output tix file with test modules excluded |
74 |
| - hpcSumCmd+=("$out/share/hpc/vanilla/tix/$tixFileRel") |
| 101 | + tixFiles+=("${check}/share/hpc/vanilla/tix/$tixFile") |
75 | 102 |
|
76 | 103 | popd
|
77 | 104 | fi
|
78 | 105 | '') checks)
|
79 | 106 | }
|
80 | 107 |
|
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" |
91 | 112 | fi
|
92 | 113 | ''}
|
93 | 114 | ''
|
0 commit comments