Skip to content

Commit

Permalink
Use definition location for StarlarkRuleFunction.export errors.
Browse files Browse the repository at this point in the history
StarlarkRuleFunction.getLocation() always returns BUILTIN.

Closes #11915.

PiperOrigin-RevId: 326724815
  • Loading branch information
benjaminp authored and copybara-github committed Aug 14, 2020
1 parent f00b2f5 commit 460ab68
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ public void export(Label starlarkLabel, String ruleClassName) throws EvalExcepti
if (attr.hasAnalysisTestTransition()) {
if (!builder.isAnalysisTest()) {
throw new EvalException(
getLocation(),
definitionLocation,
"Only rule definitions with analysis_test=True may have attributes with "
+ "analysis_test_transition transitions");
}
Expand All @@ -717,11 +717,12 @@ public void export(Label starlarkLabel, String ruleClassName) throws EvalExcepti
|| name.equals(FunctionSplitTransitionAllowlist.LEGACY_ATTRIBUTE_NAME)) {
if (!BuildType.isLabelType(attr.getType())) {
throw new EvalException(
getLocation(), "_allowlist_function_transition attribute must be a label type");
definitionLocation,
"_allowlist_function_transition attribute must be a label type");
}
if (attr.getDefaultValueUnchecked() == null) {
throw new EvalException(
getLocation(),
definitionLocation,
"_allowlist_function_transition attribute must have a default value");
}
Label defaultLabel = (Label) attr.getDefaultValueUnchecked();
Expand All @@ -740,7 +741,7 @@ public void export(Label starlarkLabel, String ruleClassName) throws EvalExcepti
.getName()
.equals(FunctionSplitTransitionAllowlist.LEGACY_LABEL.getName()))) {
throw new EvalException(
getLocation(),
definitionLocation,
"_allowlist_function_transition attribute ("
+ defaultLabel
+ ") does not have the expected value "
Expand All @@ -755,7 +756,7 @@ public void export(Label starlarkLabel, String ruleClassName) throws EvalExcepti
if (hasStarlarkDefinedTransition) {
if (!hasFunctionTransitionAllowlist) {
throw new EvalException(
getLocation(),
definitionLocation,
String.format(
"Use of Starlark transition without allowlist attribute"
+ " '_allowlist_function_transition'. See Starlark transitions documentation"
Expand All @@ -765,7 +766,7 @@ public void export(Label starlarkLabel, String ruleClassName) throws EvalExcepti
} else {
if (hasFunctionTransitionAllowlist) {
throw new EvalException(
getLocation(),
definitionLocation,
String.format(
"Unused function-based split transition allowlist: %s %s",
builder.getRuleDefinitionEnvironmentLabel(), builder.getType()));
Expand All @@ -775,7 +776,7 @@ public void export(Label starlarkLabel, String ruleClassName) throws EvalExcepti
try {
this.ruleClass = builder.build(ruleClassName, starlarkLabel + "%" + ruleClassName);
} catch (IllegalArgumentException | IllegalStateException ex) {
throw new EvalException(getLocation(), ex);
throw new EvalException(definitionLocation, ex);
}

this.builder = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public void testRuleClassTooLongAttributeName() throws Exception {
Event event = ev.getEventCollector().iterator().next();
assertThat(event.getKind()).isEqualTo(EventKind.ERROR);
assertThat(event.getMessage())
.matches("Attribute r\\.x{150}'s name is too long \\(150 > 128\\)");
.matches(":2:9: Attribute r\\.x{150}'s name is too long \\(150 > 128\\)");
}

@Test
Expand Down

0 comments on commit 460ab68

Please sign in to comment.