rules_jsonnet icon indicating copy to clipboard operation
rules_jsonnet copied to clipboard

Support import_prefix and strip_import_prefix attrs in jsonnet_library

Open dr-dime opened this issue 2 years ago • 2 comments

In light of #139 and #154, I think we should add import_prefix and strip_import_prefix attrs to jsonnet_library to bring virtual includes paths to jsonnet.

proto_library and cc_library had exact same issues in the past, and prefix magic solved the problem. I believe we can do the same for jsonnet.

Speaking of this, I think we also need to improve imports a little bit to make it similar to cc_library in some sense.

dr-dime avatar Mar 10 '22 03:03 dr-dime

@dr-dime Can you please explain you suggestion a bit more? I could try to implement it.

I'm not that experienced in writing rules, but I'd give it a try. Maybe you could provide an example like how one would pull external dependencies and manipulate the import path.

0xd3e avatar Nov 16 '22 15:11 0xd3e

The downside of something like import_prefix is that it requires us to do a whole bunch of symlink trickery. It's not as if the Jsonnet utility implementations have extensive path remapping capabilities, meaning we need to prepare the file system to have the layout that Jsonnet expects.

With regards to strip_import_prefix, I don't think there is an actual need for that. This can already be achieved by using imports, as you've noted.

With regards to #139 and #154, these issues have now been fixed. rules_jsonnet now does the sensible thing where the workspace root path is properly prepended to import paths. This means that if jsonnet_to_json() works in a given workspace, it should also work if that same workspace is used as an external module in another project.

EdSchouten avatar Apr 05 '24 13:04 EdSchouten