bazel-contrib / rules_jsonnet

Jsonnet rules for Bazel
https://bazelbuild.github.io/rules_jsonnet/
Apache License 2.0
68 stars 73 forks source link

Support import_prefix and strip_import_prefix attrs in jsonnet_library #155

Open dr-dime opened 2 years ago

dr-dime commented 2 years ago

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.

0xd3e commented 2 years ago

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

EdSchouten commented 8 months ago

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.