Open
Description
Currently, the generator_name, generator_function, and generator_location are pseudo-attributes automatically set on rule targets defined in a macro (in Bazel 8.0 and 8.1 - only for rule targets in a legacy macro). These are typically used from bazel query expressions or from native.existing_rules()
to associate a rule target to a macro.
The current API has problems:
- It's very strange that the information is exposed as pseudo-attributes which exist only sometimes (if the rule is defined in a macro), violating user expectations of how rule schema are defined. Instead, we probably should have functions (in BUILD language and in query DSL) to retrieve information about macros.
- It is exposed in a strange, illogical way; for example, if the outermost macro is a legacy macro without a
name
parameter, the rule'sgenerator_name
is set to the target name! - Users very often want to know whether a target has a given macro somewhere in its instantiation stack, not necessarily at the outermost level. Some users attempt to around this via the complete hack of setting the
generator_name
attr manually, which of course is non-composable.
I would suggest designing a replacement API, and deprecating the generator_name, generator_function, and generator_location pseudo-attributes.