Skip to content

Commit

Permalink
Include command line for TestRunnerAction.
Browse files Browse the repository at this point in the history
We achieve this by making TestRunnerAction implements the CommandAction
interface.

Fixes bazelbuild#7647
RELNOTES: None
PiperOrigin-RevId: 283306323
  • Loading branch information
joeleba authored and copybara-github committed Dec 2, 2019
1 parent 510d9e1 commit 807ed23
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -870,6 +872,22 @@ public boolean isEnableRunfiles() {
return configuration.runfilesEnabled();
}

@Override
public List<String> getArguments() throws CommandLineExpansionException {
return TestStrategy.expandedArgsFromAction(this);
}

@Override
public ImmutableMap<String, String> getIncompleteEnvironmentForTesting()
throws ActionExecutionException {
return getEnvironment().getFixedEnv().toMap();
}

@Override
public Iterable<Artifact> 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;
Expand Down
26 changes: 21 additions & 5 deletions src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,31 @@ public final ListenableFuture<Void> getTestCancelFuture(ActionOwner owner, int s
* Generates a command line to run for the test action, taking into account coverage and {@code
* --run_under} settings.
*
* <p>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<String> 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<String> expandedArgsFromAction(TestRunnerAction testAction)
throws CommandLineExpansionException {
List<String> 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
Expand Down Expand Up @@ -201,11 +221,7 @@ public static ImmutableList<String> 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);
}

Expand Down

0 comments on commit 807ed23

Please sign in to comment.