alexwl / haskell-code-explorer

Web application for exploring and understanding Haskell codebases
MIT License
509 stars 20 forks source link

"Needed for compilation but not listed in your .cabal file's other-modules" #10

Closed pwaller closed 5 years ago

pwaller commented 5 years ago

Hi!

VERSIONS: I'm using Haskell 8.2.2 and Cabal 2.0.1.0. I installed with stack --stack-yaml=stack-8.2.2.yaml install. I built master of haskell-code-explorer at d4827af.

I'm an experienced programmer but new to Haskell, so feeling a bit stupid here. Hoping to use this lovely tool to help me find my way around a large legacy codebase. I've done my best to follow the README and docs but apologies if I missed something obvious.

When running stack exec --no-ghc-package-path haskell-code-indexer -- -p ., I get:

[error] Error while indexing component exe-FooBarMyProject : These modules are needed for compilation but not listed in your .cabal file's other-modules: 
...
<Huge list of about 20 modules>
...

There are quite a lot of components. When I look at the cabal file for these failing components, I see:

other-modules:   Paths_FooBarMyProject

I found this defined in the Cabal docs. I'm guessing that in fact this is a red herring.

One thing the strikes me about the cabal file is that there are many executables/benchmarks defined which all depend on FooBarMyProject through build-depends:, and that FooBarMyProject.cabal looks like this:

name:                FooBarMyProject
...
<author etc>
...

library
  exposed-modules:
    <huge list of modules>

So my best guess is that those modules which haskell-code-indexer complains about are meant to be depended on through that library, somehow.

Thanks in advance if you can spare a moment to help with this.

alexwl commented 5 years ago

Hi!

Thank you for the report.

I think I've found the problem.

These modules are needed for compilation but not listed in your .cabal file's other-modules: is a warning, not an error (https://github.com/ghc/ghc/blob/21f0f56164f50844c2150c62f950983b2376f8b6/compiler/main/GhcMake.hs#L205). It seems that haskell-code-indexer complains because of the -Werror flag that makes all warnings fatal (https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/using-warnings.html?highlight=werror#ghc-flag--Werror).

I've removed -Werror flag from the list of options for GHC.

Can you try https://github.com/alexwl/haskell-code-explorer/commit/67d0714dc3a9fc863140014d62efc573878df2d2?

pwaller commented 5 years ago

Hmm, that commit doesn't build for me:

$ time stack --stack-yaml=stack-8.2.2.yaml install
cabal-helper-0.8.1.2: unregistering (switching from /home/pwaller/.local/src/github.com/haskell-code-explorer/vendor/cabal-helper-0.8.1.2/ to /home/pwaller/.local/src/github.com/alexwl/haskell-code-explorer/vendor/cabal-helper-0.8.1.2/)
haskell-code-explorer-0.1.0.0: unregistering (missing dependencies: cabal-helper)
cabal-helper-0.8.1.2: configure (lib + exe)
cabal-helper-0.8.1.2: build (lib + exe)
Progress 1/2

--  While building package cabal-helper-0.8.1.2 using:
      /home/pwaller/.local/src/github.com/alexwl/haskell-code-explorer/vendor/cabal-helper-0.8.1.2/.stack-work/dist/x86_64-linux/Cabal-2.0.1.0/setup/setup --builddir=.stack-work/dist/x86_64-linux/Cabal-2.0.1.0 build lib:cabal-helper exe:cabal-helper-wrapper --ghc-options " -ddump-hi -ddump-to-file -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1
    Logs have been written to: /home/pwaller/.local/src/github.com/alexwl/haskell-code-explorer/.stack-work/logs/cabal-helper-0.8.1.2.log

    [1 of 2] Compiling Main             ( /home/pwaller/.local/src/github.com/alexwl/haskell-code-explorer/vendor/cabal-helper-0.8.1.2/Setup.hs, /home/pwaller/.local/src/github.com/alexwl/haskell-code-explorer/vendor/cabal-helper-0.8.1.2/.stack-work/dist/x86_64-linux/Cabal-2.0.1.0/setup/Main.o ) [flags changed]
    [2 of 2] Compiling StackSetupShim   ( /home/pwaller/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /home/pwaller/.local/src/github.com/alexwl/haskell-code-explorer/vendor/cabal-helper-0.8.1.2/.stack-work/dist/x86_64-linux/Cabal-2.0.1.0/setup/StackSetupShim.o ) [flags changed]
    Linking /home/pwaller/.local/src/github.com/alexwl/haskell-code-explorer/vendor/cabal-helper-0.8.1.2/.stack-work/dist/x86_64-linux/Cabal-2.0.1.0/setup/setup ...
    Configuring cabal-helper-0.8.1.2...
    Preprocessing library for cabal-helper-0.8.1.2..
    Building library for cabal-helper-0.8.1.2..
    [1 of 4] Compiling CabalHelper.Shared.InterfaceTypes ( src/CabalHelper/Shared/InterfaceTypes.hs, .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/CabalHelper/Shared/InterfaceTypes.o )
    [2 of 4] Compiling CabalHelper.Shared.Sandbox ( src/CabalHelper/Shared/Sandbox.hs, .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/CabalHelper/Shared/Sandbox.o )
    [3 of 4] Compiling Paths_cabal_helper ( .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/autogen/Paths_cabal_helper.hs, .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/Paths_cabal_helper.o )
    [4 of 4] Compiling Distribution.Helper ( lib/Distribution/Helper.hs, .stack-work/dist/x86_64-linux/Cabal-2.0.1.0/build/Distribution/Helper.o )

    /home/pwaller/.local/src/github.com/alexwl/haskell-code-explorer/vendor/cabal-helper-0.8.1.2/lib/Distribution/Helper.hs:101:1: error:
        Could not find module ‘Cabal.Plan’
        There are files missing in the ‘cabal-plan-0.4.0.0’ package,
        try running 'ghc-pkg check'.
        Use -v to see a list of the files searched for.
        |
    101 | import Cabal.Plan
        | ^^^^^^^^^^^^^^^^^
pwaller commented 5 years ago

Hmm, of course that isn't to do with that, it's my fault for moving the source directory! Apologies.

pwaller commented 5 years ago

It's working! Awesome, thanks.

alexwl commented 5 years ago

Cool!

If you have any ideas or suggestions on how to improve the tool, I'd love to hear them.