From d29034e43150f32bb02c2cff3774747e25e97de3 Mon Sep 17 00:00:00 2001 From: Brentley Jones Date: Fri, 14 Oct 2022 14:37:59 -0500 Subject: [PATCH] Update flag `--experimental_remote_download_regex` to accept multiple regular expressions. (#16478) PiperOrigin-RevId: 470707773 Change-Id: I9cec072e32b641fc4cc068d53d83d95a5fe9c55d (cherry picked from commit e8278edbec1c6be14f01b2ecb078042ee9e753e9) Also includes the change in #16476. Co-authored-by: Googler --- .../lib/remote/RemoteExecutionService.java | 26 ++++++++++++------- .../lib/remote/options/RemoteOptions.java | 7 ++--- 2 files changed, 20 insertions(+), 13 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 63af731ebd421b..05173938dd903c 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 @@ -142,7 +142,6 @@ import java.util.concurrent.Phaser; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Predicate; -import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.annotation.Nullable; @@ -215,18 +214,25 @@ public RemoteExecutionService( this.scheduler = Schedulers.from(executor, /*interruptibleWorker=*/ true); - String regex = remoteOptions.remoteDownloadRegex; // TODO(bazel-team): Consider adding a warning or more validation if the remoteDownloadRegex is - // used without RemoteOutputsMode.MINIMAL. - this.shouldForceDownloads = - !regex.isEmpty() - && (remoteOptions.remoteOutputsMode == RemoteOutputsMode.MINIMAL - || remoteOptions.remoteOutputsMode == RemoteOutputsMode.TOPLEVEL); - Pattern pattern = Pattern.compile(regex); + // used without Build without the Bytes. + ImmutableList.Builder builder = ImmutableList.builder(); + if (remoteOptions.remoteOutputsMode == RemoteOutputsMode.MINIMAL + || remoteOptions.remoteOutputsMode == RemoteOutputsMode.TOPLEVEL) { + for (String regex : remoteOptions.remoteDownloadRegex) { + builder.add(Pattern.compile(regex)); + } + } + ImmutableList patterns = builder.build(); + this.shouldForceDownloads = !patterns.isEmpty(); this.shouldForceDownloadPredicate = path -> { - Matcher m = pattern.matcher(path); - return m.matches(); + for (Pattern pattern : patterns) { + if (pattern.matcher(path).matches()) { + return true; + } + } + return false; }; } diff --git a/src/main/java/com/google/devtools/build/lib/remote/options/RemoteOptions.java b/src/main/java/com/google/devtools/build/lib/remote/options/RemoteOptions.java index f729ab42b84040..a520d0a9b7158d 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/options/RemoteOptions.java +++ b/src/main/java/com/google/devtools/build/lib/remote/options/RemoteOptions.java @@ -581,15 +581,16 @@ public RemoteOutputsStrategyConverter() { @Option( name = "experimental_remote_download_regex", - defaultValue = "", + defaultValue = "null", + allowMultiple = true, documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, effectTags = {OptionEffectTag.AFFECTS_OUTPUTS}, help = "Force Bazel to download the artifacts that match the given regexp. To be used in" - + " conjunction with --remote_download_minimal or --remote_download_toplevel to allow" + + " conjunction with Build without the Bytes (or the internal equivalent) to allow" + " the client to request certain artifacts that might be needed locally (e.g. IDE" + " support)") - public String remoteDownloadRegex; + public List remoteDownloadRegex; // The below options are not configurable by users, only tests. // This is part of the effort to reduce the overall number of flags.