ghc-mod
ghc-mod copied to clipboard
When using stack with lts-10.x, -Werror causes `ghc-mod browse` to not look for dependencies
I created a stack project with two modules Lib and Dep; Lib imports Dep. I added ghc-options: -Werror to the cabal file.
Lib is in exposed-modules
Dep is in other-modules
Trying to use ghc-mod browse I get
$ ghc-mod browse Lib
EXCEPTION: browse:
These modules are needed for compilation but not listed in your .cabal file's other-modules: Dep
Failing due to -Werror.
https://github.com/davidspies/mweghcmod924/tree/master/example
Yeah I can totally see how -Werror would mess things up in this case. The easy solution is to just add the module the warning mentions to other-modules: or you can disable the warning by also adding -fno-warn-missing-home-modules.
I guess to fix this for good we could just unconditionally filter out -Werror I don't see a reason not to.
The module is in other-modules:. That's what this ticket is about.
I'm getting the error anyway
Ok I've tracked down the problem. We only ever pass the module names given on the command line to loadTargets, that used to not be a problem but with warn-missing-home-modules we should be passing the closure of the import graph starting from the given modules instead.
Should be straightforward, all we need is to call HomeModuleGraph.reachable with the passed in modules.
$ ghc-mod -vvv browse Lib
info: Found Stack project at: /home/dxld/var/build/mweghcmod924/example
Warning: 'dist/setup-config' exists, ignoring Stack project
info: Found Cabal project at: /home/dxld/var/build/mweghcmod924/example
info: Using Cabal project at: /home/dxld/var/build/mweghcmod924/example
DEBUG: reading cache: /home/dxld/var/build/mweghcmod924/example/dist/setup-config.ghc-mod.package-options
DEBUG: reading cache: /home/dxld/var/build/mweghcmod924/example/dist/setup-config.ghc-mod.cabal-components
DEBUG: resolveEntrypoint:
["-i","-idist/build","-isrc","-idist/build/autogen","-idist/build/global-autogen","-Idist/build/autogen","-Idist/build/global-autogen","-Idist/build","-optP-include","-optPdist/build/autogen/cabal_macros.h"]
DEBUG: resolveEntrypoint: []
DEBUG: making sure autogen files exist
DEBUG: reading cache: dist/setup-config.ghc-mod.resolved-components
VOMIT: Initializing GHC session with following options: "-fbuilding-cabal-package" "-O" "-outputdir" "dist/build" "-odir" "dist/build" "-hidir" "dist/build" "-stubdir" "dist/build" "-i" "-idist/build" "-isrc" "-idist/build/autogen" "-idist/build/global-autogen" "-Idist/build/autogen" "-Idist/build/global-autogen" "-Idist/build" "-optP-include" "-optPdist/build/autogen/cabal_macros.h" "-this-unit-id" "example-0.1.0.0-4p4oBKi1cnE21uStnk6OnZ" "-hide-all-packages" "-Wmissing-home-modules" "-package-id" "base-4.10.0.0" "-XHaskell2010" "-Werror" "-O0"
DEBUG: initSession: Session not initialized, creating new one
DEBUG: loadTargets: Loading: Lib
EXCEPTION: browse:
These modules are needed for compilation but not listed in your .cabal file's other-modules: Dep
Failing due to -We
1ea7e85b31c5f2c6a7aae46c116f40680f0c05fc + 6bf0ac7de82a28f20e4144ff2ca66ed97b8fee03 is a quick hack to fix this issue, can you confirm it works for you?
Running it now I get:
$ ghc-mod browse Lib
cabal-helper0.8.0.0-Cabal2.0.1.0: Unknown command: needs-build-output
Usage: cabal-helper0.8.0.0-Cabal2.0.1.0 PROJ_DIR DIST_DIR [--with-* ...] (
version
| print-lbi [--human]
| package-id
| flags
| config-flags
| non-default-config-flags
| write-autogen-files
| compiler-version
| ghc-options [--with-inplace]
| ghc-src-options [--with-inplace]
| ghc-pkg-options [--with-inplace]
| ghc-merged-pkg-options [--with-inplace]
| ghc-lang-options [--with-inplace]
| package-db-stack
| entrypoints
| source-dirs
| licenses
) ...
cabal-helper0.8.0.0-Cabal2.0.1.0: Unknown command: needs-build-output
Usage: cabal-helper0.8.0.0-Cabal2.0.1.0 PROJ_DIR DIST_DIR [--with-* ...] (
version
| print-lbi [--human]
| package-id
| flags
| config-flags
| non-default-config-flags
| write-autogen-files
| compiler-version
| ghc-options [--with-inplace]
| ghc-src-options [--with-inplace]
| ghc-pkg-options [--with-inplace]
| ghc-merged-pkg-options [--with-inplace]
| ghc-lang-options [--with-inplace]
| package-db-stack
| entrypoints
| source-dirs
| licenses
) ...
EXCEPTION: browse:
readCreateProcess: /home/david/ghc-mod/.stack-work/install/x86_64-linux/lts-10.3/8.2.2/libexec/x86_64-linux-ghc-8.2.2/cabal-helper-0.8.0.0/cabal-helper-wrapper "--with-ghc=/home/david/.stack/programs/x86_64-linux/ghc-8.2.2/bin/ghc" "--with-ghc-pkg=/home/david/.stack/programs/x86_64-linux/ghc-8.2.2/bin/ghc-pkg" "--with-cabal=cabal" "/home/david/hworkspace/mweghcmod924/example" "/home/david/hworkspace/mweghcmod924/example/.stack-work/dist/x86_64-linux/Cabal-2.0.1.0" "package-db-stack" "flags" "compiler-version" "ghc-merged-pkg-options" "config-flags" "non-default-config-flags" "ghc-src-options" "ghc-pkg-options" "ghc-lang-options" "ghc-options" "source-dirs" "entrypoints" "needs-build-output" (exit 1): failed
Actually I get that regardless of whether I include -Werror. ghc-mod seems to have stopped working for me altogether.
You need to delete cabal-helper's binary cache since you used a pre-release version, assuming you're on unix that should be at ~/.cache/cabal-helper.
I really have to add some sort of hash there on of these days :/
Yup, seems to work. Thanks!