Skip to content

Commit 93ad589

Browse files
mai93copybara-github
authored andcommitted
Fix resolving aspect attribute with same name as underlying target attribute
Check `ConfiguredAttributeMapper` only for non-aspect explicit attributes to avoid selecting a rule attribute with same name but different type Fixes: #18901 PiperOrigin-RevId: 548714977 Change-Id: Iaa9148cf21ce28d9414840e7cd874ffaaf9d7bb4
1 parent cc335fd commit 93ad589

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/main/java/com/google/devtools/build/lib/analysis/DependencyResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ private static <T> void resolveAttribute(
379379
} else if (attribute.isLateBound()) {
380380
attributeValue =
381381
type.cast(resolveLateBoundDefault(rule, attributeMap, attribute, ruleConfig));
382-
} else if (attributeMap.has(attribute.getName())) {
382+
} else if (dependencyKind.getOwningAspect() == null && attributeMap.has(attribute.getName())) {
383383
// This condition is false for aspect attributes that do not give rise to dependencies because
384384
// attributes that come from aspects do not appear in attributeMap (see the comment in the
385385
// case that handles implicit attributes).

src/test/java/com/google/devtools/build/lib/starlark/StarlarkDefinedAspectsTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8606,6 +8606,39 @@ public void testAspectRunsTwiceWithDiffBaseAspectsDeps() throws Exception {
86068606
"aspect a on @//test:t4 sees b_provider = aspect b cannot see c_provider");
86078607
}
86088608

8609+
@Test
8610+
public void testAspectWithSameExplicitAttributeNameAsUnderlyingTarget() throws Exception {
8611+
scratch.file(
8612+
"test/defs.bzl",
8613+
"def _a_impl(target, ctx):",
8614+
" value = 'x from aspect = {}, x from target = {}'.format(ctx.attr.x, ctx.rule.attr.x)",
8615+
" return struct(aspect_result = value)",
8616+
"a = aspect(",
8617+
" implementation = _a_impl,",
8618+
" attrs = {",
8619+
" 'x': attr.string(default = 'xyz')",
8620+
" },",
8621+
")",
8622+
"",
8623+
"def _rule_impl(ctx):",
8624+
" pass",
8625+
"r1 = rule(",
8626+
" implementation = _rule_impl,",
8627+
" attrs = {",
8628+
" 'x': attr.int(default = 4)",
8629+
" },",
8630+
")");
8631+
scratch.file("test/BUILD", "load('//test:defs.bzl', 'r1')", "r1(name = 't1')");
8632+
8633+
AnalysisResult analysisResult = update(ImmutableList.of("//test:defs.bzl%a"), "//test:t1");
8634+
8635+
ImmutableMap<AspectKey, ConfiguredAspect> configuredAspects = analysisResult.getAspectsMap();
8636+
ConfiguredAspect aspectA = getConfiguredAspect(configuredAspects, "a");
8637+
assertThat(aspectA).isNotNull();
8638+
String aspectAResult = (String) aspectA.get("aspect_result");
8639+
assertThat(aspectAResult).isEqualTo("x from aspect = xyz, x from target = 4");
8640+
}
8641+
86098642
private ImmutableList<AspectKey> getAspectKeys(String targetLabel, String aspectLabel) {
86108643
return skyframeExecutor.getEvaluator().getDoneValues().entrySet().stream()
86118644
.filter(

0 commit comments

Comments
 (0)