From c82224f4945118392488e508f179cdf1918491bd Mon Sep 17 00:00:00 2001 From: Francois-Rene Rideau Date: Thu, 15 Oct 2015 05:28:05 +0000 Subject: [PATCH] Remove command_helper, use resolve_command instead Eliminate side-effect in command_line_srcs and hide the internal class. -- MOS_MIGRATED_REVID=105480701 --- .../build/lib/analysis/CommandHelper.java | 9 ----- .../SkylarkRuleImplementationFunctions.java | 38 ------------------- ...kylarkRuleImplementationFunctionsTest.java | 7 ---- 3 files changed, 54 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java b/src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java index 0a48b2c50fabc9..61e88e15657da1 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/CommandHelper.java @@ -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; @@ -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.
" - + "A helper class to create shell commands.") public final class CommandHelper { /** @@ -146,12 +141,10 @@ public CommandHelper( this.labelMap = labelMapBuilder.build(); } - @SkylarkCallable(name = "resolved_tools", doc = "Experimental.", structField = true) public List getResolvedTools() { return resolvedTools; } - @SkylarkCallable(name = "runfiles_manifests", doc = "Experimental.", structField = true) public ImmutableMap getRemoteRunfileManifestMap() { return remoteRunfileManifestMap; } @@ -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( @@ -292,7 +284,6 @@ public List 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 buildCommandLine( String command, List inputs, String scriptPostFix) { Pair, Artifact> argvAndScriptFile = buildCommandLineMaybeWithScriptFile( diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleImplementationFunctions.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleImplementationFunctions.java index 5bf0ac617dcb30..cecf3f5c7af59f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleImplementationFunctions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleImplementationFunctions.java @@ -521,44 +521,6 @@ private static Map> checkLabelDict(Map labelDict return (Map>) 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> labelDict) - throws ConversionException, EvalException { - return new CommandHelper( - ctx.getRuleContext(), - castList(tools, TransitiveInfoCollection.class), - ImmutableMap.copyOf(labelDict)); - } - }; - @SkylarkSignature( name = "resolve_command", doc = "Experimental." diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java index 31191f5cf0a082..c753d6869e38b5 100644 --- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java +++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java @@ -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; @@ -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]");