Feature request: Allow generated files to be used in repository rules
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the problem / feature request / question:
Repository rules can execute various actions, and are generally quite powerful for dealing with resources outside of Bazel and the workspace. However, repository rules are restricted to only using source files from inside the workspace, and cannot use generated files from the workspace. This is implemented via [`repository_ctx.path`](https://docs.bazel.build/versions/master/skylark/lib/repository_ctx.html#path), the docs for which include: "Note that remote repositories are executed during the analysis phase and thus cannot depends on a target result (the label should point to a non-generated file)."
This limitation is frustrating for implementing reliable, consistent repository rules. In many cases, a repository rule needs to execute utilities to download or process external repositories (e.g. maven, gazelle, python). Because repository rules are limited to source files only, authors have to rely on pre-installed executables on the system and/or jump through hoops to use generated files (e.g. executing `go build` directly as rules_go does). That makes the rule's behavior hard to predict, and doesn't allow the rule to take advantage of the build language, cache, or sandbox.
Repository rules should be able to execute build steps and use the generated files. The `repository_ctx.path` method should be extended to allow generated files, specified with the usual build rules. Bazel would execute the build steps as needed, so the repository rule would have consistent inputs.
### Environment info
* Bazel version (output of `bazel info release`): 0.7.0 (and many earlier versions)
Contributor guide
Assessment
This issue has not been assessed yet.