Use a RegexPatternOption for --remote_download_regex.
So that invalid patterns produce an error message instead of crashing.
Fixes #21650.
PiperOrigin-RevId: 615041896
Change-Id: I07cda825ea0f4fb4cb4bc33b6acd78d44badc0f8
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 f6339d7..b66d0e0 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
@@ -99,6 +99,7 @@
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.common.options.OptionsBase;
import com.google.devtools.common.options.OptionsParsingResult;
+import com.google.devtools.common.options.RegexPatternOption;
import io.grpc.CallCredentials;
import io.grpc.ClientInterceptor;
import io.grpc.ManagedChannel;
@@ -332,8 +333,8 @@
// used without Build without the Bytes.
ImmutableList.Builder<Pattern> patternsToDownloadBuilder = ImmutableList.builder();
if (remoteOptions.remoteOutputsMode != RemoteOutputsMode.ALL) {
- for (String regex : remoteOptions.remoteDownloadRegex) {
- patternsToDownloadBuilder.add(Pattern.compile(regex));
+ for (RegexPatternOption patternOption : remoteOptions.remoteDownloadRegex) {
+ patternsToDownloadBuilder.add(patternOption.regexPattern());
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/remote/options/CommonRemoteOptions.java b/src/main/java/com/google/devtools/build/lib/remote/options/CommonRemoteOptions.java
index 22d9d4b..d3c1673 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/options/CommonRemoteOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/remote/options/CommonRemoteOptions.java
@@ -15,11 +15,13 @@
import com.google.devtools.common.options.Converter;
import com.google.devtools.common.options.Converters;
+import com.google.devtools.common.options.Converters.RegexPatternConverter;
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionDocumentationCategory;
import com.google.devtools.common.options.OptionEffectTag;
import com.google.devtools.common.options.OptionsBase;
import com.google.devtools.common.options.OptionsParsingException;
+import com.google.devtools.common.options.RegexPatternOption;
import java.time.Duration;
import java.util.List;
import java.util.regex.Pattern;
@@ -33,12 +35,12 @@
allowMultiple = true,
documentationCategory = OptionDocumentationCategory.REMOTE,
effectTags = {OptionEffectTag.AFFECTS_OUTPUTS},
+ converter = RegexPatternConverter.class,
help =
- "Force Bazel to download the artifacts that match the given regexp. To be used in"
- + " 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). Multiple regexes can be specified by repeating this flag.")
- public List<String> remoteDownloadRegex;
+ "Force remote build outputs whose path matches this pattern to be downloaded,"
+ + " irrespective of --remote_download_outputs. Multiple patterns may be specified by"
+ + " repeating this flag.")
+ public List<RegexPatternOption> remoteDownloadRegex;
@Option(
name = "experimental_remote_cache_ttl",