Skip to content

Commit

Permalink
Remove command_helper, use resolve_command instead
Browse files Browse the repository at this point in the history
Eliminate side-effect in command_line_srcs and hide the internal class.

--
MOS_MIGRATED_REVID=105480701
  • Loading branch information
fare authored and dslomov committed Oct 15, 2015
1 parent c3738b1 commit c82224f
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import com.google.devtools.build.lib.analysis.actions.FileWriteAction;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.syntax.SkylarkCallable;
import com.google.devtools.build.lib.syntax.SkylarkModule;
import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.vfs.PathFragment;
Expand All @@ -51,9 +49,6 @@
* that will contain the same commands,
* at which point the shell script is added to the list of inputs.
*/
@SkylarkModule(name = "command_helper",
doc = "Experimental. The API will change in the future.<br>"
+ "A helper class to create shell commands.")
public final class CommandHelper {

/**
Expand Down Expand Up @@ -146,12 +141,10 @@ public CommandHelper(
this.labelMap = labelMapBuilder.build();
}

@SkylarkCallable(name = "resolved_tools", doc = "Experimental.", structField = true)
public List<Artifact> getResolvedTools() {
return resolvedTools;
}

@SkylarkCallable(name = "runfiles_manifests", doc = "Experimental.", structField = true)
public ImmutableMap<PathFragment, Artifact> getRemoteRunfileManifestMap() {
return remoteRunfileManifestMap;
}
Expand Down Expand Up @@ -195,7 +188,6 @@ public String resolveCommandAndExpandLabels(
* Resolves the 'cmd' attribute, and expands known locations for $(location)
* variables.
*/
@SkylarkCallable(doc = "Experimental.")
public String resolveCommandAndExpandLabels(
Boolean supportLegacyExpansion, Boolean allowDataInLabel) {
return resolveCommandAndExpandLabels(
Expand Down Expand Up @@ -292,7 +284,6 @@ public List<String> buildCommandLine(
* command line is longer than the allowed maximum {@link #maxCommandLength}.
* Fixes up the input artifact list with the created bash script when required.
*/
@SkylarkCallable(doc = "Experimental.")
public List<String> buildCommandLine(
String command, List<Artifact> inputs, String scriptPostFix) {
Pair<List<String>, Artifact> argvAndScriptFile = buildCommandLineMaybeWithScriptFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,44 +521,6 @@ private static Map<Label, Iterable<Artifact>> checkLabelDict(Map<?, ?> labelDict
return (Map<Label, Iterable<Artifact>>) labelDict;
}

@SkylarkSignature(
name = "command_helper",
doc = "Experimental. Creates a command helper class.",
objectType = SkylarkRuleContext.class,
returnType = CommandHelper.class,
mandatoryPositionals = {
@Param(name = "self", type = SkylarkRuleContext.class, doc = "this RuleContext"),
@Param(
name = "tools",
type = SkylarkList.class,
generic1 = TransitiveInfoCollection.class,
doc = "list of tools (list of targets)"
),
@Param(
name = "label_dict",
type = Map.class,
defaultValue = "{}",
doc =
"dictionary of resolved labels and the corresponding list of Files "
+ "(a dict of Label : list of Files)"
)
}
)
private static final BuiltinFunction createCommandHelper =
new BuiltinFunction("command_helper") {
@SuppressWarnings("unchecked")
// TODO(bazel-team): this cast to Map is unchecked and is not safe.
// The best way to fix this probably is to convert CommandHelper to Skylark.
public CommandHelper invoke(
SkylarkRuleContext ctx, SkylarkList tools, Map<Label, Iterable<Artifact>> labelDict)
throws ConversionException, EvalException {
return new CommandHelper(
ctx.getRuleContext(),
castList(tools, TransitiveInfoCollection.class),
ImmutableMap.copyOf(labelDict));
}
};

@SkylarkSignature(
name = "resolve_command",
doc = "Experimental."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.devtools.build.lib.actions.Action;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
import com.google.devtools.build.lib.analysis.CommandHelper;
import com.google.devtools.build.lib.analysis.Runfiles;
import com.google.devtools.build.lib.analysis.actions.FileWriteAction;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
Expand Down Expand Up @@ -625,12 +624,6 @@ public void testRunfilesBadKeywordArguments() throws Exception {
"ruleContext.runfiles(bad_keyword = '')");
}

public void testCreateCommandHelper() throws Exception {
SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
Object result = evalRuleContextCode(ruleContext, "ruleContext.command_helper([], {})");
assertThat(result).isInstanceOf(CommandHelper.class);
}

public void testNsetContainsList() throws Exception {
checkErrorContains(
"sets cannot contain items of type 'list'", "set() + [ruleContext.files.srcs]");
Expand Down

0 comments on commit c82224f

Please sign in to comment.