aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ulfjack <ulfjack@google.com>2017-04-18 16:03:40 +0200
committerGravatar Klaus Aehlig <aehlig@google.com>2017-04-18 16:41:37 +0200
commit7a90b9a409bea4a69e0c80d418c6193d64c8eb3f (patch)
treea81f15ea71e46e51301d5290d2ac5d8f78f7b82a
parentd1b34d487bb83f0761d707cb8b27f88d547068e8 (diff)
Write stdout and stderr to the remote cache
Only write a cache entry when the spawn executed successfully, and with a 0 exit code. In the test, we only check that uploadFileContents is called exactly twice. Progress on #1413. PiperOrigin-RevId: 153458240
-rw-r--r--src/main/java/com/google/devtools/build/lib/remote/CachedLocalSpawnRunner.java12
-rw-r--r--src/test/java/com/google/devtools/build/lib/remote/CachedLocalSpawnRunnerTest.java7
2 files changed, 15 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/remote/CachedLocalSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/remote/CachedLocalSpawnRunner.java
index 3a10aa490d..fb7241eb7b 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/CachedLocalSpawnRunner.java
+++ b/src/main/java/com/google/devtools/build/lib/remote/CachedLocalSpawnRunner.java
@@ -126,8 +126,10 @@ final class CachedLocalSpawnRunner implements SpawnRunner {
}
}
SpawnResult spawnResult = delegate.exec(spawn, policy);
- if (options.remoteLocalExecUploadResults && spawnResult.setupSuccess()) {
- writeCacheEntry(spawn, actionKey);
+ if (options.remoteLocalExecUploadResults
+ && spawnResult.status() == Status.SUCCESS
+ && spawnResult.exitCode() == 0) {
+ writeCacheEntry(spawn, policy.getFileOutErr(), actionKey);
}
return spawnResult;
} catch (StatusRuntimeException e) {
@@ -172,7 +174,7 @@ final class CachedLocalSpawnRunner implements SpawnRunner {
outErr.printErr(new String(streams.get(1), UTF_8));
}
- private void writeCacheEntry(Spawn spawn, ActionKey actionKey)
+ private void writeCacheEntry(Spawn spawn, FileOutErr outErr, ActionKey actionKey)
throws IOException, InterruptedException {
ArrayList<Path> outputFiles = new ArrayList<>();
for (ActionInput output : spawn.getOutputFiles()) {
@@ -185,6 +187,10 @@ final class CachedLocalSpawnRunner implements SpawnRunner {
}
ActionResult.Builder result = ActionResult.newBuilder();
actionCache.uploadAllResults(execRoot, outputFiles, result);
+ ContentDigest stderr = actionCache.uploadFileContents(outErr.getErrorPath());
+ ContentDigest stdout = actionCache.uploadFileContents(outErr.getOutputPath());
+ result.setStderrDigest(stderr);
+ result.setStdoutDigest(stdout);
actionCache.setCachedActionResult(actionKey, result.build());
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/remote/CachedLocalSpawnRunnerTest.java b/src/test/java/com/google/devtools/build/lib/remote/CachedLocalSpawnRunnerTest.java
index 1456239e55..8fe2f79f27 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/CachedLocalSpawnRunnerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/CachedLocalSpawnRunnerTest.java
@@ -66,6 +66,8 @@ public class CachedLocalSpawnRunnerTest {
}
};
+ private static final ContentDigest DIGEST_FOR_EMPTY = ContentDigests.computeDigest(new byte[0]);
+
private FileSystem fs;
private Path execRoot;
private SimpleSpawn simpleSpawn;
@@ -219,6 +221,7 @@ public class CachedLocalSpawnRunnerTest {
scratch(simpleSpawn.getInputFiles().get(0), "xyz");
when(cache.getCachedActionResult(any(ActionKey.class))).thenReturn(null);
+ when(cache.uploadFileContents(any(Path.class))).thenReturn(DIGEST_FOR_EMPTY);
SpawnResult delegateResult = new SpawnResult.Builder()
.setExitCode(0)
.setStatus(Status.SUCCESS)
@@ -227,9 +230,11 @@ public class CachedLocalSpawnRunnerTest {
.thenReturn(delegateResult);
SpawnResult result = runner.exec(simpleSpawn, simplePolicy);
- // We use verify to check that each method is called exactly once.
+ // We use verify to check that each method is called the correct number of times.
verify(cache)
.uploadAllResults(any(Path.class), any(Collection.class), any(ActionResult.Builder.class));
+ // Two additional uploads for stdout and stderr.
+ verify(cache, Mockito.times(2)).uploadFileContents(any(Path.class));
verify(cache).setCachedActionResult(any(ActionKey.class), any(ActionResult.class));
assertThat(result.setupSuccess()).isTrue();
assertThat(result.exitCode()).isEqualTo(0);