aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google
diff options
context:
space:
mode:
authorGravatar Dmitry Lomov <dslomov@google.com>2017-02-23 08:55:47 +0000
committerGravatar Yue Gan <yueg@google.com>2017-02-23 11:33:06 +0000
commit503c2f7e9a6ca41885484288e47e809147beb6bf (patch)
treed39f6cbe7c3ab80ba0ae8c3d5bdb4419b07c3bda /src/main/java/com/google
parent786cfa2ed980e278c42ee474408844f7e3720385 (diff)
Add ctx.aspect_ids, deprecate ctx.aspect_id and Target.aspect_ids.
BUG=35456356 -- PiperOrigin-RevId: 148317662 MOS_MIGRATED_REVID=148317662
Diffstat (limited to 'src/main/java/com/google')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java23
2 files changed, 27 insertions, 3 deletions
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 656ca2595f..76f6aa2f56 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 @@ public final class RuleContext extends TargetContext
}
/**
+ * 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 8dfc1579d8..2d6f5a23c4 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 @@ public final class SkylarkRuleContext {
}
@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();
}