diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleImplementationFunctions.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleImplementationFunctions.java | 55 |
1 files changed, 27 insertions, 28 deletions
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 4103b81613..7b69e37684 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 @@ -52,6 +52,7 @@ import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.syntax.EvalUtils; import com.google.devtools.build.lib.syntax.Printer; import com.google.devtools.build.lib.syntax.Runtime; +import com.google.devtools.build.lib.syntax.SkylarkDict; import com.google.devtools.build.lib.syntax.SkylarkList; import com.google.devtools.build.lib.syntax.SkylarkList.MutableList; import com.google.devtools.build.lib.syntax.SkylarkList.Tuple; @@ -143,8 +144,8 @@ public class SkylarkRuleImplementationFunctions { defaultValue = "None", doc = "shell command to execute. It is usually preferable to " - + "use <code>executable</code> instead. Arguments are available with <code>$1</code>, " - + "<code>$2</code>, etc." + + "use <code>executable</code> instead. " + + "Arguments are available with <code>$1</code>, <code>$2</code>, etc." ), @Param( name = "progress_message", @@ -163,14 +164,14 @@ public class SkylarkRuleImplementationFunctions { ), @Param( name = "env", - type = Map.class, + type = SkylarkDict.class, noneable = true, defaultValue = "None", doc = "sets the dictionary of environment variables" ), @Param( name = "execution_requirements", - type = Map.class, + type = SkylarkDict.class, noneable = true, defaultValue = "None", doc = @@ -179,7 +180,7 @@ public class SkylarkRuleImplementationFunctions { ), @Param( name = "input_manifests", - type = Map.class, + type = SkylarkDict.class, noneable = true, defaultValue = "None", doc = @@ -203,7 +204,7 @@ public class SkylarkRuleImplementationFunctions { Boolean useDefaultShellEnv, Object envO, Object executionRequirementsO, - Object inputManifestsO, + Object inputManifests, Location loc) throws EvalException, ConversionException { SpawnAction.Builder builder = new SpawnAction.Builder(); @@ -289,14 +290,11 @@ public class SkylarkRuleImplementationFunctions { String.class, "execution_requirements"))); } - if (inputManifestsO != Runtime.NONE) { + if (inputManifests instanceof SkylarkDict) { for (Map.Entry<PathFragment, Artifact> entry : - castMap( - inputManifestsO, - PathFragment.class, - Artifact.class, - "input manifest file map") - .entrySet()) { + ((SkylarkDict<?, ?>) inputManifests) + .getContents(PathFragment.class, Artifact.class, "input manifest file map") + .entrySet()) { builder.addInputManifest(entry.getValue(), entry.getKey()); } } @@ -459,7 +457,7 @@ public class SkylarkRuleImplementationFunctions { doc = "the template file"), @Param(name = "output", type = Artifact.class, doc = "the output file"), - @Param(name = "substitutions", type = Map.class, + @Param(name = "substitutions", type = SkylarkDict.class, doc = "substitutions to make when expanding the template")}, optionalNamedOnly = { @Param(name = "executable", type = Boolean.class, @@ -467,23 +465,23 @@ public class SkylarkRuleImplementationFunctions { private static final BuiltinFunction createTemplateAction = new BuiltinFunction("template_action", Arrays.<Object>asList(false)) { public TemplateExpansionAction invoke(SkylarkRuleContext ctx, - Artifact template, Artifact output, Map<?, ?> substitutionsO, Boolean executable) + Artifact template, Artifact output, SkylarkDict<?, ?> substitutions, Boolean executable) throws EvalException, ConversionException { - ImmutableList.Builder<Substitution> substitutions = ImmutableList.builder(); - for (Map.Entry<String, String> substitution : castMap( - substitutionsO, String.class, String.class, "substitutions").entrySet()) { + ImmutableList.Builder<Substitution> substitutionsBuilder = ImmutableList.builder(); + for (Map.Entry<String, String> substitution : substitutions.getContents( + String.class, String.class, "substitutions").entrySet()) { // ParserInputSource.create(Path) uses Latin1 when reading BUILD files, which might // contain UTF-8 encoded symbols as part of template substitution. // As a quick fix, the substitution values are corrected before being passed on. // In the long term, fixing ParserInputSource.create(Path) would be a better approach. - substitutions.add(Substitution.of( + substitutionsBuilder.add(Substitution.of( substitution.getKey(), convertLatin1ToUtf8(substitution.getValue()))); } TemplateExpansionAction action = new TemplateExpansionAction( ctx.getRuleContext().getActionOwner(), template, output, - substitutions.build(), + substitutionsBuilder.build(), executable); ctx.getRuleContext().registerAction(action); return action; @@ -574,7 +572,8 @@ public class SkylarkRuleImplementationFunctions { // TODO(bazel-team): find a better way to typecheck this argument. @SuppressWarnings("unchecked") - private static Map<Label, Iterable<Artifact>> checkLabelDict(Map<?, ?> labelDict, Location loc) + private static Map<Label, Iterable<Artifact>> checkLabelDict( + Map<?, ?> labelDict, Location loc) throws EvalException { for (Map.Entry<?, ?> entry : labelDict.entrySet()) { Object key = entry.getKey(); @@ -633,7 +632,7 @@ public class SkylarkRuleImplementationFunctions { ), @Param( name = "make_variables", - type = Map.class, // dict(string, string) + type = SkylarkDict.class, // dict(string, string) noneable = true, doc = "make variables to expand, or None" ), @@ -646,7 +645,7 @@ public class SkylarkRuleImplementationFunctions { ), @Param( name = "label_dict", - type = Map.class, + type = SkylarkDict.class, defaultValue = "{}", doc = "dictionary of resolved labels and the corresponding list of Files " @@ -658,24 +657,24 @@ public class SkylarkRuleImplementationFunctions { private static final BuiltinFunction resolveCommand = new BuiltinFunction("resolve_command") { @SuppressWarnings("unchecked") - public Tuple invoke( + public Tuple<Object> invoke( SkylarkRuleContext ctx, String command, Object attributeO, Boolean expandLocations, Object makeVariablesO, SkylarkList tools, - Map<?, ?> labelDictM, + SkylarkDict<?, ?> labelDict, Location loc, Environment env) throws ConversionException, EvalException { Label ruleLabel = ctx.getLabel(); - Map<Label, Iterable<Artifact>> labelDict = checkLabelDict(labelDictM, loc); + Map<Label, Iterable<Artifact>> labelDictM = checkLabelDict(labelDict, loc); // The best way to fix this probably is to convert CommandHelper to Skylark. CommandHelper helper = new CommandHelper( ctx.getRuleContext(), tools.getContents(TransitiveInfoCollection.class, "tools"), - ImmutableMap.copyOf(labelDict)); + ImmutableMap.copyOf(labelDictM)); String attribute = Type.STRING.convertOptional(attributeO, "attribute", ruleLabel); if (expandLocations) { command = helper.resolveCommandAndExpandLabels( @@ -689,7 +688,7 @@ public class SkylarkRuleImplementationFunctions { List<Artifact> inputs = new ArrayList<>(); inputs.addAll(helper.getResolvedTools()); List<String> argv = helper.buildCommandLine(command, inputs, SCRIPT_SUFFIX); - return Tuple.of( + return Tuple.<Object>of( new MutableList(inputs, env), new MutableList(argv, env), helper.getRemoteRunfileManifestMap()); |