diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkActionFactory.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkActionFactory.java | 94 |
1 files changed, 80 insertions, 14 deletions
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 bc430f9340..691a1e23a9 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 @@ -306,7 +306,7 @@ public class SkylarkActionFactory implements SkylarkValue { defaultValue = "[]", named = true, positional = false, - doc = "List of the input files of the action." + doc = "List or depset of the input files of the action." ), @Param( name = "executable", @@ -320,6 +320,21 @@ public class SkylarkActionFactory implements SkylarkValue { doc = "The executable file to be called by the action." ), @Param( + name = "tools", + allowedTypes = { + @ParamType(type = SkylarkList.class), + @ParamType(type = SkylarkNestedSet.class), + }, + generic1 = Artifact.class, + defaultValue = "None", + named = true, + positional = false, + noneable = true, + doc = + "List or depset of any tools needed by the action. Tools are inputs with additional " + + "runfiles that are automatically made available to the action." + ), + @Param( name = "arguments", type = Object.class, allowedTypes = { @@ -396,19 +411,22 @@ public class SkylarkActionFactory implements SkylarkValue { "(Experimental) sets the input runfiles metadata; " + "they are typically generated by resolve_command." ) - } + }, + useLocation = true ) public void run( SkylarkList outputs, Object inputs, Object executableUnchecked, + Object toolsUnchecked, Object arguments, Object mnemonicUnchecked, Object progressMessage, Boolean useDefaultShellEnv, Object envUnchecked, Object executionRequirementsUnchecked, - Object inputManifestsUnchecked) + Object inputManifestsUnchecked, + Location location) throws EvalException { context.checkMutable("actions.run"); SpawnAction.Builder builder = new SpawnAction.Builder(); @@ -434,8 +452,18 @@ public class SkylarkActionFactory implements SkylarkValue { + EvalUtils.getDataTypeName(executableUnchecked) + " instead"); } - registerSpawnAction(outputs, inputs, mnemonicUnchecked, progressMessage, useDefaultShellEnv, - envUnchecked, executionRequirementsUnchecked, inputManifestsUnchecked, builder); + registerSpawnAction( + outputs, + inputs, + toolsUnchecked, + mnemonicUnchecked, + progressMessage, + useDefaultShellEnv, + envUnchecked, + executionRequirementsUnchecked, + inputManifestsUnchecked, + location, + builder); } /** @@ -481,7 +509,22 @@ public class SkylarkActionFactory implements SkylarkValue { defaultValue = "[]", named = true, positional = false, - doc = "List of the input files of the action." + doc = "List or depset of the input files of the action." + ), + @Param( + name = "tools", + allowedTypes = { + @ParamType(type = SkylarkList.class), + @ParamType(type = SkylarkNestedSet.class), + }, + generic1 = Artifact.class, + defaultValue = "None", + named = true, + positional = false, + noneable = true, + doc = + "List or depset of any tools needed by the action. Tools are inputs with additional " + + "runfiles that are automatically made available to the action." ), @Param( name = "arguments", @@ -581,11 +624,13 @@ public class SkylarkActionFactory implements SkylarkValue { "(Experimental) sets the input runfiles metadata; " + "they are typically generated by resolve_command." ) - } + }, + useLocation = true ) public void runShell( SkylarkList outputs, Object inputs, + Object toolsUnchecked, Object arguments, Object mnemonicUnchecked, Object commandUnchecked, @@ -593,7 +638,8 @@ public class SkylarkActionFactory implements SkylarkValue { Boolean useDefaultShellEnv, Object envUnchecked, Object executionRequirementsUnchecked, - Object inputManifestsUnchecked) + Object inputManifestsUnchecked, + Location location) throws EvalException { context.checkMutable("actions.run_shell"); @@ -643,12 +689,14 @@ public class SkylarkActionFactory implements SkylarkValue { registerSpawnAction( outputs, inputs, + toolsUnchecked, mnemonicUnchecked, progressMessage, useDefaultShellEnv, envUnchecked, executionRequirementsUnchecked, inputManifestsUnchecked, + location, builder); } @@ -694,12 +742,14 @@ public class SkylarkActionFactory implements SkylarkValue { private void registerSpawnAction( SkylarkList outputs, Object inputs, + Object toolsUnchecked, Object mnemonicUnchecked, Object progressMessage, Boolean useDefaultShellEnv, Object envUnchecked, Object executionRequirementsUnchecked, Object inputManifestsUnchecked, + Location location, SpawnAction.Builder builder) throws EvalException { Iterable<Artifact> inputArtifacts; @@ -713,12 +763,28 @@ public class SkylarkActionFactory implements SkylarkValue { } builder.addOutputs(outputs.getContents(Artifact.class, "outputs")); - // The actual command can refer to an executable from the inputs, which could require - // some runfiles. Consequently, we add the runfiles of all inputs of this action manually. - for (Artifact current : inputArtifacts) { - FilesToRunProvider provider = context.getExecutableRunfiles(current); - if (provider != null) { - builder.addTool(provider); + if (toolsUnchecked != Runtime.NONE) { + final Iterable<Artifact> toolsIterable; + if (toolsUnchecked instanceof SkylarkList) { + toolsIterable = ((SkylarkList) toolsUnchecked).getContents(Artifact.class, "tools"); + } else { + toolsIterable = ((SkylarkNestedSet) toolsUnchecked).getSet(Artifact.class); + } + for (Artifact artifact : toolsIterable) { + builder.addInput(artifact); + FilesToRunProvider provider = context.getExecutableRunfiles(artifact); + if (provider != null) { + builder.addTool(provider); + } + } + } 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); + } } } |