Skip to content

Fix hpc for cross-compiled builds #862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions lib/cover-project.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ let
</html>
'';

ghc =
if (builtins.length coverageReports) > 0
then (builtins.head coverageReports).library.project.pkg-set.config.ghc.package or pkgs.ghc
else pkgs.ghc;

libs = map (r: r.library) coverageReports;

projectLibs = map (pkg: pkg.components.library) (lib.attrValues (haskellLib.selectProjectPackages ((lib.head libs).project.hsPkgs)));
Expand All @@ -60,21 +55,22 @@ let
srcDirs = map (l: l.src.outPath) (projectLibs);

in pkgs.runCommand "project-coverage-report"
({ buildInputs = [ghc];
LANG = "en_US.UTF-8";
({ LANG = "en_US.UTF-8";
LC_ALL = "en_US.UTF-8";
} // lib.optionalAttrs (stdenv.buildPlatform.libc == "glibc") {
LOCALE_ARCHIVE = "${pkgs.buildPackages.glibcLocales}/lib/locale/locale-archive";
})
''
local hpc=${pkgs.buildPackages.haskellPackages.ghc}/bin/hpc

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this work?

nativeBuildInputs = [(ghc.buildGHC or ghc)];

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fundamental issue I believe is that our cross compilers (and musl is considered on) do not ship hpc, thus while you'd get a valid expression for ghc, you have no guarantee it has hpc?

On the other, hand your suggesting is to always use the buildGHC, which can never realistically be a cross compiler by default. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure what's the best way to do it.
This way works for me at the moment.
But one issue is that the ghc version could be different to what's used by the project.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rvl right, that's what @hamishmack's change would address. We mostly use the same ghc version to bootstrap the cross compilers. But it might not for regular compiers. Ahh this is frustrating.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK thanks, I have changed it as @hamishmack suggested, and it seems to work.

function markup() {
local -n srcDs=$1
local -n mixDs=$2
local -n includedModules=$3
local destDir=$4
local tixFile=$5

local hpcMarkupCmd=("hpc" "markup" "--destdir=$destDir")
local hpcMarkupCmd=("$hpc" "markup" "--destdir=$destDir")
for srcDir in "''${srcDs[@]}"; do
hpcMarkupCmd+=("--srcdir=$srcDir")
done
Expand Down Expand Up @@ -106,6 +102,7 @@ in pkgs.runCommand "project-coverage-report"
popd
}

mkdir -p $out/nix-support
mkdir -p $out/share/hpc/vanilla/tix/all
mkdir -p $out/share/hpc/vanilla/mix/
mkdir -p $out/share/hpc/vanilla/html/
Expand All @@ -129,13 +126,14 @@ in pkgs.runCommand "project-coverage-report"
if [ ''${#tixFiles[@]} -ne 0 ]; then
# Create tix file with test run information for all packages
tixFile="$out/share/hpc/vanilla/tix/all/all.tix"
hpcSumCmd=("hpc" "sum" "--union" "--output=$tixFile")
hpcSumCmd=("$hpc" "sum" "--union" "--output=$tixFile")
hpcSumCmd+=("''${tixFiles[@]}")
echo "''${hpcSumCmd[@]}"
eval "''${hpcSumCmd[@]}"

# Markup a HTML coverage report for the entire project
cp ${projectIndexHtml} $out/share/hpc/vanilla/html/index.html
echo "report coverage-per-package $out/share/hpc/vanilla/html/index.html" >> $out/nix-support/hydra-build-products

local markupOutDir="$out/share/hpc/vanilla/html/all"
local srcDirs=${toBashArray srcDirs}
Expand All @@ -146,5 +144,6 @@ in pkgs.runCommand "project-coverage-report"
findModules allMixModules "$out/share/hpc/vanilla/mix/" "*.mix"

markup srcDirs mixDirs allMixModules "$markupOutDir" "$tixFile"
echo "report coverage $markupOutDir/hpc_index.html" >> $out/nix-support/hydra-build-products
fi
''
14 changes: 8 additions & 6 deletions lib/cover.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# argument. Use a larger list of libraries if you would like the tests
# of one local package to generate coverage for another.
, mixLibraries ? [library]
# hack for project-less projects
, ghc ? library.project.pkg-set.config.ghc.package
}:

let
Expand All @@ -24,8 +22,7 @@ let
srcDirs = map (l: l.src.outPath) mixLibraries;

in pkgs.runCommand (name + "-coverage-report")
({ buildInputs = [ ghc ];
passthru = {
({ passthru = {
inherit name library checks;
};
# HPC will fail if the Haskell file contains non-ASCII characters,
Expand All @@ -39,14 +36,16 @@ in pkgs.runCommand (name + "-coverage-report")
LOCALE_ARCHIVE = "${pkgs.buildPackages.glibcLocales}/lib/locale/locale-archive";
})
''
local hpc=${pkgs.buildPackages.haskellPackages.ghc}/bin/hpc

function markup() {
local -n srcDs=$1
local -n mixDs=$2
local -n includedModules=$3
local destDir=$4
local tixFile=$5

local hpcMarkupCmd=("hpc" "markup" "--destdir=$destDir")
local hpcMarkupCmd=("$hpc" "markup" "--destdir=$destDir")
for srcDir in "''${srcDs[@]}"; do
hpcMarkupCmd+=("--srcdir=$srcDir")
done
Expand All @@ -70,7 +69,7 @@ in pkgs.runCommand (name + "-coverage-report")
local -n tixFs=$2
local outFile="$3"

local hpcSumCmd=("hpc" "sum" "--union" "--output=$outFile")
local hpcSumCmd=("$hpc" "sum" "--union" "--output=$outFile")

for module in "''${includedModules[@]}"; do
hpcSumCmd+=("--include=$module")
Expand Down Expand Up @@ -99,6 +98,7 @@ in pkgs.runCommand (name + "-coverage-report")

local mixDirs=${toBashArray mixDirs}

mkdir -p $out/nix-support
mkdir -p $out/share/hpc/vanilla/mix/${name}
mkdir -p $out/share/hpc/vanilla/tix/${name}
mkdir -p $out/share/hpc/vanilla/html/${name}
Expand Down Expand Up @@ -161,5 +161,7 @@ in pkgs.runCommand (name + "-coverage-report")

# Markup a HTML report, included modules from only this package
markup srcDirs mixDirs pkgMixModules "$markupOutDir" "$sumTixFile"

echo "report coverage $markupOutDir/hpc_index.html" >> $out/nix-support/hydra-build-products
fi
''