Create a way for macros to "reify" string labels into label objects #15172
Labels
area-Bzlmod
Bzlmod-specific PRs, issues, and feature requests
P2
We'll consider working on this in future. (Assignee optional)
team-ExternalDeps
External dependency handling, remote repositiories, WORKSPACE file.
type: feature request
The immediately obvious answer seems to be "just call
Label(...)
", except that would anchor the string label at the current .bzl file's context. For a macro that receives string labels from BUILD files, it would probably want to convert string labels with the BUILD file's context. Example:Here
mymacro
simply includes an extra dep before forwarding the call tomyrule
. But the check is almost never true becausedeps
almost always contains only strings! We can't do[Label(dep) for dep in deps]
because that would mean":hello"
gets turned into@myrule//myrule:hello
instead of@myproject//pkg:hello
. We also can't checkif str(DEFAULT_DEP) not in deps
becausedeps
can contain non-absolute labels, whereasstr(DEFAULT_DEP)
is an absolute label.We need a way to turn a string into a Label using the calling package's context. This is actually exactly the deprecated
Label(..., relative_to_caller_package=True)
constructor that we removed, thinking nobody would ever use it. It turns out that's not true (see protocolbuffers/protobuf#9688). We should maybe add it back, and maybe think of a better API for it.cc @brandjon @meteorcloudy
The text was updated successfully, but these errors were encountered: