You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a multi-GHC setting, we have e.g. ghc-9.4.4 and ghc-9.2.5 installed. These "know" of their companion programs like ghc-pkg. E.g. I can do
cabal repl -w ghc-9.2.5
even if my current ghc is ghc-9.4.4.
doctest however gets confused in such settings.
E.g. I installed doctest for 9.2.5:
$ cabal install -w ghc-9.2.5 doctest --program-suffix=-9.2.5...
$ doctest-9.2.5 --versiondoctest version 0.20.1using version 9.2.5 of the GHC APIusing /usr/local/bin/ghc-9.2.5
$ doctest-9.2.5 --numeric-version9.2.5
As one can see, doctest is well aware of the GHC version it is build for.
However:
$ cabal repl -w doctest-9.2.5
Error: cabal: Version mismatch between ghc and ghc-pkg:
doctest-9.2.5 is version 9.2.5
/usr/local/bin/ghc-pkg is version 9.4.4
So this fails.
I can't shake the feeling that this cabal repl -w doctest is just a hack that in some benign cases works but in general fails.
The reason might be that cabal isn't really prepared to work with anything else but ghc. Frankly, I don't know how cabal determines ghc-pkg-x.y.z from ghc-x.y.z, but this might also just be implemented naively by some string manipulation (rather than involving ghc --numeric-version).
doctest however gets confused in such settings. E.g. I installed doctest for 9.2.5:
$ cabal install -w ghc-9.2.5 doctest --program-suffix=-9.2.5
...
$ doctest-9.2.5 --version
doctest version 0.20.1
using version 9.2.5 of the GHC API
using /usr/local/bin/ghc-9.2.5
$ doctest-9.2.5 --numeric-version
9.2.5
As one can see, doctest is well aware of the GHC version it is build for. However:
$ cabal repl -w doctest-9.2.5
Error: cabal: Version mismatch between ghc and ghc-pkg:
doctest-9.2.5 is version 9.2.5
/usr/local/bin/ghc-pkg is version 9.4.4
From what I understand, cabal gets confused here, not doctest.
I can't shake the feeling that this cabal repl -w doctest is just a hack that in some benign cases works but in general fails.
I'm not aware of any better (or even remotely robust) way to get the correct flags for a Cabal project.
AFAIK, e.g. hie-bios / hls use the same approach to get the correct flags for a source file + other tools could benefit from it too. If there are limitations with cabal then I think addressing these limitations in cabal is the way forward.
Frankly, I don't know how cabal determines ghc-pkg-x.y.z from ghc-x.y.z
That's the relevant question.
Educated guess:
cabal looks at the canonical path of ghc (all symlinks resolved) and then uses any ghc-pkg next to that.
If there is no such ghc-pkg (as would be the case with doctest) then cabal falls back to whatever ghc-pkg is on the PATH.
(just an educated guess, somebody would need to confirm this by looking at the code)
A more robust way for cabal to find ghc-pkg would be to look at the output of ghc --info. ghc --info does not contain the path to ghc-pkg. However, it contain the path to unlit and ghc-pkg is in that same directory.
@sol does hie-bios/hls uses the same ghc key in their augmented ghc --info? Because I wonder if an alternative ghc:path or path:ghc would allow more flexibility if adapted to other tools/values.
Activity
sol commentedon Jan 31, 2023
From what I understand,
cabalgets confused here, notdoctest.I'm not aware of any better (or even remotely robust) way to get the correct flags for a Cabal project.
AFAIK, e.g.
hie-bios/hlsuse the same approach to get the correct flags for a source file + other tools could benefit from it too. If there are limitations withcabalthen I think addressing these limitations incabalis the way forward.That's the relevant question.
Educated guess:
caballooks at the canonical path ofghc(all symlinks resolved) and then uses anyghc-pkgnext to that.ghc-pkg(as would be the case withdoctest) thencabalfalls back to whateverghc-pkgis on thePATH.(just an educated guess, somebody would need to confirm this by looking at the code)
A more robust way for
cabalto findghc-pkgwould be to look at the output ofghc --info.ghc --infodoes not contain the path toghc-pkg. However, it contain the path tounlitandghc-pkgis in that same directory.sol commentedon Jan 31, 2023
@andreasabel please try if
--with-hc-pkg=ghc-pkg-9.2.5can be used as a workaround.Make sure that `doctest` finds the correct version of `ghc-pkg`
sol commentedon Feb 1, 2023
@andreasabel haskell/cabal#8718 addresses this in
Cabal; no changes todoctestrequired.Ensure corret version of `ghc-pkg` for `cabal repl --with-ghc=doctest`
Ensure corret version of `ghc-pkg` for `cabal repl --with-ghc=doctest`
Ensure corret version of `ghc-pkg` for `cabal repl --with-ghc=doctest`
wismill commentedon May 27, 2024
I revived @sol's PR at haskell/cabal#10057.
@sol does
hie-bios/hlsuses the sameghckey in their augmentedghc --info? Because I wonder if an alternativeghc:pathorpath:ghcwould allow more flexibility if adapted to other tools/values.sol commentedon May 27, 2024
Great 👍
I'm not aware that they would do anything in that regard right now.
sol commentedon Jul 18, 2024
This is addressed by #439.
With
cabal-installversion 3.12 or later try: