From 9e9af9107acd829df784bcc9f5d99ac363cf9513 Mon Sep 17 00:00:00 2001 From: "Artem V. Navrotskiy" Date: Thu, 8 Sep 2022 15:13:00 +0300 Subject: [PATCH] Allow locally build actions with scrubbed inputs --- .../lib/remote/RemoteExecutionService.java | 20 ++++++++++++++++++- .../build/lib/remote/RemoteModule.java | 5 +---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionService.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionService.java index 8f15ad60ca1773..5570f8e672f56c 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionService.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionService.java @@ -341,7 +341,8 @@ public CachePolicy getWriteCachePolicy(Spawn spawn) { public boolean mayBeExecutedRemotely(Spawn spawn) { return remoteCache instanceof RemoteExecutionCache && remoteExecutor != null - && Spawns.mayBeExecutedRemotely(spawn); + && Spawns.mayBeExecutedRemotely(spawn) + && !hasScrubbedInput(spawn, scrubber); } @VisibleForTesting @@ -1595,6 +1596,23 @@ void report(Event evt) { } } + private static boolean hasScrubbedInput(Spawn spawn, @Nullable Scrubber scrubber) { + if (scrubber == null) { + return false; + } + SpawnScrubber spawnScrubber = scrubber.forSpawn(spawn); + if (spawnScrubber == null) { + return false; + } + var inputFiles = spawn.getInputFiles(); + for (ActionInput inputFile : inputFiles.getLeaves()) { + if (spawnScrubber.shouldOmitInput(inputFile)) { + return true; + } + } + return false; + } + /** * A simple value class combining a hash of the tool inputs (and their digests) as well as a set * of the relative paths of all tool inputs. diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java index db9adc0e03c0b3..e80df9a8c03ae9 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java @@ -313,10 +313,7 @@ public void beforeCommand(CommandEnvironment env) throws AbruptExitException { boolean enableScrubbing = remoteOptions.scrubber != null; if (enableScrubbing && enableRemoteExecution) { - - throw createOptionsExitException( - "Cannot combine remote cache key scrubbing with remote execution", - FailureDetails.RemoteOptions.Code.EXECUTION_WITH_SCRUBBING); + env.getReporter().handle(Event.warn("Cannot combine remote cache key scrubbing with remote execution. All actions with cache key scrubbing will be executed locally")); } // TODO(bazel-team): Consider adding a warning or more validation if the remoteDownloadRegex is