Skip to content

[9.1.0] Fix visibility for implicit deps of parent rules (https://github.com/bazelbuild/bazel/pull/28627)#28688

Merged
iancha1992 merged 1 commit intobazelbuild:release-9.1.0from
bazel-io:cp28627-9.1.0
Feb 17, 2026
Merged

[9.1.0] Fix visibility for implicit deps of parent rules (https://github.com/bazelbuild/bazel/pull/28627)#28688
iancha1992 merged 1 commit intobazelbuild:release-9.1.0from
bazel-io:cp28627-9.1.0

Conversation

@bazel-io
Copy link
Copy Markdown
Member

The visibility of a default value of an implicit dep in an extended rule should be checked relative to the definition of the rule that introduced it, which may not be the child rule.

Fixes #28618

Closes #28627.

PiperOrigin-RevId: 871303947
Change-Id: I0027e277dc9f01396fa4674297d2a73e1e9d257e

Commit a16489f

The visibility of a default value of an implicit dep in an extended rule should be checked relative to the definition of the rule that introduced it, which may not be the child rule.

Fixes bazelbuild#28618

Closes bazelbuild#28627.

PiperOrigin-RevId: 871303947
Change-Id: I0027e277dc9f01396fa4674297d2a73e1e9d257e
@bazel-io bazel-io requested a review from a team as a code owner February 17, 2026 15:26
@bazel-io bazel-io added team-Configurability platforms, toolchains, cquery, select(), config transitions awaiting-review PR is awaiting review from an assigned reviewer labels Feb 17, 2026
@bazel-io bazel-io requested a review from brandjon February 17, 2026 15:26
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to fix a visibility issue with implicit dependencies in extended Starlark rules. The core logic change to walk up the parent rule chain to find the original definer of an attribute is correct for handling inherited private attributes. However, this new logic is placed under a condition that will not trigger for private Starlark attributes (which start with _), making the fix ineffective for its intended purpose. I've left a critical comment explaining the issue on the new code block.

Comment on lines +204 to +212
// Rule extensions can't override private attributes, so we can just walk up the chain to
// find the rule class that actually introduced the attribute and thus its default.
var owningRule = rule.getRuleClassObject();
RuleClass parent;
while ((parent = owningRule.getStarlarkParent()) != null
&& parent.getAttributeProvider().getAttributeByNameMaybe(attrName) != null) {
owningRule = parent;
}
state.owningRule = owningRule;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This logic to find the original defining rule class is correct for handling inherited private attributes in Starlark. However, it is placed inside an if (isImplicitDep) block where the condition will not be met for private Starlark attributes.

The isImplicitDep check at line 189 is based on attribute.isImplicit(), which only returns true for attribute names starting with $. Private Starlark attributes start with _, so isImplicit() will be false for them. This means this new logic will not execute for the very case it is intended to fix, as demonstrated by the _tool attribute in the new test.

To fix this, this logic block should be moved, or the conditional at line 189 should be updated to also check for private Starlark attributes (e.g., attribute.getName().startsWith("_")). Since line 189 is not in the diff, I recommend moving this block to a new else if that correctly handles private Starlark attributes.

@iancha1992 iancha1992 requested review from Wyverald and gregestren and removed request for Wyverald February 17, 2026 17:21
@iancha1992 iancha1992 enabled auto-merge February 17, 2026 17:24
@iancha1992 iancha1992 added this pull request to the merge queue Feb 17, 2026
Merged via the queue into bazelbuild:release-9.1.0 with commit faaa1b4 Feb 17, 2026
46 checks passed
@github-actions github-actions bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-Configurability platforms, toolchains, cquery, select(), config transitions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants