Add workspace_root to repository_ctx #15441
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are a number of use-cases for this, and I've seen it come up in
bazel-discussand similar. It is possible to abuse this information,but this information is currently available by looking up something like:
But this is unreliable as
WORKSPACE.bazelwas added as an alternativeto
WORKSPACE, and trying to look up a label which doesn't exist is afatal error.
We're currently using this to work around the fact that labels can't
exist if the file they point at doesn't already exist.
In repository rules we want users to be able to set an attribute to
point at a lockfile, which may not yet exist, and which our rule may
create as a side-effect of running. The nicest way we've worked out how
to do this is to use a
attr.string, and userepository_ctx.executeto test for the existence of a file, but that relies on being able to
find the path to the root repository.
It may be interesting to try to introduce some kind of fallible
label/path lookup, but that feels like a much bigger change for the
future.
Closes #13417.
PiperOrigin-RevId: 442839850