aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java
diff options
context:
space:
mode:
authorGravatar ccalvarin <ccalvarin@google.com>2017-12-14 10:37:41 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-14 10:41:14 -0800
commit2192b56babc6c4f0e84d130a313a6710753cfae4 (patch)
tree14f4f36972dc22e7e6531ed004fe59cb7c44fb93 /src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java
parent8b3ba50246fed6ff13d70299fb039cc66be465c4 (diff)
We accepted these by environment variable largely because setting it via invocation policy would require changing invocation policy for each command, which had caused the Bazel server to restart, loosing incremental state. This is fixed: changing invocation policy no longer causes Bazel to restart its servers, so accept these as normal options. We will soon no longer accept these flags by environment variable, but will accept both for a transition period, so that nobody relying on these values is broken by a single release. To inform users of this environment variable, anyone setting the environment variable without the flag will receive a warning but the value will be kept. The following release will no longer accept an environment variable. Note on format: invocation_id we accept only clean UUIDs, but for build_request_id, to help differentiate otherwise undifferentiable id types, we accept arbitrary prefixes before the UUID. The user is responsible for picking prefixes that are sane. RELNOTES: None. PiperOrigin-RevId: 179063120
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java b/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java
index dd1960ae1d..238eb225d6 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java
@@ -13,16 +13,21 @@
// limitations under the License.
package com.google.devtools.build.lib.runtime;
+import static com.google.common.base.Strings.isNullOrEmpty;
+
import com.google.devtools.build.lib.runtime.CommandLineEvent.ToolCommandLineEvent;
import com.google.devtools.build.lib.util.OptionsUtils;
import com.google.devtools.build.lib.vfs.PathFragment;
+import com.google.devtools.common.options.Converter;
import com.google.devtools.common.options.Converters;
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.OptionMetadataTag;
import com.google.devtools.common.options.OptionsBase;
+import com.google.devtools.common.options.OptionsParsingException;
import java.util.List;
+import java.util.UUID;
import java.util.logging.Level;
/**
@@ -113,6 +118,85 @@ public class CommonCommandOptions extends OptionsBase {
)
public boolean allowUndefinedConfigs;
+ /** Converter for UUID. Accepts values as specified by {@link UUID#fromString(String)}. */
+ public static class UUIDConverter implements Converter<UUID> {
+
+ @Override
+ public UUID convert(String input) throws OptionsParsingException {
+ if (isNullOrEmpty(input)) {
+ return null;
+ }
+ try {
+ return UUID.fromString(input);
+ } catch (IllegalArgumentException e) {
+ throw new OptionsParsingException(
+ String.format("Value '%s' is not a value UUID.", input), e);
+ }
+ }
+
+ @Override
+ public String getTypeDescription() {
+ return "a UUID";
+ }
+ }
+
+ /**
+ * Converter for options (--build_request_id) that accept prefixed UUIDs. Since we do not care
+ * about the structure of this value after validation, we store it as a string.
+ */
+ public static class PrefixedUUIDConverter implements Converter<String> {
+
+ @Override
+ public String convert(String input) throws OptionsParsingException {
+ if (isNullOrEmpty(input)) {
+ return null;
+ }
+ // UUIDs that are accepted by UUID#fromString have 36 characters. Interpret the last 36
+ // characters as an UUID and the rest as a prefix. We do not check anything about the contents
+ // of the prefix.
+ try {
+ int uuidStartIndex = input.length() - 36;
+ UUID.fromString(input.substring(uuidStartIndex));
+ } catch (IllegalArgumentException | IndexOutOfBoundsException e) {
+ throw new OptionsParsingException(
+ String.format("Value '%s' does end in a valid UUID.", input), e);
+ }
+ return input;
+ }
+
+ @Override
+ public String getTypeDescription() {
+ return "An optionally prefixed UUID. The last 36 characters will be verified as a UUID.";
+ }
+ }
+
+ // Command ID and build request ID can be set either by flag or environment variable. In most
+ // cases, the internally generated ids should be sufficient, but we allow these to be set
+ // externally if required. Option wins over environment variable, if both are set.
+ // TODO(b/67895628) Stop reading ids from the environment after the compatibility window has
+ // passed.
+ @Option(
+ name = "invocation_id",
+ defaultValue = "",
+ converter = UUIDConverter.class,
+ documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
+ effectTags = {OptionEffectTag.BAZEL_MONITORING, OptionEffectTag.BAZEL_INTERNAL_CONFIGURATION},
+ metadataTags = {OptionMetadataTag.HIDDEN},
+ help = "Unique identifier for the command being run."
+ )
+ public UUID invocationId;
+
+ @Option(
+ name = "build_request_id",
+ defaultValue = "",
+ converter = PrefixedUUIDConverter.class,
+ documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
+ effectTags = {OptionEffectTag.BAZEL_MONITORING, OptionEffectTag.BAZEL_INTERNAL_CONFIGURATION},
+ metadataTags = {OptionMetadataTag.HIDDEN},
+ help = "Unique identifier for the build being run."
+ )
+ public String buildRequestId;
+
@Option(
name = "profile",
defaultValue = "null",