haskell/hie-bios

direct cradle: weird errors on static GHC flags

Opened this issue · 2 comments

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.

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

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.