From e530f684be3d32cbb9e67a6905aebf6bbdb61a89 Mon Sep 17 00:00:00 2001 From: Vladimir Chebotarev Date: Thu, 25 Apr 2019 12:11:16 +0300 Subject: [PATCH] test3 --- .../build/lib/remote/RemoteSpawnCache.java | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java index 2da0cc1203d446..15d40c6a738cb3 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnCache.java @@ -18,6 +18,7 @@ import build.bazel.remote.execution.v2.Action; import build.bazel.remote.execution.v2.ActionResult; import build.bazel.remote.execution.v2.Command; +import build.bazel.remote.execution.v2.OutputFile; import build.bazel.remote.execution.v2.Platform; import com.google.devtools.build.lib.actions.ActionInput; import com.google.devtools.build.lib.actions.ExecException; @@ -46,9 +47,11 @@ import java.io.IOException; import java.util.Collection; import java.util.HashSet; +import java.util.List; import java.util.NoSuchElementException; import java.util.Set; import java.util.SortedMap; +import java.util.stream.Collectors; import javax.annotation.Nullable; /** A remote {@link SpawnCache} implementation. */ @@ -143,20 +146,29 @@ public CacheHandle lookup(Spawn spawn, SpawnExecutionContext context) result = remoteCache.getCachedActionResult(actionKey); } if (result != null) { - // We don't cache failed actions, so we know the outputs exist. - // For now, download all outputs locally; in the future, we can reuse the digests to - // just update the TreeNodeRepository and continue the build. - try (SilentCloseable c = Profiler.instance().profile("RemoteCache.download")) { - remoteCache.download(result, execRoot, context.getFileOutErr()); + List expectedPaths = spawn.getOutputFiles().stream().map( + (actionInput) -> actionInput.getExecPathString() + ).collect(Collectors.toList()); + Set actualPaths = result.getOutputFilesList().stream().map( + (outputFile) -> outputFile.getPath() + ).collect(Collectors.toSet()); + if (actualPaths.containsAll(expectedPaths)) // What a miss otherwise! + { + // We don't cache failed actions, so we know the outputs exist. + // For now, download all outputs locally; in the future, we can reuse the digests to + // just update the TreeNodeRepository and continue the build. + try (SilentCloseable c = Profiler.instance().profile("RemoteCache.download")) { + remoteCache.download(result, execRoot, context.getFileOutErr()); + } + SpawnResult spawnResult = + new SpawnResult.Builder() + .setStatus(Status.SUCCESS) + .setExitCode(result.getExitCode()) + .setCacheHit(true) + .setRunnerName("remote cache hit") + .build(); + return SpawnCache.success(spawnResult); } - SpawnResult spawnResult = - new SpawnResult.Builder() - .setStatus(Status.SUCCESS) - .setExitCode(result.getExitCode()) - .setCacheHit(true) - .setRunnerName("remote cache hit") - .build(); - return SpawnCache.success(spawnResult); } } catch (CacheNotFoundException e) { // Intentionally left blank