diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/analysis')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkActionFactory.java | 94 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java | 24 |
2 files changed, 102 insertions, 16 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); + } } } diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java index 45b9f02d9b..73c5a89e5b 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java @@ -1087,6 +1087,21 @@ public final class SkylarkRuleContext 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 of the any tools needed by the action. Tools are inputs with additional " + + "runfiles that are automatically made available to the action." + ), + @Param( name = "arguments", allowedTypes = { @ParamType(type = SkylarkList.class), @@ -1186,6 +1201,7 @@ public final class SkylarkRuleContext implements SkylarkValue { SkylarkList outputs, Object inputs, Object executableUnchecked, + Object toolsUnchecked, Object arguments, Object mnemonicUnchecked, Object commandUnchecked, @@ -1210,19 +1226,22 @@ public final class SkylarkRuleContext implements SkylarkValue { outputs, inputs, executableUnchecked, + toolsUnchecked, arguments, mnemonicUnchecked, progressMessage, useDefaultShellEnv, envUnchecked, executionRequirementsUnchecked, - inputManifestsUnchecked); + inputManifestsUnchecked, + loc); } else { actions() .runShell( outputs, inputs, + toolsUnchecked, arguments, mnemonicUnchecked, commandUnchecked, @@ -1230,7 +1249,8 @@ public final class SkylarkRuleContext implements SkylarkValue { useDefaultShellEnv, envUnchecked, executionRequirementsUnchecked, - inputManifestsUnchecked); + inputManifestsUnchecked, + loc); } return Runtime.NONE; } |