Skip to content

Patch HPC for better compatibility with large projects #1464

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

Closed
wants to merge 2 commits into from

Conversation

peterbecich
Copy link
Contributor

@peterbecich peterbecich commented May 9, 2022

This is a patch to HPC authored by @purefn . I've received permission from him to attempt to upstream this patch.

Paraphrasing @purefn ,
HPC currently requires all inputs as command line arguments.

Usage: hpc report [OPTION] .. <TIX_FILE> [<MODULE> [<MODULE> ..]]
Output textual report about program coverage
Options:
    --per-module                  show module level detail
    --decl-list                   show unused decls
    --exclude=[PACKAGE:][MODULE]  exclude MODULE and/or PACKAGE
    --include=[PACKAGE:][MODULE]  include MODULE and/or PACKAGE
    --srcdir=DIR                  path to source directory of .hs files
                                  multi-use of srcdir possible
    --hpcdir=DIR                  append sub-directory that contains .mix files
                                  default .hpc [rarely used]
    --reset-hpcdirs               empty the list of hpcdir's
                                  [rarely used]
    --xml-output                  show output in XML
    --verbosity=[0-2]             verbosity level, 0-2
                                  default 1

With large projects this can result in an argument list too long error: NixOS/nix#5593
This patch to HPC adds the arguments srcdirs-from=<FILE>, hpcdirs-from=<FILE>, and includes-from=<FILE>.
Then, haskell.nix passes these inputs as files rather than as direct command line arguments.

@purefn notes this improvement to HPC ought to be upstreamed to HPC directly: https://gitlab.haskell.org/ghc/packages/hpc
However, would this result in the change being available to old GHC versions such as 8.10.7?


Here are two tests of this patch on public projects:

Pandoc
peterbecich/pandoc@93bc858
This HTML report can be generated with: nix build -f default.nix projectCoverageReport
No other arguments are needed because they are here: https://github.com/peterbecich/pandoc/blob/93bc85844c539a81b3a31eb8e76f7efb0d5aac63/default.nix#L13-L20
Screenshot 2022-05-08 at 23-43-01 Screenshot

more tests TODO...

I do not have a test which exhibits the error without the patch. This is because projects sufficiently large to cause unpatched HPC to fail also hit other instances of the argument list too long error, unrelated to HPC: #1297
So, the best I can do is to show that the patch is not a regression.

@michaelpj
Copy link
Collaborator

I think this needs to be upstreamed. I would guess that it would be pretty safe to make hpc reinstallable, so even if this patch is only available in recent versions of hpc, it'll probably be usable by people on older versions of GHC.

@michaelpj
Copy link
Collaborator

We already have way too many GHC patches, if we can possibly avoid more that would be great...

@peterbecich
Copy link
Contributor Author

peterbecich commented May 10, 2022

Thanks, I will try to upstream the change. I see now it applies to hpc-bin (https://gitlab.haskell.org/ghc/ghc/-/tree/master/utils/hpc); not hpc (https://gitlab.haskell.org/ghc/packages/hpc)

Because this change applies to the GHC source tree, not the HPC source tree, does that mean it will only take effect on future GHCs, unless explicitly back-ported?

@peterbecich
Copy link
Contributor Author

Here is the upstream change: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/8194 I should probably provide a test to show it works without haskell.nix before asking for review.
If/when it is merged, I will open a new PR to make the corresponding changes to haskell.nix. Thanks again

@michaelpj
Copy link
Collaborator

That looks super, thanks.

Like I said, I think we might be able to get away with just:

  • A new release of HPC on Hackage
  • Letting HPC be re-installed so that users can just pick up the new Hackage version rather than taking the one bundled with their GHC.

ghc-mirror-bot pushed a commit to ghc/ghc that referenced this pull request Aug 18, 2022
This is an improvement to HPC authored by Richard Wallace
(https://github.com/purefn) and myself. I have received permission from
him to attempt to upstream it. This improvement was originally
implemented as a patch to HPC via input-output-hk/haskell.nix:
input-output-hk/haskell.nix#1464

Paraphrasing Richard, HPC currently requires all inputs as command line arguments.
With large projects this can result in an argument list too long error.
I have only seen this error in Nix, but I assume it can occur is a plain Unix environment.

This MR adds the standard response file syntax support to HPC. For
example you can now pass a file to the command line which contains the
arguments.

```
hpc @response_file_1 @response_file_2 ...

The contents of a Response File must have this format:
COMMAND ...

example:
report my_library.tix --include=ModuleA --include=ModuleB
```

Updates hpc submodule

Co-authored-by:  Richard Wallace <[email protected]>

Fixes #22050
@BinderDavid
Copy link

That looks super, thanks.

Like I said, I think we might be able to get away with just:

* A new release of HPC on Hackage

* Letting HPC be re-installed so that users can just pick up the new Hackage version rather than taking the one bundled with their GHC.

@michaelpj Just to let you know that HPC has a new maintainership team now, and we are working on this. I just created a ticket for a reinstallable HPC here: https://gitlab.haskell.org/hpc/hpc-bin/-/issues/13 If you have any requirements on the HPC binary, feel free to chime in with feature requests :)

@michaelpj
Copy link
Collaborator

Great! We may well have such in future, should I tag you in that case?

@BinderDavid
Copy link

Great! We may well have such in future, should I tag you in that case?

Yes, feel free to tag me :)

Tritlo pushed a commit to Tritlo/hpc-bin that referenced this pull request Jul 12, 2023
This is an improvement to HPC authored by Richard Wallace
(https://github.com/purefn) and myself. I have received permission from
him to attempt to upstream it. This improvement was originally
implemented as a patch to HPC via input-output-hk/haskell.nix:
input-output-hk/haskell.nix#1464

Paraphrasing Richard, HPC currently requires all inputs as command line arguments.
With large projects this can result in an argument list too long error.
I have only seen this error in Nix, but I assume it can occur is a plain Unix environment.

This MR adds the standard response file syntax support to HPC. For
example you can now pass a file to the command line which contains the
arguments.

```
hpc @response_file_1 @response_file_2 ...

The contents of a Response File must have this format:
COMMAND ...

example:
report my_library.tix --include=ModuleA --include=ModuleB
```

Updates hpc submodule

Co-authored-by:  Richard Wallace <[email protected]>

Fixes #22050
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants