Skip to content

Commit

Permalink
Fix up documentation for Actions API
Browse files Browse the repository at this point in the history
--
MOS_MIGRATED_REVID=139569372
  • Loading branch information
brandjon authored and meteorcloudy committed Nov 18, 2016
1 parent ef5ceef commit 894550d
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/docgen/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib:java-rules",
"//src/main/java/com/google/devtools/build/lib:packages",
"//src/main/java/com/google/devtools/build/lib:skylarkinterface",
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/build/lib/rules/apple",
"//src/main/java/com/google/devtools/build/lib/rules/cpp",
"//src/main/java/com/google/devtools/common/options",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.devtools.build.docgen.skylark.SkylarkBuiltinMethodDoc;
import com.google.devtools.build.docgen.skylark.SkylarkJavaMethodDoc;
import com.google.devtools.build.docgen.skylark.SkylarkModuleDoc;
import com.google.devtools.build.lib.actions.AbstractAction;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.rules.SkylarkModules;
import com.google.devtools.build.lib.rules.SkylarkRuleContext;
Expand Down Expand Up @@ -189,6 +190,8 @@ private static Map<SkylarkModule, Class<?>> collectBuiltinJavaObjects(String ...
collectBuiltinModule(modules, SkylarkRuleContext.class);
collectBuiltinModule(modules, TransitiveInfoCollection.class);

collectBuiltinModule(modules, AbstractAction.class);

collectBuiltinModule(modules, AppleConfiguration.class);
collectBuiltinModule(modules, CppConfiguration.class);
collectBuiltinModule(modules, JavaConfiguration.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.Printer;
import com.google.devtools.build.lib.syntax.SkylarkDict;
Expand All @@ -52,8 +53,12 @@
@Immutable @ThreadSafe
@SkylarkModule(
name = "Action",
doc = "Base class for actions.",
documented = false)
category = SkylarkModuleCategory.BUILTIN,
doc = "An action created on a <a href=\"ctx.html\">ctx</a> object. You can retrieve these "
+ "using the <a href=\"globals.html#Actions\">Actions</a> provider. Some fields are only "
+ "applicable for certain kinds of actions. Fields that are inapplicable are set to "
+ "<code>None</code>."
)
public abstract class AbstractAction implements Action, SkylarkValue {

/**
Expand Down Expand Up @@ -508,7 +513,9 @@ public SkylarkNestedSet getSkylarkOutputs() {
@SkylarkCallable(
name = "argv",
doc = "For actions created by <a href=\"ctx.html#action\">ctx.action()</a>, an immutable "
+ "list of the command line arguments. For all other actions, None.",
+ "list of the arguments for the command line to be executed. Note that when using the "
+ "shell (i.e., when <a href=\"ctx.html#action.executable\">executable</a> is not set), "
+ "the first two arguments will be the shell path and <code>\"-c\"</code>.",
structField = true,
allowReturnNones = true)
public SkylarkList<String> getSkylarkArgv() {
Expand All @@ -519,7 +526,7 @@ public SkylarkList<String> getSkylarkArgv() {
name = "content",
doc = "For actions created by <a href=\"ctx.html#file_action\">ctx.file_action()</a> or "
+ "<a href=\"ctx.html#template_action\">ctx.template_action()</a>, the contents of the "
+ "file to be written. For all other actions, None.",
+ "file to be written.",
structField = true,
allowReturnNones = true)
public String getSkylarkContent() throws IOException {
Expand All @@ -528,8 +535,8 @@ public String getSkylarkContent() throws IOException {

@SkylarkCallable(
name = "substitutions",
doc = "For actions created by <a href=\"ctx#template_action\">ctx.template_action()</a>, "
+ "an immutable dict holding the substitution mapping. For all other actions, None.",
doc = "For actions created by <a href=\"ctx.html#template_action\">"
+ "ctx.template_action()</a>, an immutable dict holding the substitution mapping.",
structField = true,
allowReturnNones = true)
public SkylarkDict<String, String> getSkylarkSubstitutions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* This provides a view over the actions that were created during the analysis of a rule
* (not including actions for its transitive dependencies).
*/
public final class ActionsProvider{
public final class ActionsProvider {

public static final SkylarkClassObjectConstructor ACTIONS_PROVIDER =
SkylarkClassObjectConstructor.createNative("Actions");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,17 @@ public Object getDefault(AttributeMap rule) {
// configured BaseFunction, rather than defining a new BuiltinFunction. This should wait for
// better support from the Skylark/Java interface, or perhaps support for first-class modules.
@SkylarkSignature(name = "Actions", returnType = SkylarkClassObjectConstructor.class, doc =
"Provides access to the actions generated by a rule. This is designed for testing rules, "
+ "and should not be accessed outside of test logic. This provider is only available for "
+ "targets generated by rules marked with <pre class=\"language-python\">"
+ "_skylark_testable=True</pre>."
"<i>(Note: This is a provider type. Don't instantiate it yourself; use it to retrieve a "
+ "provider object from a <a href=\"Target.html\">Target</a>.)</i>"
+ "<br/><br/>"
+ "Provides access to the <a href=\"Action.html\">actions</a> generated by a rule. There "
+ "is one field, <code>by_file</code>, which is a dictionary from an output of the rule "
+ "to its corresponding generating action. "
+ "<br/><br/>"
+ "This is designed for testing rules, and should not be accessed outside of test logic. "
+ "This provider is only available for targets generated by rules that have "
+ "<a href=\"globals.html#rule._skylark_testable\">_skylark_testable</a> set to "
+ "<code>True</code>."
)
private static final SkylarkClassObjectConstructor actions = ActionsProvider.ACTIONS_PROVIDER;

Expand Down Expand Up @@ -330,13 +337,13 @@ public SkylarkClassObjectConstructor invoke(Location location) {
type = Boolean.class,
defaultValue = "False",
doc =
"<i>(Experimental)</i> "
"<i>(Experimental)</i><br/><br/>"
+ "If true, this rule will expose its actions for inspection by rules that depend "
+ "on it via an <a href=\"ActionsSkylarkApiProvider.html\">actions</a> provider."
+ "on it via an <a href=\"globals.html#Actions\">Actions</a> provider. "
+ "The provider is also available to the rule itself by calling "
+ "<code>ctx.created_actions()</code>."
+ ""
+ "<p>This should only be used for testing the analysis-time behavior of Skylark "
+ "<a href=\"ctx.html#created_actions\">ctx.created_actions()</a>."
+ "<br/><br/>"
+ "This should only be used for testing the analysis-time behavior of Skylark "
+ "rules. This flag may be removed in the future."
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,14 +435,15 @@ public static SkylarkClassObjectConstructor getDefaultProvider() {
}

@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. "
doc = "For rules with <a href=\"globals.html#rule._skylark_testable\">_skylark_testable"
+ "</a> set to <code>True</code>, this returns an "
+ "<a href=\"globals.html#Actions\">Actions</a> provider representing all actions "
+ "created so far for the current rule. For all other rules, returns <code>None</code>. "
+ "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.")
+ "<br/><br/>"
+ "This is intended to help write tests for rule-implementation helper functions, which "
+ "may take in a<code>ctx</code> object and create actions on it.")
public Object createdActions() {
if (ruleContext.getRule().getRuleClassObject().isSkylarkTestable()) {
return ActionsProvider.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ public Runtime.NoneType invoke(
"Expands all <code>$(location ...)</code> templates in the given string by replacing "
+ "<code>$(location //x)</code> with the path of the output file of target //x. "
+ "Expansion only works for labels that point to direct dependencies of this rule or that "
+ "are explicitly listed in the optional argument <code>targets</code>.<br/>"
+ "are explicitly listed in the optional argument <code>targets</code>. "
+ "<br/><br/>"
+ "<code>$(location ...)</code> will cause an error if the referenced target has multiple "
+ "outputs. In this case, please use <code>$(locations ...)</code> since it produces a space-"
+ "separated list of output paths. It can be safely used for a single output file, too.",
Expand Down

0 comments on commit 894550d

Please sign in to comment.