Skip to content

Commit

Permalink
Re-add StarlarkDefinedAspect.getAttributeAspects
Browse files Browse the repository at this point in the history
Needed for the new version of Stardoc.

Accidentally removed by b21cf25

PiperOrigin-RevId: 518375888
Change-Id: I7927e302bda282ce63b98a9c03f959de6406cdd8
  • Loading branch information
tetromino authored and copybara-github committed Mar 21, 2023
1 parent 9c01a5a commit 6ec2511
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public Optional<String> getDocumentation() {
return Optional.ofNullable(documentation);
}

/** Returns the names of rule attributes along which the aspect will propagate. */
public ImmutableList<String> getAttributeAspects() {
return attributeAspects;
}

public ImmutableList<Attribute> getAttributes() {
return attributes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2021,6 +2021,21 @@ public void declaredProvidersBadTypeForDoc() throws Exception {
"got value of type 'int', want 'string or NoneType'", "provider(doc = 1)");
}

@Test
public void aspectAttrs() throws Exception {
evalAndExport(
ev,
"def _impl(target, ctx):", //
" pass",
"my_aspect = aspect(_impl, attr_aspects=['srcs', 'data'])");

StarlarkDefinedAspect myAspect = (StarlarkDefinedAspect) ev.lookup("my_aspect");
assertThat(myAspect.getAttributeAspects()).containsExactly("srcs", "data");
assertThat(myAspect.getDefinition(AspectParameters.EMPTY).propagateAlong("srcs")).isTrue();
assertThat(myAspect.getDefinition(AspectParameters.EMPTY).propagateAlong("data")).isTrue();
assertThat(myAspect.getDefinition(AspectParameters.EMPTY).propagateAlong("other")).isFalse();
}

@Test
public void aspectAllAttrs() throws Exception {
evalAndExport(
Expand All @@ -2030,6 +2045,7 @@ public void aspectAllAttrs() throws Exception {
"my_aspect = aspect(_impl, attr_aspects=['*'])");

StarlarkDefinedAspect myAspect = (StarlarkDefinedAspect) ev.lookup("my_aspect");
assertThat(myAspect.getAttributeAspects()).containsExactly("*");
assertThat(myAspect.getDefinition(AspectParameters.EMPTY).propagateAlong("foo")).isTrue();
}

Expand Down

0 comments on commit 6ec2511

Please sign in to comment.