diff --git a/src/main/java/com/google/devtools/build/lib/analysis/test/TestRunnerAction.java b/src/main/java/com/google/devtools/build/lib/analysis/test/TestRunnerAction.java index f5c912345b7568..4db8d46d4f5c82 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/test/TestRunnerAction.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/test/TestRunnerAction.java @@ -33,6 +33,7 @@ import com.google.devtools.build.lib.actions.ActionResult; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.ArtifactPathResolver; +import com.google.devtools.build.lib.actions.CommandAction; import com.google.devtools.build.lib.actions.CommandLineExpansionException; import com.google.devtools.build.lib.actions.EnvironmentalExecException; import com.google.devtools.build.lib.actions.ExecException; @@ -51,6 +52,7 @@ import com.google.devtools.build.lib.buildeventstream.TestFileNameConstants; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.collect.ImmutableIterable; +import com.google.devtools.build.lib.exec.TestStrategy; import com.google.devtools.build.lib.util.Fingerprint; import com.google.devtools.build.lib.util.LoggingUtil; import com.google.devtools.build.lib.util.Pair; @@ -76,7 +78,7 @@ */ // Not final so that we can mock it in tests. public class TestRunnerAction extends AbstractAction - implements NotifyOnActionCacheHit, ExecutionInfoSpecifier { + implements NotifyOnActionCacheHit, ExecutionInfoSpecifier, CommandAction { public static final PathFragment COVERAGE_TMP_ROOT = PathFragment.create("_coverage"); // Used for selecting subset of testcase / testmethods. @@ -870,6 +872,22 @@ public boolean isEnableRunfiles() { return configuration.runfilesEnabled(); } + @Override + public List getArguments() throws CommandLineExpansionException { + return TestStrategy.expandedArgsFromAction(this); + } + + @Override + public ImmutableMap getIncompleteEnvironmentForTesting() + throws ActionExecutionException { + return getEnvironment().getFixedEnv().toMap(); + } + + @Override + public Iterable getPossibleInputsForTesting() { + return getInputs(); + } + /** The same set of paths as the parent test action, resolved against a given exec root. */ public final class ResolvedPaths { private final Path execRoot; diff --git a/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java index 3430486829e266..561c6e1d659740 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java @@ -164,11 +164,31 @@ public final ListenableFuture getTestCancelFuture(ActionOwner owner, int s * Generates a command line to run for the test action, taking into account coverage and {@code * --run_under} settings. * + *

Basically {@code expandedArgsFromAction}, but throws ExecException instead. This should be + * used in action execution. + * * @param testAction The test action. * @return the command line as string list. * @throws ExecException */ public static ImmutableList getArgs(TestRunnerAction testAction) throws ExecException { + try { + return expandedArgsFromAction(testAction); + } catch (CommandLineExpansionException e) { + throw new UserExecException(e); + } + } + + /** + * Generates a command line to run for the test action, taking into account coverage and {@code + * --run_under} settings. + * + * @param testAction The test action. + * @return the command line as string list. + * @throws CommandLineExpansionException + */ + public static ImmutableList expandedArgsFromAction(TestRunnerAction testAction) + throws CommandLineExpansionException { List args = Lists.newArrayList(); // TODO(ulfjack): `executedOnWindows` is incorrect for remote execution, where we need to // consider the target configuration, not the machine Bazel happens to run on. Change this to @@ -201,11 +221,7 @@ public static ImmutableList getArgs(TestRunnerAction testAction) throws // Execute the test using the alias in the runfiles tree, as mandated by the Test Encyclopedia. args.add(execSettings.getExecutable().getRootRelativePath().getCallablePathString()); - try { - Iterables.addAll(args, execSettings.getArgs().arguments()); - } catch (CommandLineExpansionException e) { - throw new UserExecException(e); - } + Iterables.addAll(args, execSettings.getArgs().arguments()); return ImmutableList.copyOf(args); }