forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workspace_root to repository_ctx (bazelbuild#15441)
There are a number of use-cases for this, and I've seen it come up in `bazel-discuss` and similar. It is possible to abuse this information, but this information is currently available by looking up something like: ```python repository_ctx.path(Label("@//:WORKSPACE")).dirname ``` But this is unreliable as `WORKSPACE.bazel` was added as an alternative to `WORKSPACE`, and trying to look up a label which doesn't exist is a fatal 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 use `repository_ctx.execute` to 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 bazelbuild#13417. PiperOrigin-RevId: 442839850 Co-authored-by: Daniel Wagner-Hall <dwagnerhall@apple.com>
- Loading branch information
1 parent
b877092
commit 8d510ec
Showing
3 changed files
with
26 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters