Skip to content

Commit

Permalink
Return early for error configured aspects
Browse files Browse the repository at this point in the history
This subtle regression was introduced in 7c4bf7f

Starlark analysis tests with `expect_failure = True` rely on the old behavior, since their implementation functions exit early with `fail()` and never return any providers. Se we need to skip validating advertised providers whenever there are analysis failures.

Fixes #19287

PiperOrigin-RevId: 558734461
Change-Id: I430013bc19baa487a2792e247c0fd7d43d64fd75
  • Loading branch information
hvadehra authored and copybara-github committed Aug 21, 2023
1 parent a9c9f6c commit 1e9334c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,10 @@ public ConfiguredAspect createAspect(
ruleClassProvider.getToolsRepository());
if (configuredAspect == null) {
return erroredConfiguredAspect(ruleContext, null);
} else if (configuredAspect.get(AnalysisFailureInfo.STARLARK_CONSTRUCTOR) != null) {
// this was created by #erroredConfiguredAspect, return early to skip validating advertised
// providers
return configuredAspect;
}

validateAdvertisedProviders(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,39 @@ public void starlarkAspectAndRuleFailure_analysisFailureInfoPropagatesOnlyFromRu
.comparingElementsUsing(analysisFailureCorrespondence)
.containsExactly(expectedRuleFailure);
}

@Test
public void starlarkAspectWithAdvertisedProvidersFailure_analysisFailurePropagates()
throws Exception {
scratch.file(
"test/extension.bzl",
"MyInfo = provider()",
"",
"def custom_aspect_impl(target, ctx):",
" fail('Aspect Failure')",
"",
"custom_aspect = aspect(implementation = custom_aspect_impl, provides = [MyInfo])",
"",
"def custom_rule_impl(ctx):",
" pass",
"",
"custom_rule = rule(implementation = custom_rule_impl,",
" attrs = {'deps' : attr.label_list(aspects = [custom_aspect])})");
scratch.file(
"test/BUILD",
"load('//test:extension.bzl', 'custom_rule')",
"",
"custom_rule(name = 'one')",
"custom_rule(name = 'two', deps = [':one'])");

ConfiguredTarget target = getConfiguredTarget("//test:two");
AnalysisFailureInfo info =
(AnalysisFailureInfo) target.get(AnalysisFailureInfo.STARLARK_CONSTRUCTOR.getKey());
AnalysisFailure expectedRuleFailure =
new AnalysisFailure(Label.parseCanonicalUnchecked("//test:one"), "Aspect Failure");

assertThat(info.getCausesNestedSet().toList())
.comparingElementsUsing(analysisFailureCorrespondence)
.containsExactly(expectedRuleFailure);
}
}

0 comments on commit 1e9334c

Please sign in to comment.