diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java index 56c2d8407f9448..8ff410f230c67d 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java @@ -245,17 +245,13 @@ public SpawnResult exec(Spawn spawn, SpawnExecutionContext context) () -> { ExecuteRequest request = requestBuilder.build(); - // Upload the command and all the inputs into the remote cache, if remote caching - // is enabled and not disabled using tags, {@see Spawns#mayBeCachedRemotely} - if (spawnCacheableRemotely) { - try (SilentCloseable c = prof.profile(UPLOAD_TIME, "upload missing inputs")) { - Map additionalInputs = Maps.newHashMapWithExpectedSize(2); - additionalInputs.put(actionKey.getDigest(), action); - additionalInputs.put(commandHash, command); - remoteCache.ensureInputsPresent(merkleTree, additionalInputs, execRoot); - } + // Upload the command and all the inputs into the remote cache. + try (SilentCloseable c = prof.profile(UPLOAD_TIME, "upload missing inputs")) { + Map additionalInputs = Maps.newHashMapWithExpectedSize(2); + additionalInputs.put(actionKey.getDigest(), action); + additionalInputs.put(commandHash, command); + remoteCache.ensureInputsPresent(merkleTree, additionalInputs, execRoot); } - ExecuteResponse reply; try (SilentCloseable c = prof.profile(REMOTE_EXECUTION, "execute remotely")) { reply = remoteExecutor.executeRemotely(request); diff --git a/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java b/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java index 6c787cbc488bb1..b8beb81f54d6be 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java @@ -212,7 +212,7 @@ public void nonCachableSpawnsShouldNotBeCached_localFallback() throws Exception runner.exec(spawn, policy); verify(localRunner).exec(spawn, policy); - verify(cache, never()).upload(any(), any(), any(), any(), any(), any()); + verify(cache).ensureInputsPresent(any(), any(), eq(execRoot)); verifyNoMoreInteractions(cache); } diff --git a/src/test/shell/bazel/remote/remote_execution_http_test.sh b/src/test/shell/bazel/remote/remote_execution_http_test.sh index a85df0cf6258f5..2925a1a12a55d2 100755 --- a/src/test/shell/bazel/remote/remote_execution_http_test.sh +++ b/src/test/shell/bazel/remote/remote_execution_http_test.sh @@ -426,4 +426,34 @@ EOF rm -rf $cache } +function test_tag_no_remote_cache() { + mkdir -p a + cat > a/BUILD <<'EOF' +genrule( + name = "foo", + srcs = [], + outs = ["foo.txt"], + cmd = "echo \"foo\" > \"$@\"", + tags = ["no-remote-cache"] +) +EOF + + bazel build \ + --spawn_strategy=local \ + --remote_cache=grpc://localhost:${worker_port} \ + //a:foo >& $TEST_log || "Failed to build //a:foo" + + expect_log "1 local" + + bazel clean + + bazel build \ + --spawn_strategy=local \ + --remote_cache=grpc://localhost:${worker_port} \ + //a:foo || "Failed to build //a:foo" + + expect_log "1 local" + expect_not_log "remote cache hit" +} + run_suite "Remote execution and remote cache tests" diff --git a/src/test/shell/bazel/remote/remote_execution_test.sh b/src/test/shell/bazel/remote/remote_execution_test.sh index af6a303831e685..a296e9fe6d73a0 100755 --- a/src/test/shell/bazel/remote/remote_execution_test.sh +++ b/src/test/shell/bazel/remote/remote_execution_test.sh @@ -1195,6 +1195,56 @@ EOF //a:foo || "Failed to build //a:foo" } +function test_tag_no_remote_cache() { + mkdir -p a + cat > a/BUILD <<'EOF' +genrule( + name = "foo", + srcs = [], + outs = ["foo.txt"], + cmd = "echo \"foo\" > \"$@\"", + tags = ["no-remote-cache"] +) +EOF + + bazel build \ + --remote_executor=grpc://localhost:${worker_port} \ + //a:foo >& $TEST_log || "Failed to build //a:foo" + + expect_log "1 remote" + + bazel clean + + bazel build \ + --remote_executor=grpc://localhost:${worker_port} \ + //a:foo || "Failed to build //a:foo" + + expect_log "1 remote" + expect_not_log "remote cache hit" +} + +function test_tag_no_remote_exec() { + mkdir -p a + cat > a/BUILD <<'EOF' +genrule( + name = "foo", + srcs = [], + outs = ["foo.txt"], + cmd = "echo \"foo\" > \"$@\"", + tags = ["no-remote-exec"] +) +EOF + + bazel build \ + --spawn_strategy=remote,local \ + --remote_executor=grpc://localhost:${worker_port} \ + //a:foo >& $TEST_log || "Failed to build //a:foo" + + expect_log "1 local" + expect_not_log "1 remote" +} + + # TODO(alpha): Add a test that fails remote execution when remote worker # supports sandbox.