bazelbuild / bazelbuild/bazel

Deprecate generator_name, generator_function, generator_location and replace with better API

Open
#25,771 1 comment 0 reactions 0 assignees View on GitHub
P2 team-Loading-API team-Rules-API team-Starlark-Integration type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

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'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

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the current generator_name, generator_function, and generator_location pseudo-attributes, including how they appear in bazel query expressions and native.existing_rules(). Compare the requested needs in the BUILD language and query DSL. Done would mean a defined replacement API and a deprecation plan for the existing attributes.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.