Repository navigation
Description
So here are some notes on how ghc-mod interacts with Cabal to get a discussion going on how we can do better for cabal new-build. (As discussed with @dcoutts)
Currently ghc-mod interacts with cabal though a library/program wrapper called cabal-helper. ghc-mod uses cabal-helper's library which compiles a small program at runtime which uses the Cabal library internally.
To ensure version compatibility this helper program is compiled against the exact same version of Cabal as was used to generate the configuration state (dist/setup-config) we're reading.
We only really have to do this runtime-compilation dance because ghc-mod doesn't control which version of cabal-install/Cabal the user might have so we need to adapt to whatever is there. If cabal-install itself provided a command to get at the information we extract using cabal-helper there wouldn't be any need for it in the first place.
Therefore I think something simmilar in spirit to #2771 would be a good way to move forward.
So let's run through how ghc-mod usually interacts with Cabal:
-
First we reconfigure the project if needed. To do this we have to re-implement the reconfiguration logic cabal-install already has since there isn't a
cabal configure --reconfigureflag or something afaik andcabal build(which would reconfigure if needed) would be too much. -
Then we get all the information we need about each component out of
dist/setup-config(LocalBuildInfo). That includes various rendered subsets of
GhcOptionsas well asexposed-modules,other-modulesandmain-isas applicable to the component. We need the latter to compute the module closue for components that don't list all modules. (they are meant to according to duncan) -
We call write
initialBuildStepsForAllComponentsto getPaths_*modules and such.
That's pretty much it. One thing we don't handle yet are preprocessors. If a project is using hsc2hs or something like that IIRC the user has to run cabal build first to get ghc-mod to work. It would be nice if there was an interface to just run preprocessors and to get information about source files that need them.
For more details about what GhcOptions subsets we need see cabal-helper's "helper" executable source: https://github.com/DanielG/cabal-helper/blob/master/CabalHelper/Main.hs#L185
Activity
dcoutts commentedon Sep 19, 2016
Thanks!
Yeah, that's really not going to work well in future. We can quite easily in a single project have different packages using different versions of Cabal (due to custom setup that can specify their own deps and thus can specify the Cabal lib version, and different Setup.hs don't have to use the same versions of deps as each other).
I think now you could do just
cabal (new-)build --dry-runand that'd update everything and check that constraints etc are soluble. You could usecabal (new-)configurebut that looses any flags that were previously used manually withcabal (new-)configure. (The model is thatcabal (new-)configure --flagsjust (over)writes the flags incabal.project.localwhich is then automagically included). So it depends if you want to have ghc-mode control the local config flags (cabal.project.local) or if you want to have users control that manually.Right here's where something like #2771 fits in, in addition to looking at the $distdir/cache/plan.json to find out what packages/components are in the project.
A
buildflag that only runs up to the pre-processor phase would cover it. Other people have asked for the same thing (e.g. source code analysis tools) and it shouldn't be too hard to do.merijn commentedon Nov 6, 2020
@DanielG I'm guessing that with all the
hie/hlsdevelopments and the end ofghc-modas a standalone tool this issue has become obsolete?jneira commentedon Nov 6, 2020
In any case
show-build-infoshould gives enough info to any tool, including ghc-mod, i supposeDanielG commentedon Nov 7, 2020
This issue in particular is pretty obsolete, yeah, but given that cabal has 1.3k open issues what does it matter ;)
As for s-b-i being "enough for any tool" -- personally I've come to the conclusion that the approach we've taken there is still flawed in some ways, though it's admittedly still better than the status quo. I haven't had much time/motivation for Haskell tooling work in recent times though so I just haven't gotten around to putting up a prototype for another approach though.
merijn commentedon Nov 7, 2020
phadej has been trying to clean up as many obsolete issues as possible, so I'm trying to do my part and help when I run into things, because we gotta start somewhere if we ever wanna end up with a reasonable number of issues :)