Add ctx.aspect_ids, deprecate ctx.aspect_id and Target.aspect_ids.
BUG=35456356
--
PiperOrigin-RevId: 148317662
MOS_MIGRATED_REVID=148317662
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
index 656ca25..76f6aa2 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
@@ -277,6 +277,13 @@
}
/**
+ * All aspects applied to the rule.
+ */
+ public ImmutableList<AspectDescriptor> getAspectDescriptors() {
+ return aspectDescriptors;
+ }
+
+ /**
* Accessor for the attributes of the rule and its aspects.
*
* <p>The rule's native attributes can be queried both on their structure / existence and values
diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java
index 8dfc157..2d6f5a2 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java
@@ -676,13 +676,30 @@
}
@SkylarkCallable(structField = true,
+ name = "aspect_ids",
+ doc = "Returns a list ids for all aspects applied to the target."
+ + " Only available in aspect implementation functions.")
+ public ImmutableList<String> aspectIds() throws EvalException {
+ if (ruleAttributesCollection == null) {
+ throw new EvalException(
+ Location.BUILTIN, "'aspect_ids' is only available in aspect implementations");
+ }
+
+ ImmutableList.Builder<String> result = ImmutableList.builder();
+ for (AspectDescriptor descriptor : ruleContext.getAspectDescriptors()) {
+ result.add(descriptor.getDescription());
+ }
+ return result.build();
+ }
+
+
+ @SkylarkCallable(structField = true,
name = "aspect_id",
- doc = "Returns a string uniquely identifying this aspect"
- + " Only available in aspect implementation functions.")
+ doc = "Deprecated, use 'aspect_ids'.")
public String aspectId() throws EvalException {
if (ruleAttributesCollection == null) {
throw new EvalException(
- Location.BUILTIN, "'aspect' is only available in aspect implementations");
+ Location.BUILTIN, "'aspect_id' is only available in aspect implementations");
}
return aspectDescriptor.getDescription();
}