Convert between stack/cabal naming conventions
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?
See sample files in https://github.com/haskell/haskell-ide-engine/pull/1533
Is there any specification for both of these formats?
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.
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_namepackage_name_with_version:component_namepackage_name:libpackage_name:[test|bench|exe]:component_name
while cabal uses the following syntax:
component_namecomponent_kind:component_namecomponent_name:module_or_file_namecomponent_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_namethat 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 aspackage_nameor:component_name(user wants this).
@sureyeaah nice resume, i will use for reference too 😄
For completeness, i think that component_kind == [lib|test|bench|exe]
@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.
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)
It's good to document this but I'm still not convinced it's something which needs to be "fixed" in the library.
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.
@jneira I should have searched the docs a bit better. Still got to read some code :)
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