cabal icon indicating copy to clipboard operation
cabal copied to clipboard

Only use cpphs for .cpphs files

Open vmchale opened this issue 3 years ago • 15 comments

This addresses https://github.com/haskell/cabal/issues/4278. I think mboes is correct and it should simply fail to process .cpphs files if cpphs is not available, especially since new-build and build-tool-depends: cpphs:cpphs

Tested by building the exe and running it locally.

vmchale avatar Aug 15 '22 22:08 vmchale

Would there be a way to cheaply test this in our test suite? Is it blocking you and would a backport to 3.8 potentially help?

Mikolaj avatar Aug 16 '22 06:08 Mikolaj

@Mikolaj I'd say a backpack to 3.8 would be useful, yes! GHC 9.4.1 has a bug in its preprocessor.

vmchale avatar Aug 16 '22 11:08 vmchale

@Mikolaj I'd say a backpack to 3.8 would be useful, yes! GHC 9.4.1 has a bug in its preprocessor.

3.8 is the Cabal version shipped with 9.4.1. Backport to 3.6 is not likely. An option is include this PR only in 3.10 that is not yet even planned, but I gather we'd want to avoid that.

Mikolaj avatar Aug 16 '22 11:08 Mikolaj

Let me rebase to include a workaround to our CI instability and fix the tests.

Mikolaj avatar Aug 16 '22 22:08 Mikolaj

@mergify rebase

Mikolaj avatar Aug 16 '22 22:08 Mikolaj

rebase

✅ Branch has been successfully rebased

mergify[bot] avatar Aug 16 '22 22:08 mergify[bot]

Wow: it just said that it was me who pushed the rebased committs?..

ulysses4ever avatar Aug 16 '22 22:08 ulysses4ever

BTW, we are ready to assist with modifying an existing test or writing a new one.

Mikolaj avatar Sep 15 '22 15:09 Mikolaj

Has anyone thought about what would a test amount to? For one (it seems to me), it'd require cpphs installed in the test environment. Does anyone know of a way to get a Hackage-hosted tool installed in the test environment for one test only? From what I know, I think it's only possible to install stuff globally for all tests. Do we want that?

ulysses4ever avatar Sep 21 '22 14:09 ulysses4ever

I don't know. Perhaps the new feature for specifying an exe build dependency would be enough (forgot how it's called). I mean, perhaps we could add cpphs as such dependency to the .cabal file of the single test in question.?

Mikolaj avatar Sep 22 '22 12:09 Mikolaj

@Mikolaj my impression (correct me if I'm wrong) was that those cabal files don't have access to Hackage; see FAQ for the testsuite, Q#3.

ulysses4ever avatar Sep 22 '22 14:09 ulysses4ever

Right, I now remember a discussion when somebody wanted the access to check messages from cabal update. How big is cpphs? Would it be cached?

Mikolaj avatar Sep 22 '22 14:09 Mikolaj

It's very small, both in terms of dependency footprint and in terms of code size. On my laptop it took several seconds to build. And yes, it'd probably be in the cache all the time.

It's not the build time that I'm concerned about, but just expanding the CI script, and the precedent of doing that for a single test. But maybe it's not worth worrying.

ulysses4ever avatar Sep 22 '22 14:09 ulysses4ever

Let's expand this one last time. :)

Mikolaj avatar Sep 22 '22 15:09 Mikolaj

(Apologies if I'm talking out of turn here -- just ignore me. By some cosmic coincidence -- spotted by @vmchale -- a few days ago I found cpphs answered a specific need, and for which off-the-shelf cpp wasn't helping.)

Has anyone thought about what would a test amount to?

cpphs is more friendly for Haskell code than cpp -- that is, if you tell it the right way to do things. I wrote up some notes for the cpphs options that might be helpful for a tester.

  • A good test would be to expand a multi-line macro into a multi-line Haskell decl with --layout, making sure it indents properly.
  • Another good test would be expansions with -XMagicHash; and possibly defining an operator (##). Hashes have special significance within cpp, which make them difficult to use in your Haskell. If you want a test to break something, try those same tests with --hashes set.
  • By default, cpphs produces a header line in the output starting #line .... I guess GHC won't know what to do with that(?) Option --noline suppresses it.
  • As my note says, cpphs's style for calling macros is myMacro(someArg) -- needs the parens round the arg, not Haskell style myMacro someArg -- whitespace between them. What's bad is that if you use Haskell style, cpphs doesn't shout at you, it'll pass on myMacro someArg into the generated source, where presumably myMacro is not defined. I would include a expected fail test for this, to make sure GHC handles it gracefully.

AntC2 avatar Sep 23 '22 11:09 AntC2

@AntC2: thank you for the helpful ideas.

@vmchale: could we assist you in any way?

Mikolaj avatar Oct 19 '22 18:10 Mikolaj

Marking this PR as draft :slightly_smiling_face:

Kleidukos avatar May 17 '23 06:05 Kleidukos