From aaf11e91a02a2f42d8bf26cce76df941c8afc8e2 Mon Sep 17 00:00:00 2001 From: tomlu Date: Sat, 2 Jun 2018 10:20:16 -0700 Subject: Make tools in action inputs an error. Supporting tools in inputs introduces a slow linear scan. Such tools should be moved to the 'tools' attribute. If --incompatible_no_support_tools_in_action_inputs is set the inputs are scanned, but a helpful error message is issued to the user. Eventually we will remove the slow scanning. Errors will surface in the execution phase instead of during analysis, and the resulting error messages will be less obvious. RELNOTES: None RELNOTES[INC]: With --incompatible_no_support_tools_in_action_inputs enabled, Skylark action inputs are no longer scanned for tools. Move any such inputs to the newly introduced 'tools' attribute. PiperOrigin-RevId: 198996093 --- .../lib/analysis/skylark/SkylarkActionFactory.java | 47 +++++++++++++++++++--- .../build/lib/packages/SkylarkSemanticsCodec.java | 2 + .../lib/packages/SkylarkSemanticsOptions.java | 17 ++++++++ .../build/lib/syntax/SkylarkSemantics.java | 5 +++ 4 files changed, 66 insertions(+), 5 deletions(-) (limited to 'src/main/java/com') diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkActionFactory.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkActionFactory.java index a13b2818f0..bb39ec5ee2 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkActionFactory.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkActionFactory.java @@ -13,7 +13,10 @@ // limitations under the License. package com.google.devtools.build.lib.analysis.skylark; +import static java.util.stream.Collectors.toList; + import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.actions.Action; @@ -392,11 +395,45 @@ public class SkylarkActionFactory implements SkylarkActionFactoryApi { } } else { // Users didn't pass 'tools', kick in compatibility modes - // Full legacy support -- add tools from inputs - for (Artifact artifact : inputArtifacts) { - FilesToRunProvider provider = context.getExecutableRunfiles(artifact); - if (provider != null) { - builder.addTool(provider); + if (skylarkSemantics.incompatibleNoSupportToolsInActionInputs()) { + // In this mode we error out if we find any tools among the inputs + List tools = null; + for (Artifact artifact : inputArtifacts) { + FilesToRunProvider provider = context.getExecutableRunfiles(artifact); + if (provider != null) { + tools = tools != null ? tools : new ArrayList<>(1); + tools.add(artifact); + } + } + if (tools != null) { + String toolsAsString = + Joiner.on(", ") + .join( + tools + .stream() + .map(Artifact::getExecPathString) + .map(s -> "'" + s + "'") + .collect(toList())); + throw new EvalException( + location, + String.format( + "Found tool(s) %s in inputs. " + + "A tool is an input with executable=True set. " + + "All tools should be passed using the 'tools' " + + "argument instead of 'inputs' in order to make their runfiles available " + + "to the action. This safety check will not be performed once the action " + + "is modified to take a 'tools' argument. " + + "To temporarily disable this check, " + + "set --incompatible_no_support_tools_in_action_inputs=false.", + toolsAsString)); + } + } else { + // Full legacy support -- add tools from inputs + for (Artifact artifact : inputArtifacts) { + FilesToRunProvider provider = context.getExecutableRunfiles(artifact); + if (provider != null) { + builder.addTool(provider); + } } } } diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsCodec.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsCodec.java index 28b3c6747a..758eb39155 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsCodec.java +++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsCodec.java @@ -53,6 +53,7 @@ public final class SkylarkSemanticsCodec implements ObjectCodec