Skip to content

Commit 807ed23

Browse files
joelebacopybara-github
authored andcommitted
Include command line for TestRunnerAction.
We achieve this by making TestRunnerAction implements the CommandAction interface. Fixes #7647 RELNOTES: None PiperOrigin-RevId: 283306323
1 parent 510d9e1 commit 807ed23

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

src/main/java/com/google/devtools/build/lib/analysis/test/TestRunnerAction.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.google.devtools.build.lib.actions.ActionResult;
3434
import com.google.devtools.build.lib.actions.Artifact;
3535
import com.google.devtools.build.lib.actions.ArtifactPathResolver;
36+
import com.google.devtools.build.lib.actions.CommandAction;
3637
import com.google.devtools.build.lib.actions.CommandLineExpansionException;
3738
import com.google.devtools.build.lib.actions.EnvironmentalExecException;
3839
import com.google.devtools.build.lib.actions.ExecException;
@@ -51,6 +52,7 @@
5152
import com.google.devtools.build.lib.buildeventstream.TestFileNameConstants;
5253
import com.google.devtools.build.lib.cmdline.Label;
5354
import com.google.devtools.build.lib.collect.ImmutableIterable;
55+
import com.google.devtools.build.lib.exec.TestStrategy;
5456
import com.google.devtools.build.lib.util.Fingerprint;
5557
import com.google.devtools.build.lib.util.LoggingUtil;
5658
import com.google.devtools.build.lib.util.Pair;
@@ -76,7 +78,7 @@
7678
*/
7779
// Not final so that we can mock it in tests.
7880
public class TestRunnerAction extends AbstractAction
79-
implements NotifyOnActionCacheHit, ExecutionInfoSpecifier {
81+
implements NotifyOnActionCacheHit, ExecutionInfoSpecifier, CommandAction {
8082
public static final PathFragment COVERAGE_TMP_ROOT = PathFragment.create("_coverage");
8183

8284
// Used for selecting subset of testcase / testmethods.
@@ -870,6 +872,22 @@ public boolean isEnableRunfiles() {
870872
return configuration.runfilesEnabled();
871873
}
872874

875+
@Override
876+
public List<String> getArguments() throws CommandLineExpansionException {
877+
return TestStrategy.expandedArgsFromAction(this);
878+
}
879+
880+
@Override
881+
public ImmutableMap<String, String> getIncompleteEnvironmentForTesting()
882+
throws ActionExecutionException {
883+
return getEnvironment().getFixedEnv().toMap();
884+
}
885+
886+
@Override
887+
public Iterable<Artifact> getPossibleInputsForTesting() {
888+
return getInputs();
889+
}
890+
873891
/** The same set of paths as the parent test action, resolved against a given exec root. */
874892
public final class ResolvedPaths {
875893
private final Path execRoot;

src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,31 @@ public final ListenableFuture<Void> getTestCancelFuture(ActionOwner owner, int s
164164
* Generates a command line to run for the test action, taking into account coverage and {@code
165165
* --run_under} settings.
166166
*
167+
* <p>Basically {@code expandedArgsFromAction}, but throws ExecException instead. This should be
168+
* used in action execution.
169+
*
167170
* @param testAction The test action.
168171
* @return the command line as string list.
169172
* @throws ExecException
170173
*/
171174
public static ImmutableList<String> getArgs(TestRunnerAction testAction) throws ExecException {
175+
try {
176+
return expandedArgsFromAction(testAction);
177+
} catch (CommandLineExpansionException e) {
178+
throw new UserExecException(e);
179+
}
180+
}
181+
182+
/**
183+
* Generates a command line to run for the test action, taking into account coverage and {@code
184+
* --run_under} settings.
185+
*
186+
* @param testAction The test action.
187+
* @return the command line as string list.
188+
* @throws CommandLineExpansionException
189+
*/
190+
public static ImmutableList<String> expandedArgsFromAction(TestRunnerAction testAction)
191+
throws CommandLineExpansionException {
172192
List<String> args = Lists.newArrayList();
173193
// TODO(ulfjack): `executedOnWindows` is incorrect for remote execution, where we need to
174194
// consider the target configuration, not the machine Bazel happens to run on. Change this to
@@ -201,11 +221,7 @@ public static ImmutableList<String> getArgs(TestRunnerAction testAction) throws
201221

202222
// Execute the test using the alias in the runfiles tree, as mandated by the Test Encyclopedia.
203223
args.add(execSettings.getExecutable().getRootRelativePath().getCallablePathString());
204-
try {
205-
Iterables.addAll(args, execSettings.getArgs().arguments());
206-
} catch (CommandLineExpansionException e) {
207-
throw new UserExecException(e);
208-
}
224+
Iterables.addAll(args, execSettings.getArgs().arguments());
209225
return ImmutableList.copyOf(args);
210226
}
211227

0 commit comments

Comments
 (0)