hie-bios icon indicating copy to clipboard operation
hie-bios copied to clipboard

Convert between stack/cabal naming conventions

Open alanz opened this issue 6 years ago • 11 comments

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 avatar Dec 31 '19 17:12 alanz

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

alanz avatar Dec 31 '19 18:12 alanz

Is there any specification for both of these formats?

fendor avatar Jan 13 '20 16:01 fendor

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.

alanz avatar Jan 13 '20 22:01 alanz

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:

  • package_name
  • package_name_with_version
  • :component_name
  • package_name:lib
  • package_name:[test|bench|exe]:component_name

while cabal uses the following syntax:

  • component_name
  • component_kind:component_name
  • component_name:module_or_file_name
  • component_kind:component_name:module_or_file_name

  • I think the naming convention might not be the same in both cases, not sure about it.
  • Cabal also lets you specify which module/file you want to build - is that relevant for our use case?
  • How should the translation work? I think we would need to restrict some cases to be able to do it unambiguously or make no changes for cases where we are unable to decide the translation. e.g. target is component_name that was written for a cabal cradle and we change it to stack. In that case, we can't decide if we want to interpret it as package_name or :component_name(user wants this).

sureyeaah avatar Feb 07 '20 01:02 sureyeaah

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

jneira avatar Feb 07 '20 05:02 jneira

@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.

sureyeaah avatar Feb 07 '20 08:02 sureyeaah

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

  • cabal: https://cabal.readthedocs.io/en/latest/nix-local-build.html#cabal-v2-build
  • stack: https://docs.haskellstack.org/en/stable/build_command/#target-syntax

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

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

jneira avatar Feb 07 '20 10:02 jneira

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

mpickering avatar Feb 07 '20 10:02 mpickering

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.

ndmitchell avatar Feb 07 '20 10:02 ndmitchell

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

sureyeaah avatar Feb 07 '20 11:02 sureyeaah

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

jneira avatar Feb 07 '20 12:02 jneira