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

Can not load test/Main.hs with a hie-bios cabal cradle #1727

Closed
mouse07410 opened this issue Apr 8, 2020 · 10 comments
Closed

Can not load test/Main.hs with a hie-bios cabal cradle #1727

mouse07410 opened this issue Apr 8, 2020 · 10 comments

Comments

@mouse07410
Copy link

MacOS Catalina 10.15.4, Xcode-11.4, current ghcup that installed GHC 8.8.3 and Cabal-3.2.0.0.
Current HIE master, built with Cabal for target hie-8.8.3.

Current VSCode with Haskell Language Server plugin 0.0.37 (and a few more plugins).

I'm trying to add HSpec framework to the tests.

Problem: the very first import Test.Hspec is highlighted as an error. See the screenshot:

Screen Shot 2020-04-08 at 17 20 44

Here's the error message from the "Problems" tab:

{
	"resource": "/Users/ur20980/Src/Str2Split/test/Spec.hs",
	"owner": "Haskell HIE (Str2Split)",
	"severity": 8,
	"message": "Fail on initialisation for \"/Users/ur20980/Src/Str2Split/test/Spec.hs\".\nFailed to parse result of calling cabal\n\ncabal: Unknown target '/Users/ur20980/Src/Str2Split/test/Spec.hs'.\nThe package Str2Split has no file target 'test/Spec.hs'.\n\n\n\n\n",
	"source": "bios",
	"startLineNumber": 1,
	"startColumn": 1,
	"endLineNumber": 2,
	"endColumn": 1
}

You see the complete content of test/Spec.hs above. Here's Str2Split.cabal:

cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.31.2.
--
-- see: https://github.com/sol/hpack
--
-- hash: 295f93990a5fee525c421b111658ccb55aa40dfb968670dede78f92d405738ba

name:           Str2Split
version:        0.1.0.0
description:    Please see the README on GitHub at <https://github.com/mouse07410/Str2Split#readme>
homepage:       https://github.com/mouse07410/Str2Split#readme
bug-reports:    https://github.com/mouse07410/Str2Split/issues
author:         Mouse
copyright:      Copyright (C) 2019 Mouse
license:        BSD3
license-file:   LICENSE
build-type:     Simple
extra-source-files:
    README.md
    ChangeLog.md

source-repository head
  type: git
  location: https://github.com/mouse07410/Str2Split

library
  exposed-modules:
      Lib
  other-modules:
      Paths_Str2Split
  hs-source-dirs:
      src
  build-depends:
      base >=4.7 && <5
  default-language: Haskell2010

executable Str2Split-exe
  main-is: Main.hs
  other-modules:
      Paths_Str2Split
  hs-source-dirs:
      app
  ghc-options: -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      Str2Split
    , base >=4.7 && <5
  default-language: Haskell2010

test-suite Str2Split-test
  type: exitcode-stdio-1.0
  main-is: Spec.hs
  other-modules:
      Paths_Str2Split
  hs-source-dirs:
      test
  ghc-options: -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      Str2Split
    , base >=4.7 && <5
    , hspec >=2.7
    , QuickCheck >=2.13
  default-language: Haskell2010

Both Cabal and Stack seem to be able to build both executables Str2Split-exe and Str2Split-test fine, despite the error messages. I can run both of them.

If you'd like to see the complete project - please see https://github.com/mouse07410/Str2Split.git

I do not claim that it's a bug - likely a pilot error. But would appreciate any help, please.

@fendor
Copy link
Collaborator

fendor commented Apr 8, 2020

Thank you for your awesomely detailed bug report!
To me, it looks like this is the manifestation of a known bug in hie-bios and cabal, see haskell/hie-bios#164 and the underlying cause haskell/cabal#6622.
Fix is haskell/cabal#6623

Workaround: provide a full mapping from path to component.

@fendor fendor changed the title Weird error...? Can not load test/Main.hs with hie-bios in a cabal cradle Apr 8, 2020
@fendor fendor changed the title Can not load test/Main.hs with hie-bios in a cabal cradle Can not load test/Main.hs with a hie-bios cabal cradle Apr 8, 2020
@mouse07410
Copy link
Author

mouse07410 commented Apr 8, 2020

Thank you for your awesomely detailed bug report!

My pleasure - hope I can maintain that level!

To me, it looks like this is the manifestation of a known bug in hie-bios and cabal ...
Fix is haskell/cabal#6623

So, this bug is not in HIE, but in Cabal itself? But the builds and runs seem to work, somehow...?

Workaround: provide a full mapping from path to component

Please pardon my ignorance - could you show what you mean/what the workaround should look like, and in what file(s)?

Update

Also, if I don't want to wait an unpredictable amount of time before the 6623 ends up in a released version of Cabal:
a. Should I just clone Cabal repo, merge that PR, build, and install in place of a released Cabal?
b. To get HIE employ this fix - probably having cabal-install executable is not good enough? How do I build HIE to incorporate this fix? Thanks!

Update 2

Please take a look at haskell/cabal#6659 - looks like I cannot build a decent cabal-install from its Git repo.

@fendor
Copy link
Collaborator

fendor commented Apr 9, 2020

So, this bug is not in HIE, but in Cabal itself? But the builds and runs seem to work, somehow...?

That is unrelated. What essentially happens in hie-bios (quite literally), with your hie.yaml, is the invocation cabal repl test/Spec.hs, which you can test in your terminal. In this case, it ought to fail with the same message as returned by your lsp message (piped through putStrLn):

Fail on initialisation for "/Users/ur20980/Src/Str2Split/test/Spec.hs".
Failed to parse result of calling cabal

cabal: Unknown target '/Users/ur20980/Src/Str2Split/test/Spec.hs'.
The package Str2Split has no file target 'test/Spec.hs'.

Please pardon my ignorance - could you show what you mean/what the workaround should look like, and in what file(s)?

Like what we do in haskell-ide-engine: https://github.com/haskell/haskell-ide-engine/blob/master/hie.yaml.cbl

a. Should I just clone Cabal repo, merge that PR, build, and install in place of a released Cabal?
b. To get HIE employ this fix - probably having cabal-install executable is not good enough? How do I build HIE to incorporate this fix? Thanks!

It should be enough to just checkout the pr and install it, via cabal install exe:cabal (assuming cabal-install 3.0.0.0 or newer).
HIE is not built against Cabal, it is enough if this modified version is on your PATH, e.g. cabal repl test/Spec.hs succeeds in your terminal, then it works with HIE.

@mouse07410
Copy link
Author

mouse07410 commented Apr 9, 2020

@fendor unfortunately, it looks like I cannot build a working cabal-install from local sources. It builds fine, but any attempt to actually install something with it results in abort on failed assertion.

As I said, my setup is building shared libraries and dynamic executables. Is there a way to build cabal-install with static libraries (it's impossible to force static executables on MacOS because some of the system libraries are shared only)? Or can you see another possible cause for this failed assertion? It's now 100% consistent, while downloaded cabal-install binaries appear to work fine...

Also, I'm confused with hie.yaml.cbl - what are "components"? Targets in <project>.cabal? Names of the executable or library files? Or...?

@mouse07410
Copy link
Author

@fendor I give up. I don't know Haskell well enough to either succeed building Cabal from source, or even enjoy the process. Nor do I understand what should go into hie.yaml - what is considered a "component"? When should "path" point at a directory (like - path: "./test/dispatcher/") and when at a specific file (like - path: "./app/MainHie.hs")? So far, no matter what I'm doing I get

$ cabal repl test/Spec.hs 
cabal: Unknown target 'test/Spec.hs'.
The package Str2Split has no file target 'test/Spec.hs'.

Here's my latest experimental hie.yaml, which unquestionably is incorrect:

cradle:
  cabal:
    - path: "./"
      component: "lib:Str2Split"

    - path: "./test/Spec.hs"
      component: "test-suite"

    - path: "./app/Main.hs"
      component: "executable"

Could you do me a favor? My sample project https://github.com/mouse07410/Str2Split.git seems small and simple enough. Would you be so kind to post the correct hie.yaml for this project? It has three "targets", as far as I understand - "library", "executable", and "test-suite".

Thanks in advance!

@fendor
Copy link
Collaborator

fendor commented Apr 9, 2020

When should "path" point at a directory (like - path: "./test/dispatcher/") and when at a specific file (like - path: "./app/MainHie.hs")

You only provide an exact file match if there is an overlap in components. E.g. the main for the executable is defined in the library.

Could you do me a favor? My sample project https://github.com/mouse07410/Str2Split.git seems small and simple enough. Would you be so kind to post the correct hie.yaml for this project? It has three "targets", as far as I understand - "library", "executable", and "test-suite".

I made a PR

@mouse07410
Copy link
Author

@fendor Thank you!

@mouse07410
Copy link
Author

As your workaround works (thank you!) I'm closing this ticket.

If it's possible to make hie.yaml support both Cabal and Stack builds on that same project - I'd appreciate if you could post the updated variant here or make another PR.

Thanks again!

@fendor
Copy link
Collaborator

fendor commented Apr 10, 2020

If it's possible to make hie.yaml support both Cabal and Stack builds on that same project - I'd appreciate if you could post the updated variant here or make another PR.

No, it isnt

@mouse07410 mouse07410 reopened this Apr 12, 2020
@fendor
Copy link
Collaborator

fendor commented Apr 13, 2020

Please open another issue and dont hijack the existing issue!

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