Description
This is a question / discussion that can hopefully turn into a well defined feature request, rather than a bug report. I hope it's ok to do it in this format 😅
I am implementing tooling on top of the ghc api (see https://gitlab.com/tseenshe/hsinspect) and I am unfortunately unable to find the correct ghc version and flags to use for any given haskell source file.
I orginally wanted to use the envfiles generated by v2-exec
but that 1) requires knowing which flags were last used 2) requires the project to have successfully compiled to get the inplace packages 3) doesn't let me know which ghc flags were used (e.g. lang extensions, preprocessor flags, etc).
I have had a discussion with the cabal-helper
author at DanielG/cabal-helper#75 where we concluded that cabal-helper
currently doesn't do what I need, and I have had an offline discussion with the hie-bios
authors where we concluded that it is not possible to get what I need from the cabal
executable by hacking v2-repl
(although it's possible to get close, see notes at the end).
I am watching #5954 by @fendor from a distance but I still don't think it gives me what I need, although it might give some useful information.
For any given source file I need to know the ghc version and ghcflags that were last used to compile that file. e.g. if a user is swapping compiler version or optimisation flags, I need access to the most recent. Ideally I'd like to get the information back in a really simple format that doesn't require further processing (e.g. so that I can script it in a launcher script). For example, this UX would be ideal
$ cabal v2-ghcinfo /path/to/file.hs
ghc-version: 8.4.4
ghc-flags: -fbuilding-cabal-package -O0 [...] -optP-DHAVE_TRANSFORMERS -optP-include -optP/home/tseenshe/Projects/ffunctor/dist-newstyle/build/x86_64-linux/ghc-8.4.4/ffunctor-1.2.0/build/autogen/cabal_macros.h -this-unit-id ffunctor-1.2.0-inplace -hide-all-packages -Wmissing-home-modules -no-user-package-db -package-db /home/tseenshe/.cabal/store/ghc-8.4.4/package.db -package-db /home/tseenshe/Projects/ffunctor/dist-newstyle/packagedb/ghc-8.4.4 -package-db /home/tseenshe/Projects/ffunctor/dist-newstyle/build/x86_64-linux/ghc-8.4.4/ffunctor-1.2.0/package.conf.inplace -package-id base-4.11.1.0 -package-id transformers-0.5.5.0 -XHaskell2010 Data.FFunctor -Wall -Werror=missing-home-modules -hide-all-packages -ferror-spans
If there is no cache hit (e.g. if the user hasn't called v2-build or v2-run yet), then it is ok to exit with a failure.
Appendix 1: hie-bios
uses a hack that ultimately doesn't work. It uses a wrapper script to masquerade as ghc
. But 1) there is no way to find out which parameters the user last used 2) the cache will always miss because the ghc hash will change.
Appendix 2: I would love it if we got into trading features like old fashioned hippies. e.g. if you implement this feature in cabal-install, I will prioritise your feature request in haskell-tng/hsinspect.