aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java
diff options
context:
space:
mode:
authorGravatar Jon Brandvein <brandjon@google.com>2016-10-11 20:27:58 +0000
committerGravatar Yue Gan <yueg@google.com>2016-10-12 08:56:11 +0000
commita629005a0f7b5c702067b2f47e048f11700a5092 (patch)
treee878fc3978091fcc5c81e54a97b076bf3880fec8 /src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java
parent0c4a10adcfa8a6a07f6a1c56ea460ad614ec5c6d (diff)
Automated [] rollback of commit 8d36a34ee02ad0fd07d713b8c8ee273ff30d2fb9.
*** Reason for rollback *** Fixed depended-on broken CL *** Original change description *** Automated [] rollback of commit f341bc4f6e918b6a41c1536c111bbf24f14f967b. *** Reason for rollback *** Depends on c/135226123 which depends on commit 9c25afe750a937b2152c21a93effc8b9ba82c27b, which needs to be rolled back. *** Original change description *** Add ctx.get_actions(), for inspecting the actions created by the current rule. This returns an ActionsProvider. In the case where the rule does not emit any more actions afterwards, the provider is equivalent to the one that gets passed on to the rule's dependencies. This may be u... *** ROLLBACK_OF=135781162 -- MOS_MIGRATED_REVID=135833495
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleContext.java23
1 files changed, 21 insertions, 2 deletions
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 2db3649201..31ad28093e 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
@@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.Root;
+import com.google.devtools.build.lib.analysis.ActionsProvider;
import com.google.devtools.build.lib.analysis.AnalysisUtils;
import com.google.devtools.build.lib.analysis.ConfigurationMakeVariableContext;
import com.google.devtools.build.lib.analysis.FilesToRunProvider;
@@ -164,8 +165,8 @@ public final class SkylarkRuleContext {
public SkylarkRuleContext(RuleContext ruleContext, Kind kind)
throws EvalException, InterruptedException {
this.ruleContext = Preconditions.checkNotNull(ruleContext);
- fragments = new FragmentCollection(ruleContext, ConfigurationTransition.NONE);
- hostFragments = new FragmentCollection(ruleContext, ConfigurationTransition.HOST);
+ this.fragments = new FragmentCollection(ruleContext, ConfigurationTransition.NONE);
+ this.hostFragments = new FragmentCollection(ruleContext, ConfigurationTransition.HOST);
if (kind == Kind.RULE) {
Collection<Attribute> attributes = ruleContext.getRule().getAttributes();
@@ -419,6 +420,24 @@ public final class SkylarkRuleContext {
return ruleContext;
}
+ @SkylarkCallable(name = "created_actions",
+ doc = "For rules marked <code>_skylark_testable=True</code>, this returns an "
+ + "<a href=\"ActionsSkylarkApiProvider.html\">actions</a> provider representing all "
+ + "actions created so far for the current rule. For all other rules, returns None. "
+ + "Note that the provider is not updated when subsequent actions are created, so you "
+ + "will have to call this function again if you wish to inspect them. "
+ + ""
+ + "<p>This is intended to help test rule-implementation helper functions that take in a "
+ + "<a href=\"ctx.html\">ctx</a> object and create actions for it.")
+ public Object createdActions() {
+ if (ruleContext.getRule().getRuleClassObject().isSkylarkTestable()) {
+ return ActionsProvider.create(
+ ruleContext.getAnalysisEnvironment().getRegisteredActions());
+ } else {
+ return Runtime.NONE;
+ }
+ }
+
@SkylarkCallable(name = "attr", structField = true, doc = ATTR_DOC)
public SkylarkClassObject getAttr() {
return attributesCollection.getAttr();