From 0c07c2e6571dd4806552213b2237ecb7a908afa4 Mon Sep 17 00:00:00 2001 From: Chi Wang Date: Tue, 8 Jun 2021 00:16:11 -0700 Subject: [PATCH] Remote: Add remoteCacheable key to execution log Fixes https://github.com/bazelbuild/bazel/issues/13495. Closes #13551. PiperOrigin-RevId: 378090621 --- .../devtools/build/lib/exec/SpawnLogContext.java | 1 + src/main/protobuf/spawn.proto | 3 +++ .../build/lib/exec/AbstractSpawnStrategyTest.java | 4 +++- src/test/shell/bazel/bazel_execlog_test.sh | 13 +++++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/devtools/build/lib/exec/SpawnLogContext.java b/src/main/java/com/google/devtools/build/lib/exec/SpawnLogContext.java index 262c35f1672fbc..9b78bc8c35a325 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/SpawnLogContext.java +++ b/src/main/java/com/google/devtools/build/lib/exec/SpawnLogContext.java @@ -138,6 +138,7 @@ public void logSpawn( builder.setTimeoutMillis(timeout.toMillis()); } builder.setCacheable(Spawns.mayBeCached(spawn)); + builder.setRemoteCacheable(Spawns.mayBeCachedRemotely(spawn)); builder.setExitCode(result.exitCode()); builder.setRemoteCacheHit(result.isCacheHit()); builder.setRunner(result.getRunnerName()); diff --git a/src/main/protobuf/spawn.proto b/src/main/protobuf/spawn.proto index f602fe625ed515..7fb621a13df9dd 100644 --- a/src/main/protobuf/spawn.proto +++ b/src/main/protobuf/spawn.proto @@ -123,4 +123,7 @@ message SpawnExec { // Its semantics varies greatly depending on the status field. // Dependable: if status is empty, exit_code is guaranteed to be zero. int32 exit_code = 15; + + // Was the Spawn result allowed to be cached remotely. + bool remote_cacheable = 16; } diff --git a/src/test/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategyTest.java b/src/test/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategyTest.java index 2f9a019eed6ac5..fe4aa66c1910c6 100644 --- a/src/test/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategyTest.java +++ b/src/test/java/com/google/devtools/build/lib/exec/AbstractSpawnStrategyTest.java @@ -360,6 +360,7 @@ public void testLogSpawn() throws Exception { .setExitCode(23) .setRemotable(true) .setCacheable(true) + .setRemoteCacheable(true) .setProgressMessage("my progress message") .setMnemonic("MyMnemonic") .setRunner("runner") @@ -486,6 +487,7 @@ private static SpawnExec.Builder defaultSpawnExecBuilder(String cmd) { .setMnemonic("Mnemonic") .setRunner("runner") .setStatus("NON_ZERO_EXIT") - .setExitCode(23); + .setExitCode(23) + .setRemoteCacheable(true); } } diff --git a/src/test/shell/bazel/bazel_execlog_test.sh b/src/test/shell/bazel/bazel_execlog_test.sh index 6652833006c955..fb7428fa294f6e 100755 --- a/src/test/shell/bazel/bazel_execlog_test.sh +++ b/src/test/shell/bazel/bazel_execlog_test.sh @@ -188,4 +188,17 @@ EOF grep "listedOutputs" output.json || fail "log does not contain listed outputs" } +function test_no_remote_cache() { + cat > BUILD <<'EOF' +genrule( + name = "action", + outs = ["out.txt"], + cmd = "echo hello > $(location out.txt)", + tags = ["no-remote-cache"], +) +EOF + bazel build //:action --execution_log_json_file=output.json 2>&1 >> $TEST_log || fail "could not build" + grep "\"remoteCacheable\": false" output.json || fail "log does not contain valid remoteCacheable entry" +} + run_suite "execlog_tests"