Skip to content

Commit fb04c5b

Browse files
ulfjackcopybara-github
authored andcommitted
Refactor test action preparation
Move all deletion / directory creation to prepareFileSystem. PiperOrigin-RevId: 245374483
1 parent 48c3be8 commit fb04c5b

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,10 @@ public Path getXmlOutputPath() {
923923
return getPath(xmlOutputPath);
924924
}
925925

926+
public Path getCoverageDirectory() {
927+
return getPath(TestRunnerAction.this.getCoverageDirectory());
928+
}
929+
926930
public Path getCoverageDataPath() {
927931
return getPath(getCoverageData().getExecPath());
928932
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ public TestRunnerSpawn createTestRunnerSpawn(
9797
TestRunnerAction action, ActionExecutionContext actionExecutionContext)
9898
throws ExecException, InterruptedException {
9999
Path execRoot = actionExecutionContext.getExecRoot();
100-
Path coverageDir = execRoot.getRelative(action.getCoverageDirectory());
101100
Path runfilesDir =
102101
getLocalRunfilesDirectory(
103102
action,
@@ -143,7 +142,7 @@ public TestRunnerSpawn createTestRunnerSpawn(
143142
ImmutableList.copyOf(action.getSpawnOutputs()),
144143
localResourceUsage);
145144
return new StandaloneTestRunnerSpawn(
146-
action, actionExecutionContext, spawn, tmpDir, coverageDir, workingDirectory, execRoot);
145+
action, actionExecutionContext, spawn, tmpDir, workingDirectory, execRoot);
147146
}
148147

149148
private StandaloneFailedAttemptResult processFailedTestAttempt(
@@ -454,7 +453,6 @@ private final class StandaloneTestRunnerSpawn implements TestRunnerSpawn {
454453
private final ActionExecutionContext actionExecutionContext;
455454
private final Spawn spawn;
456455
private final Path tmpDir;
457-
private final Path coverageDir;
458456
private final Path workingDirectory;
459457
private final Path execRoot;
460458

@@ -463,14 +461,12 @@ private final class StandaloneTestRunnerSpawn implements TestRunnerSpawn {
463461
ActionExecutionContext actionExecutionContext,
464462
Spawn spawn,
465463
Path tmpDir,
466-
Path coverageDir,
467464
Path workingDirectory,
468465
Path execRoot) {
469466
this.testAction = testAction;
470467
this.actionExecutionContext = actionExecutionContext;
471468
this.spawn = spawn;
472469
this.tmpDir = tmpDir;
473-
this.coverageDir = coverageDir;
474470
this.workingDirectory = workingDirectory;
475471
this.execRoot = execRoot;
476472
}
@@ -483,7 +479,7 @@ public ActionExecutionContext getActionExecutionContext() {
483479
@Override
484480
public TestAttemptContinuation beginExecution()
485481
throws InterruptedException, IOException, ExecException {
486-
prepareFileSystem(testAction, tmpDir, coverageDir, workingDirectory);
482+
prepareFileSystem(testAction, actionExecutionContext.getExecRoot(), tmpDir, workingDirectory);
487483
return beginTestAttempt(testAction, spawn, actionExecutionContext, execRoot);
488484
}
489485

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.google.devtools.build.lib.analysis.test.TestConfiguration;
3333
import com.google.devtools.build.lib.analysis.test.TestResult;
3434
import com.google.devtools.build.lib.analysis.test.TestRunnerAction;
35+
import com.google.devtools.build.lib.analysis.test.TestRunnerAction.ResolvedPaths;
3536
import com.google.devtools.build.lib.analysis.test.TestTargetExecutionSettings;
3637
import com.google.devtools.build.lib.cmdline.Label;
3738
import com.google.devtools.build.lib.events.Event;
@@ -63,24 +64,32 @@ public abstract class TestStrategy implements TestActionContext {
6364
* not result in stale files.
6465
*/
6566
protected void prepareFileSystem(
66-
TestRunnerAction testAction, Path tmpDir, Path coverageDir, Path workingDirectory)
67+
TestRunnerAction testAction, Path execRoot, Path tmpDir, Path workingDirectory)
6768
throws IOException {
69+
if (tmpDir != null) {
70+
recreateDirectory(tmpDir);
71+
}
72+
if (workingDirectory != null) {
73+
workingDirectory.createDirectoryAndParents();
74+
}
75+
76+
ResolvedPaths resolvedPaths = testAction.resolve(execRoot);
6877
if (testAction.isCoverageMode()) {
69-
recreateDirectory(coverageDir);
78+
recreateDirectory(resolvedPaths.getCoverageDirectory());
7079
}
71-
recreateDirectory(tmpDir);
72-
workingDirectory.createDirectoryAndParents();
80+
81+
resolvedPaths.getBaseDir().createDirectoryAndParents();
82+
resolvedPaths.getUndeclaredOutputsDir().createDirectoryAndParents();
83+
resolvedPaths.getUndeclaredOutputsAnnotationsDir().createDirectoryAndParents();
84+
resolvedPaths.getSplitLogsDir().createDirectoryAndParents();
7385
}
7486

7587
/**
7688
* Ensures that all directories used to run test are in the correct state and their content will
7789
* not result in stale files. Only use this if no local tmp and working directory are required.
7890
*/
79-
protected void prepareFileSystem(TestRunnerAction testAction, Path coverageDir)
80-
throws IOException {
81-
if (testAction.isCoverageMode()) {
82-
recreateDirectory(coverageDir);
83-
}
91+
protected void prepareFileSystem(TestRunnerAction testAction, Path execRoot) throws IOException {
92+
prepareFileSystem(testAction, execRoot, null, null);
8493
}
8594

8695
/** Removes directory if it exists and recreates it. */

src/test/shell/bazel/bazel_test_test.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -717,12 +717,12 @@ EOF
717717
bazel test -s //dir:test &> $TEST_log || fail "expected success"
718718

719719
# Check that the undeclared outputs directory doesn't exist.
720-
outputs_dir=bazel-testlogs/dir/test/test.outputs/
721-
[ ! -d $outputs_dir ] || fail "$outputs_dir was present after test"
720+
outputs_zip=bazel-testlogs/dir/test/test.outputs/outputs.zip
721+
[ ! -e $outputs_zip ] || fail "$outputs_zip was present after test"
722722

723723
# Check that the undeclared outputs manifest directory doesn't exist.
724-
outputs_manifest_dir=bazel-testlogs/dir/test/test.outputs_manifest/
725-
[ ! -d $outputs_manifest_dir ] || fail "$outputs_manifest_dir was present after test"
724+
outputs_manifest=bazel-testlogs/dir/test/test.outputs_manifest/MANIFEST
725+
[ ! -d $outputs_manifest ] || fail "$outputs_manifest was present after test"
726726
}
727727

728728
function test_test_with_nobuild_runfile_manifests() {

0 commit comments

Comments
 (0)