Skip to content

Commit 2895ce2

Browse files
committed
Store lastBuildId and compare it with the one in StartBuildResponse
1 parent 5e356f7 commit 2895ce2

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/main/java/com/google/devtools/build/lib/remote/BazelOutputService.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public class BazelOutputService implements OutputService {
8686
private final boolean verboseFailures;
8787
private final RemoteRetrier retrier;
8888
private final ReferenceCountedChannel channel;
89+
@Nullable private final String lastBuildId;
8990

9091
@Nullable private String buildId;
9192
@Nullable private PathFragment outputPathTarget;
@@ -100,7 +101,8 @@ public BazelOutputService(
100101
String remoteOutputServiceOutputPathPrefix,
101102
boolean verboseFailures,
102103
RemoteRetrier retrier,
103-
ReferenceCountedChannel channel) {
104+
ReferenceCountedChannel channel,
105+
@Nullable String lastBuildId) {
104106
this.outputBaseId = DigestUtil.hashCodeToString(md5().hashString(outputBase.toString(), UTF_8));
105107
this.execRootSupplier = execRootSupplier;
106108
this.outputPathSupplier = outputPathSupplier;
@@ -111,6 +113,7 @@ public BazelOutputService(
111113
this.verboseFailures = verboseFailures;
112114
this.retrier = retrier;
113115
this.channel = channel;
116+
this.lastBuildId = lastBuildId;
114117
}
115118

116119
public void shutdown() {
@@ -244,7 +247,12 @@ public ModifiedFileSet startBuild(
244247
outputPathTarget = constructOutputPathTarget(outputPathPrefix, response);
245248
prepareOutputPath(outputPath, outputPathTarget);
246249

247-
if (finalizeActions) {
250+
if (finalizeActions && response.hasInitialOutputPathContents()) {
251+
var initialOutputPathContents = response.getInitialOutputPathContents();
252+
if (!initialOutputPathContents.getBuildId().equals(lastBuildId)) {
253+
return ModifiedFileSet.EVERYTHING_DELETED;
254+
}
255+
248256
// TODO(chiwang): Handle StartBuildResponse.initial_output_path_contents
249257
}
250258

src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public final class RemoteModule extends BlazeModule {
138138
@Nullable private TempPathGenerator tempPathGenerator;
139139
@Nullable private BlockWaitingModule blockWaitingModule;
140140
@Nullable private RemoteOutputChecker remoteOutputChecker;
141+
@Nullable private String lastBuildId;
141142

142143
private ChannelFactory channelFactory =
143144
new ChannelFactory() {
@@ -473,7 +474,8 @@ public void beforeCommand(CommandEnvironment env) throws AbruptExitException {
473474
remoteOptions.remoteOutputServiceOutputPathPrefix,
474475
verboseFailures,
475476
retrier,
476-
bazelOutputServiceChannel);
477+
bazelOutputServiceChannel,
478+
lastBuildId);
477479
} else {
478480
outputService = new RemoteOutputService(env);
479481
}
@@ -919,6 +921,8 @@ public void afterCommand() {
919921
() -> afterCommandTask(actionContextProviderRef, tempPathGeneratorRef, rpcLogFileRef));
920922
}
921923

924+
lastBuildId = Preconditions.checkNotNull(env).getCommandId().toString();
925+
922926
buildEventArtifactUploaderFactoryDelegate.reset();
923927
repositoryRemoteExecutorFactoryDelegate.reset();
924928
remoteDownloaderSupplier.set(null);

0 commit comments

Comments
 (0)