Skip to content

Commit 4009b17

Browse files
justinhorvitzcopybara-github
authored andcommitted
Use ArtifactPathResolver when deleting outputs.
PiperOrigin-RevId: 338961970
1 parent 364a867 commit 4009b17

9 files changed

Lines changed: 28 additions & 15 deletions

File tree

src/main/java/com/google/devtools/build/lib/actions/AbstractAction.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,16 @@ public void repr(Printer printer) {
353353
* @param execRoot the exec root in which this action is executed
354354
* @param bulkDeleter a helper to bulk delete outputs to avoid delegating to the filesystem
355355
*/
356-
protected void deleteOutputs(Path execRoot, @Nullable BulkDeleter bulkDeleter)
356+
protected void deleteOutputs(
357+
Path execRoot, ArtifactPathResolver pathResolver, @Nullable BulkDeleter bulkDeleter)
357358
throws IOException, InterruptedException {
358359
if (bulkDeleter != null) {
359360
bulkDeleter.bulkDelete(Artifact.asPathFragments(getOutputs()));
360361
return;
361362
}
362363

363364
for (Artifact output : getOutputs()) {
364-
deleteOutput(output.getPath(), output.getRoot());
365+
deleteOutput(pathResolver.toPath(output), output.getRoot());
365366
}
366367
}
367368

@@ -457,9 +458,10 @@ protected void checkOutputsForDirectories(ActionExecutionContext actionExecution
457458
}
458459

459460
@Override
460-
public void prepare(Path execRoot, @Nullable BulkDeleter bulkDeleter)
461+
public void prepare(
462+
Path execRoot, ArtifactPathResolver pathResolver, @Nullable BulkDeleter bulkDeleter)
461463
throws IOException, InterruptedException {
462-
deleteOutputs(execRoot, bulkDeleter);
464+
deleteOutputs(execRoot, pathResolver, bulkDeleter);
463465
}
464466

465467
@Override

src/main/java/com/google/devtools/build/lib/actions/Action.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public interface Action extends ActionExecutionMetadata {
8585
* @throws IOException if there is an error deleting the outputs.
8686
* @throws InterruptedException if the execution is interrupted
8787
*/
88-
void prepare(Path execRoot, @Nullable BulkDeleter bulkDeleter)
88+
void prepare(Path execRoot, ArtifactPathResolver pathResolver, @Nullable BulkDeleter bulkDeleter)
8989
throws IOException, InterruptedException;
9090

9191
/**

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,10 @@ protected String getRawProgressMessage() {
482482
* the test log base name with arbitrary prefix and extension.
483483
*/
484484
@Override
485-
protected void deleteOutputs(Path execRoot, @Nullable BulkDeleter bulkDeleter)
485+
protected void deleteOutputs(
486+
Path execRoot, ArtifactPathResolver pathResolver, @Nullable BulkDeleter bulkDeleter)
486487
throws IOException, InterruptedException {
487-
super.deleteOutputs(execRoot, bulkDeleter);
488+
super.deleteOutputs(execRoot, pathResolver, bulkDeleter);
488489

489490
// We do not rely on globs, as it causes quadratic behavior in --runs_per_test and test
490491
// shard count.

src/main/java/com/google/devtools/build/lib/bazel/BazelWorkspaceStatusModule.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.devtools.build.lib.actions.ActionOwner;
2727
import com.google.devtools.build.lib.actions.ActionResult;
2828
import com.google.devtools.build.lib.actions.Artifact;
29+
import com.google.devtools.build.lib.actions.ArtifactPathResolver;
2930
import com.google.devtools.build.lib.analysis.BlazeDirectories;
3031
import com.google.devtools.build.lib.analysis.BuildInfo;
3132
import com.google.devtools.build.lib.analysis.BuildInfoEvent;
@@ -154,11 +155,13 @@ private static byte[] printStatusMap(Map<String, String> map) {
154155
}
155156

156157
@Override
157-
public void prepare(Path execRoot, @Nullable BulkDeleter bulkDeleter) throws IOException {
158+
public void prepare(
159+
Path execRoot, ArtifactPathResolver pathResolver, @Nullable BulkDeleter bulkDeleter)
160+
throws IOException {
158161
// The default implementation of this method deletes all output files; override it to keep
159162
// the old stableStatus around. This way we can reuse the existing file (preserving its mtime)
160163
// if the contents haven't changed.
161-
deleteOutput(volatileStatus.getPath(), volatileStatus.getRoot());
164+
deleteOutput(pathResolver.toPath(volatileStatus), volatileStatus.getRoot());
162165
}
163166

164167
@Override

src/main/java/com/google/devtools/build/lib/rules/cpp/CreateIncSymlinkAction.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
// Copyright 2016 The Bazel Authors. All rights reserved.
32
//
43
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,6 +24,7 @@
2524
import com.google.devtools.build.lib.actions.ActionOwner;
2625
import com.google.devtools.build.lib.actions.ActionResult;
2726
import com.google.devtools.build.lib.actions.Artifact;
27+
import com.google.devtools.build.lib.actions.ArtifactPathResolver;
2828
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
2929
import com.google.devtools.build.lib.collect.nestedset.Order;
3030
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
@@ -65,12 +65,13 @@ public CreateIncSymlinkAction(
6565
}
6666

6767
@Override
68-
public void prepare(Path execRoot, @Nullable BulkDeleter bulkDeleter)
68+
public void prepare(
69+
Path execRoot, ArtifactPathResolver pathResolver, @Nullable BulkDeleter bulkDeleter)
6970
throws IOException, InterruptedException {
7071
if (includePath.isDirectory(Symlinks.NOFOLLOW)) {
7172
includePath.deleteTree();
7273
}
73-
super.prepare(execRoot, bulkDeleter);
74+
super.prepare(execRoot, pathResolver, bulkDeleter);
7475
}
7576

7677
@Override

src/main/java/com/google/devtools/build/lib/rules/java/JavaCompileAction.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,10 @@ public ActionContinuationOrResult execute()
621621
// Fall back to running with the full classpath. This requires first deleting potential
622622
// artifacts generated by the reduced action and clearing the metadata caches.
623623
try {
624-
deleteOutputs(actionExecutionContext.getExecRoot(), /* bulkDeleter= */ null);
624+
deleteOutputs(
625+
actionExecutionContext.getExecRoot(),
626+
actionExecutionContext.getPathResolver(),
627+
/*bulkDeleter=*/ null);
625628
} catch (IOException e) {
626629
throw new EnvironmentalExecException(
627630
e,

src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.google.common.collect.Iterables;
2525
import com.google.common.collect.Lists;
2626
import com.google.devtools.build.lib.actions.Artifact;
27+
import com.google.devtools.build.lib.actions.ArtifactPathResolver;
2728
import com.google.devtools.build.lib.actions.CommandLine;
2829
import com.google.devtools.build.lib.actions.CommandLineExpansionException;
2930
import com.google.devtools.build.lib.actions.EnvironmentalExecException;
@@ -437,7 +438,7 @@ public BlazeCommandResult exec(CommandEnvironment env, OptionsParsingResult opti
437438
workingDir = env.getExecRoot();
438439

439440
try {
440-
testAction.prepare(env.getExecRoot(), /* bulkDeleter= */ null);
441+
testAction.prepare(env.getExecRoot(), ArtifactPathResolver.IDENTITY, /*bulkDeleter=*/ null);
441442
} catch (IOException e) {
442443
return reportAndCreateFailureResult(
443444
env,

src/main/java/com/google/devtools/build/lib/skyframe/SkyframeActionExecutor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,7 @@ public ActionStepOrResult run(Environment env) throws InterruptedException {
931931
// keep previous outputs in place.
932932
action.prepare(
933933
actionExecutionContext.getExecRoot(),
934+
actionExecutionContext.getPathResolver(),
934935
outputService != null ? outputService.bulkDeleter() : null);
935936
} catch (IOException e) {
936937
logger.atWarning().withCause(e).log(

src/test/java/com/google/devtools/build/lib/rules/cpp/CreateIncSymlinkActionTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.devtools.build.lib.actions.ActionExecutionContext.LostInputsCheck;
2323
import com.google.devtools.build.lib.actions.ActionKeyContext;
2424
import com.google.devtools.build.lib.actions.Artifact;
25+
import com.google.devtools.build.lib.actions.ArtifactPathResolver;
2526
import com.google.devtools.build.lib.actions.ArtifactRoot;
2627
import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
2728
import com.google.devtools.build.lib.actions.util.DummyExecutor;
@@ -154,7 +155,7 @@ public void testFileRemoved() throws Exception {
154155
Path extra = rootDirectory.getRelative("out/extra");
155156
FileSystemUtils.createEmptyFile(extra);
156157
assertThat(extra.exists()).isTrue();
157-
action.prepare(rootDirectory, /*bulkDeleter=*/ null);
158+
action.prepare(rootDirectory, ArtifactPathResolver.IDENTITY, /*bulkDeleter=*/ null);
158159
assertThat(extra.exists()).isFalse();
159160
}
160161

0 commit comments

Comments
 (0)