Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use consistent include paths when buiding in an external repository #178

Closed

Conversation

agotsis
Copy link

@agotsis agotsis commented Apr 1, 2024

Currently, the include paths passed to the jsonnet compiler are not all adjusted for when used in an external repository - only explicitly included imports.

This results in inconsistent include behavior when rules from rules_jsonnet are depended upon in an external repository.

Adding the workspace_root as appropriate makes this behavior consistent between builds in a local workspace and in an external one.

All existing tests pass bazel build @examples//... with bazel 6.4.0.

doc = "List of import `-J` flags to be passed to the `jsonnet` compiler.",
doc = """List of import `-J` flags to be passed to the `jsonnet` compiler.

The workspace_root, the genfiles_dir, and bin_dir are always included.""",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was already true. The generated documentation is not updated due to #177.

@agotsis
Copy link
Author

agotsis commented Apr 2, 2024

The CI build is failing on master already - see #173.
This was tested successfully with bazel 6.4.0

Consider fixing #173 first, #174 seems to be insufficient.

Edit: All is well with #179.

@agotsis agotsis force-pushed the external-repo-compatibility branch from 0af6a6c to 3697af1 Compare April 4, 2024 06:15
EdSchouten added a commit to EdSchouten/rules_jsonnet that referenced this pull request Apr 4, 2024
Right now you see that jsonnet_to_json() and jsonnet_to_json_test()
implicitly call jsonnet with "-J .". This means that if these rules are
used in combination with libraries that are declared in the root module,
everything works as expected. But as soon as libraries are used from
other modules, importing them becomes more tedious.

The goal of this change is to ensure that if a Jsonnet project can be
built within the root module, that module can also safely be used as a
child module. We solve this by automatically adding the workspace root
to the set of import paths for which one or more source files exist.
Furthermore, by considering the root of every source file, we no longer
need to use bin_dir and genfiles_dir.

Fixes: bazel-contrib#44
Fixes: bazel-contrib#86
Fixed: bazel-contrib#139
Fixes: bazel-contrib#154
Fixes: bazel-contrib#178
EdSchouten added a commit to EdSchouten/rules_jsonnet that referenced this pull request Apr 4, 2024
Right now you see that jsonnet_to_json() and jsonnet_to_json_test()
implicitly call jsonnet with "-J .". This means that if these rules are
used in combination with libraries that are declared in the root module,
everything works as expected. But as soon as libraries are used from
other modules, importing them becomes more tedious.

The goal of this change is to ensure that if a Jsonnet project can be
built within the root module, that module can also safely be used as a
child module. We solve this by automatically adding the workspace root
to the set of import paths for which one or more source files exist.
Furthermore, by considering the root of every source file, we no longer
need to use bin_dir and genfiles_dir.

Fixes: bazel-contrib#44
Fixes: bazel-contrib#86
Fixed: bazel-contrib#139
Fixes: bazel-contrib#154
Fixes: bazel-contrib#178
@EdSchouten EdSchouten closed this in 0a60c2f Apr 4, 2024
@EdSchouten
Copy link
Collaborator

Thanks for the PR, @agotsis! I just merged a somewhat different change in #182 that should also address this issue. The reason I deviated from your change is because I think that we should simply make sure that the imports in the provider contains the correct set of paths to use. This also allows us to get rid of the genfiles/bindir logic.

@agotsis
Copy link
Author

agotsis commented Apr 4, 2024

Thank you very much @EdSchouten - I have tested your changes in a large repo with complex dependencies on jsonnet and found that the issue that motivated me to open the PR has been fixed <3

@agotsis agotsis deleted the external-repo-compatibility branch April 4, 2024 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants