haskell / hie-bios

Set up a GHC API session for various Haskell Projects
https://hackage.haskell.org/package/hie-bios
BSD 3-Clause "New" or "Revised" License
181 stars 63 forks source link

direct cradle: weird errors on static GHC flags #432

Open lyokha opened 7 months ago

lyokha commented 7 months ago

Direct cradles accept only dynamic GHC flags, static flags are considered targets. Configuration

cradle:
  direct:
    arguments: ["-Wall", "-O2", "--make"]

gives

$ hie-bios check aaa_bb.hs
[Debug] ghc --print-libdir
[Info] Cradle: Cradle{ cradleRootDir = "/home/lyokha/devel/nginx-haskell-module/haskell/ngx-export-distribution/test-nhm", cradleOptsProg = CradleAction: Direct}
[Info] invoking build tool to determine build flags (this may take some time depending on the cache)
hie-bios: target ‘--make’ is not a module name or a source file

It is not stated in documentation that only dynamic flags are accepted as flags, so I had to clone the project to find out what happens (in addCmdOpts).

IMHO, it seems to make sense to

  1. Clearly state in documentation that direct cradles accepts dynamic flags only.
  2. (Probably) Catch static flags in addCmdOpts and warn about them not trying to consider them targets.
fendor commented 7 months ago

Both of these sound like good improvements, and I'd be happy to merge PRs that improve the docs and addCmdOpts.

lyokha commented 7 months ago

It's look that it's not simple to extract mode options (--make etc.) as the corresponding parser parseModeFlags is only available in the GHC Main.hs (see https://github.com/ghc/ghc/blob/5e4f4ba835fd24135759ee7a2d0d5c636a8a1505/ghc/Main.hs#L577), so the point 1 still survives while point 2 is fading. While it's still possible to catch all option-like arguments (i.e. those starting with a dash) and give it another message (other than not a module name or source file), it has less sense than using existing API.