Skip to content
This repository has been archived by the owner on Apr 25, 2020. It is now read-only.

When using stack with lts-10.x, -Werror causes ghc-mod browse to not look for dependencies #924

Open
davidspies opened this issue Jan 7, 2018 · 10 comments

Comments

@davidspies
Copy link

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.

@davidspies
Copy link
Author

@DanielG
Copy link
Owner

DanielG commented Jan 15, 2018

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.

@davidspies
Copy link
Author

The module is in other-modules:. That's what this ticket is about.

@davidspies
Copy link
Author

I'm getting the error anyway

@DanielG
Copy link
Owner

DanielG commented Jan 18, 2018

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

@DanielG
Copy link
Owner

DanielG commented Jan 23, 2018

1ea7e85 + 6bf0ac7 is a quick hack to fix this issue, can you confirm it works for you?

@davidspies
Copy link
Author

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

@davidspies
Copy link
Author

Actually I get that regardless of whether I include -Werror. ghc-mod seems to have stopped working for me altogether.

@DanielG
Copy link
Owner

DanielG commented Jan 27, 2018

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 :/

@davidspies
Copy link
Author

Yup, seems to work. Thanks!

davidspies added a commit to davidspies/cipola that referenced this issue Jan 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants