haskell / haskell-ide-engine

The engine for haskell ide-integration. Not an IDE
BSD 3-Clause "New" or "Revised" License
2.38k stars 211 forks source link

HIE failing on test directory - multi cradle configuration. #1613

Closed drewboardman closed 4 years ago

drewboardman commented 4 years ago

I'm running hie+ nix with the all-hies cachix binaries. The production code works fine, however the test files fail with the following:

2020-01-28T17:16:46.020 DEBUG (pid:157615) [language-client-index] - [languageserver.haskell] 2020-01-28 17:16:46.02033692 [ThreadId 15] - Fail on cradle initialisation: (ExitFailure 1)["Failed to parse result of calling cabal","Resolving dependencies...
Build profile: -w ghc-8.6.4 -O1
In order, the following will be built (use -v for more details):
- myPackage-0.1 (lib) (configuration changed)
- myPackage-0.1 (test:test) (first run)
Configuring library for myPackage-0.1..
Preprocessing library for myPackage-0.1..
Building library for myPackage-0.1..
","Warning: 'ghc-options: -threaded' has no effect for libraries. It should
only be used for executables.
Warning: 'ghc-options: -rtsopts' has no effect for libraries. It should only
be used for executables.
gcc: error:
/home/drew/code/myRepo/dist-newstyle/build/x86_64-linux/ghc-8.6.4/myPackage-0.1/build/myPackage/DB/Schema.dyn_o:
No such file or directory `cc' failed in phase `Linker'. (Exit code: 1)
cabal: Failed to build myPackage-0.1 (which is required by test:test from myPackage-0.1).
",""]

2020-01-28T17:16:46.020 DEBUG (pid:157615) [language-client-index] - [languageserver.haskell] 
2020-01-28 17:16:46.020566651 [ThreadId 15] - ghcDispatcher:Got error for a request: IdeError 
{ideCode = OtherError, ideMessage = "Fail on initialisation for \"/home/drew/code/myRepo/test/src
/myPackage/Tests/DB/XX/Thing.hs\". Failed to parse result of calling cabal", ideInfo = Null} with mid: 
Nothing

My hie.yaml is:

cradle:
  cabal:
    - path: "./exec/build"
      component: "exe:build"
    - path: "./"
      component: "lib:myproject"
    - path: "./exec/myproject"
      component: "exe:myproject"
    - path: "./test/src"
      component: "test:test"

The test portion of package.yaml is:

tests:
  test:
    main: Main.hs
    source-dirs: test/src
    ghc-options:
      - -with-rtsopts=-N
      - -Wall
      - -Werror
fendor commented 4 years ago

Does cabal repl test/src/myPackage/Tests/DB/XX/Thing.hs work? You can also try to execute hie --debug test/src in the project root and link the logs here for debugging.

infinisil commented 4 years ago
No such file or directory `cc'

Perhaps that's the problem? I'd try get a C compiler in your environment

drewboardman commented 4 years ago

I'm running in an impure shell and have /usr/bin/cc.

drewboardman commented 4 years ago

Does cabal repl test/src/myPackage/Tests/DB/XX/Thing.hs work? You can also try to execute hie --debug test/src in the project root and link the logs here for debugging.

So running cabal v2-repl test/src/myPackage/Tests/DB/XX/Thing.hs creates an identical error.

$ (nix-shell) > hie --debug "test/src"
Invalid argument `test/src'

Any ideas on the args that this wants?

drewboardman commented 4 years ago

I found the issue, and it has to do with arch and linking.

https://wiki.archlinux.org/index.php/Haskell#Problems_with_linking

To anyone running into this in the future, add this to your cabal config

# ~/.cabal/config
library-vanilla: False
shared: True
executable-dynamic: True
ghc-options:
  -dynamic
drewboardman commented 4 years ago

Quoting @fendor from previous discussion thread https://github.com/mpickering/hie-bios/issues/102#issuecomment-579820614:

You can try to install the executable from this project with cabal install exe:hie-bios and then execute hie-bios debug <path to test file> and see if this succeeds. Additionally, you can use hie-bios check <path to test file> which tries to type-check the file. Not sure if the output will be helpful though. If it debug succeeds, it should print component flags. Try to execute ghc <component-flags> and see if it contains any error messages. If all this does not help at all, I would recommend to install hie from source and test my suggestion in haskell/haskell-ide-engine#1613 (comment), e.g. hie --debug <path to test file>. This should us give something.

If nothing helps at all, please try to share your project with us (if you did not install hie from source before, I would suggest this option before installing hie from source). If it is confidential, try to reduce it to something that is not confidential and share that (assuming, it reproduces your problem).

drewboardman commented 4 years ago

The one difference between the experiment you suggest and this project is that I'm using nix + all-hies.

fendor commented 4 years ago

Not a problem, just execute hie-bios/ghc in the nix-shell.

drewboardman commented 4 years ago

I'm seeing this error trying to install that:

$ cabal new-install exe:hie-bios
Warning: /home/drew/.cabal/config: Unrecognized field ghc-options on line 18
cabal: Internal error in target matching. It should always be possible to find
a syntax that's sufficiently qualified to give an unambiguous match. However
when matching 'exe:hie-bios' we found exe:hie-bios (unknown-component) which
does not have an unambiguous syntax. The possible syntax and the targets they
match are as follows:
'exe:hie-bios' which matches exe:hie-bios (unknown-component),
:pkg:exe:lib:exe:file:hie-bios (unknown-file)

Same output with $ cabal new-install 'exe:hie-bios'

infinisil commented 4 years ago

I have a patch to all-hies which includes the hie-bios command directly. I should get to pushing that

infinisil commented 4 years ago

Done that in https://github.com/infinisil/all-hies/commit/67227c42ab0b652775dbaf6401f8eff71f5d0c4f :)

drewboardman commented 4 years ago

The underlying error after running hie --debug <path to test file> is:

"can't load .so/.DLL for: /nix/store/681354n3k44r8z90m35hm8945vsp95h1-glibc-2.27/lib/libpthread.so (/nix/store/681354n3k44r8z90m35hm8945vsp95h1-glibc-2.27/lib/libpthread.so.0: undefined symbol: __libc_vfork, version GLIBC_PRIVATE)"