Skip to content

Deprecate generator_name, generator_function, generator_location and replace with better API #25771

Open
@tetromino

Description

@tetromino

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's generator_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.

@comius @brandjon FYI

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2We'll consider working on this in future. (Assignee optional)team-Loading-APIBUILD file and macro processing: labels, package(), visibility, globteam-Rules-APIAPI for writing rules/aspects: providers, runfiles, actions, artifactsteam-Starlark-IntegrationIssues involving Bazel's integration with Starlark, excluding builtin symbolstype: feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions