alexwl / haskell-code-explorer

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

Fails to index #4

Open hasufell opened 5 years ago

hasufell commented 5 years ago
$ haskell-code-indexer --package /home/maerwald/git/hpath --dist dist-newstyle
2018-10-05 11:06:27.113302971 +08 : [info] haskell-code-indexer version 0.1.0.0, GHC version 8.2.2.0
cabal-helper-wrapper: /home/maerwald/git/hpath/dist-newstyle/setup-config: openFile: does not exist (No such file or directory)
2018-10-05 11:06:27.124410555 +08 : [error] readCreateProcess: /home/maerwald/git/haskell-code-explorer/.stack-work/install/x86_64-linux-tinfo6/lts-11.3/8.2.2/libexec/x86_64-linux-ghc-8.2.2/cabal-helper-0.8.0.2/cabal-helper-wrapper "--with-ghc=ghc" "--with-ghc-pkg=ghc-pkg" "--with-cabal=cabal" "/home/maerwald/git/hpath" "/home/maerwald/git/hpath/dist-newstyle" "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

I have no idea why it's trying to get into .stack-work directory of my package. I don't use stack for that package and told it to use dist-newstyle.

alexwl commented 5 years ago

Since the file /home/maerwald/git/hpath/dist-newstyle/setup-config doesn't exist, then it is possible that the package hpath was not built. The package should be built (using cabal or stack) before indexing (i.e., cabal new-build,cabal build, or stack build command should be executed).

Sorry, I should have added that to the README (I will update the README soon).

hasufell commented 5 years ago

The package was definitely built.

alexwl commented 5 years ago

Oh, now I see, I've provided an incorrect example in the README. dist directory (where setup-config file is saved) for cabal new-build should be not just dist-newstyle, but something like dist-newstyle/build/x86_64-linux/ghc-8.2.2/hpath-0.9.2.

Can you try to find a directory with setup-config file manually? I'm not sure if there is a cabal command that returns relative path to a dist directory (like stack path --dist-dir).

hasufell commented 5 years ago

Yes, that seems to work, but as expected... cabal-helper fails with random errors. It's a plague, really.

alexwl commented 5 years ago

Can you show the output of haskell-code-indexer with --verbose option?

hasufell commented 5 years ago
Registering library for Cabal-2.2.0.0..
done
[1 of 4] Compiling CabalHelper.Shared.Common ( /home/maerwald/.cache/cabal-helper/cabal-helper0.8.0.2-Cabal2.2.0.0.build/CabalHelper/Shared/Common.hs, /home/maerwald/.cache/cabal-helper/cabal-helper0.8.0.2-Cabal2.2.0.0.build/CabalHelper/Shared/Common.o )
[2 of 4] Compiling CabalHelper.Shared.InterfaceTypes ( /home/maerwald/.cache/cabal-helper/cabal-helper0.8.0.2-Cabal2.2.0.0.build/CabalHelper/Shared/InterfaceTypes.hs, /home/maerwald/.cache/cabal-helper/cabal-helper0.8.0.2-Cabal2.2.0.0.build/CabalHelper/Shared/InterfaceTypes.o )
[3 of 4] Compiling CabalHelper.Shared.Sandbox ( /home/maerwald/.cache/cabal-helper/cabal-helper0.8.0.2-Cabal2.2.0.0.build/CabalHelper/Shared/Sandbox.hs, /home/maerwald/.cache/cabal-helper/cabal-helper0.8.0.2-Cabal2.2.0.0.build/CabalHelper/Shared/Sandbox.o )
[4 of 4] Compiling Main             ( /home/maerwald/.cache/cabal-helper/cabal-helper0.8.0.2-Cabal2.2.0.0.build/CabalHelper/Runtime/Main.hs, /home/maerwald/.cache/cabal-helper/cabal-helper0.8.0.2-Cabal2.2.0.0.build/Main.o )

/home/maerwald/.cache/cabal-helper/cabal-helper0.8.0.2-Cabal2.2.0.0.build/CabalHelper/Runtime/Main.hs:47:1: error:
    Could not find module ‘Distribution.PackageDescription.Parse’
    Perhaps you meant
      Distribution.PackageDescription.Parsec (from Cabal-2.2.0.0)
      Distribution.PackageDescription.Check (from Cabal-2.2.0.0)
      Distribution.PackageDescription.Quirks (from Cabal-2.2.0.0)
    Use -v to see a list of the files searched for.
   |
47 | import Distribution.PackageDescription.Parse
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
alexwl commented 5 years ago

cabal-helper-0.8.0.2 that is used by haskell-code-indexer supports only Cabal >=1.14 && <1.26 || ==2.0.*

I should update the cabal-helper package

LeventErkok commented 5 years ago

I'm having precisely this same issue. Would be great if you could add support!

hasufell commented 5 years ago

cabal-helper is a terrible hack. It really just adds more fragility to the tooling ecosystem.

alexwl commented 5 years ago

Of course, compiling and linking cabal-helper executable at runtime is an additional point of failure. Is there a simpler way to get build information (https://www.haskell.org/cabal/release/latest/doc/API/Cabal/Distribution-Simple-LocalBuildInfo.html)? The problem is that a format of setup-config file depends on a version of Cabal library.

pwaller commented 5 years ago

I've hit this. It's trying to pick up MyProjectFoo/bar/dist/setup-config when the path should instead be:

$ cd MyProjectFoo/bar
$ ls
bar.cabal src
$ stack path --dist-dir
.stack-work/dist/x86_64-linux/Cabal-2.0.1.0

(It did work for me for the top level project which lives at MyProjectFoo/)

Is there a workaround for this?

pwaller commented 5 years ago

To answer my own question, this appears to work:

stack exec --no-ghc-package-path haskell-code-indexer -- -p . --dist $(stack path --dist-dir)
alexwl commented 5 years ago

When there is no --dist option, haskell-code-indexer tries to find the 'dist' directory: https://haskell-code-explorer.mfix.io/package/haskell-code-explorer-0.1.0.0/show/src/HaskellCodeExplorer/PackageInfo.hs#L315

The logic is as follows: if the package directory contains stack.yaml file, haskell-code-indexer executes stack path --dist-dir command to get the 'dist' directory, otherwise it tries to use the default 'dist' directory dist.

pwaller commented 5 years ago

So in my situation there is a MyProjectFoo/stack.yaml but no MyProjectFoo/bar/stack.yaml; the dist directory for bar is at MyProjectFoo/bar/.stack-work/dist/x86_64-linux/Cabal-2.0.1.0. Should the indexer check upper directories for a stack.yaml and if it finds one fall back to running stack path --dist-dir in the CWD?

hasufell commented 5 years ago

I don't see how this is related to the original issue, which was about using cabal.

pwaller commented 5 years ago

Apologies, I've filed a separate issue for that https://github.com/alexwl/haskell-code-explorer/issues/13.