haskell / hie-bios

Set up a GHC API session for various Haskell Projects
https://hackage.haskell.org/package/hie-bios
BSD 3-Clause "New" or "Revised" License
179 stars 62 forks source link

Convert between stack/cabal naming conventions #120

Open alanz opened 4 years ago

alanz commented 4 years ago

The hie-bios README gives the following two examples

cradle: {stack: {component: "haskell-ide-engine:lib" }}
cradle: {cabal: {component: "lib:haskell-ide-engine"}}

They are both referring to the library component in haskell-ide-engine, but stack and cabal have different naming conventions for them.

If I have a complex multi-cradle, such as

cradle:
  stack:
    - path: "./test/dispatcher/"
      component: "haskell-ide-engine:test:dispatcher-test"
    - path: "./test/functional/"
      component: "haskell-ide-engine:test:func-test"
    - path: "./test/unit/"
      component: "haskell-ide-engine:test:unit-test"
    - path: "./hie-plugin-api/"
      component: "hie-plugin-api:lib"
    - path: "./app/MainHie.hs"
      component: "haskell-ide-engine:exe:hie"
    - path: "./app/HieWrapper.hs"
      component: "haskell-ide-engine:exe:hie-wrapper"
    - path: "./"
      component: "haskell-ide-engine:lib"

I would ideally like to just replace stack with cabal on the second line and have it continue to work.

Can we do some kind of implicit name translation for this case?

alanz commented 4 years ago

See sample files in https://github.com/haskell/haskell-ide-engine/pull/1533

fendor commented 4 years ago

Is there any specification for both of these formats?

alanz commented 4 years ago

I suspect it is a case of reading the code. Best case is it will be in the documentation, but I am not holding my breath.

sureyeaah commented 4 years ago

Couldn't find it in the documentation but relevant code can be found here (stack, cabal). From what I understand, a stack build target can be specified in these ways:

while cabal uses the following syntax:

jneira commented 4 years ago

@sureyeaah nice resume, i will use for reference too 😄 For completeness, i think that component_kind == [lib|test|bench|exe]

sureyeaah commented 4 years ago

@jneira thanks, would be great to document this somewhere. I could share this via a blog post maybe after I understand it more. Also Cabal lets you use the component kind "flib" for foreign libraries IIUC.

jneira commented 4 years ago

Well, it is documented but it seems it is not easily discoverable:

Also Cabal lets you use the component kind "flib" for foreign libraries IIUC

Oh yeah i forgot them (i've never used them)

mpickering commented 4 years ago

It's good to document this but I'm still not convinced it's something which needs to be "fixed" in the library.

ndmitchell commented 4 years ago

I'd rather it was fixed in stack/cabal, but given how easy it is to shim between them, seems useful to have in hie-bios so people can experiment with stack/cabal quickly without running into the obvious bug.

sureyeaah commented 4 years ago

@jneira I should have searched the docs a bit better. Still got to read some code :)

jneira commented 4 years ago

Well, at least some validation would be great ("you are using wrong syntax for targets, see [link] of [build-tool] for reference"), even if translation ends up being tricky