aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/runtime
diff options
context:
space:
mode:
authorGravatar ccalvarin <ccalvarin@google.com>2018-08-01 19:25:22 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-08-01 19:26:50 -0700
commit78142a6bf3dbf802e3140c1098cf3fda8d4be883 (patch)
tree0cabf6381320a3c39fecbc14926ee1196e1182bf /src/main/java/com/google/devtools/build/lib/runtime
parentc82074a3848e4b7340a85ce855f3d5b9fb157fd7 (diff)
Add a normal startup-option for setting the digest function.
We continue to support the jvm property -Dbazel.DigestFunction, for backwards compatibility, but this will go away. The startup-option is marked experimental for now as we iron out issues. (note: leaving this out of release notes until the experimental tag is removed) As part of this refactor, the default constructor calls for FileSystem and derived classes will now use this default. This should remove the need for constructors that accept custom hash functions. RELNOTES: None. PiperOrigin-RevId: 207035217
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime')
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BazelFileSystemModule.java43
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java27
2 files changed, 48 insertions, 22 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BazelFileSystemModule.java b/src/main/java/com/google/devtools/build/lib/runtime/BazelFileSystemModule.java
index a734424a03..9e57bf84e9 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BazelFileSystemModule.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BazelFileSystemModule.java
@@ -13,11 +13,13 @@
// limitations under the License.
package com.google.devtools.build.lib.runtime;
+import com.google.common.base.Preconditions;
import com.google.devtools.build.lib.unix.UnixFileSystem;
import com.google.devtools.build.lib.util.AbruptExitException;
import com.google.devtools.build.lib.util.ExitCode;
import com.google.devtools.build.lib.util.OS;
import com.google.devtools.build.lib.vfs.DigestHashFunction;
+import com.google.devtools.build.lib.vfs.DigestHashFunction.DefaultAlreadySetException;
import com.google.devtools.build.lib.vfs.DigestHashFunction.DigestFunctionConverter;
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.JavaIoFileSystem;
@@ -34,27 +36,36 @@ import com.google.devtools.common.options.OptionsProvider;
public class BazelFileSystemModule extends BlazeModule {
@Override
- public FileSystem getFileSystem(OptionsProvider startupOptions) throws AbruptExitException {
- final DigestHashFunction hashFunction;
- String value = null;
+ public void globalInit(OptionsProvider startupOptionsProvider) throws AbruptExitException {
+ BlazeServerStartupOptions startupOptions =
+ Preconditions.checkNotNull(
+ startupOptionsProvider.getOptions(BlazeServerStartupOptions.class));
+ DigestHashFunction commandLineHashFunction = startupOptions.digestHashFunction;
try {
- value = System.getProperty("bazel.DigestFunction", "SHA256");
- hashFunction = new DigestFunctionConverter().convert(value);
- } catch (OptionsParsingException e) {
- throw new AbruptExitException(
- "The specified hash function '" + value + "' is not supported.",
- ExitCode.COMMAND_LINE_ERROR,
- e);
+ if (commandLineHashFunction != null) {
+ DigestHashFunction.setDefault(commandLineHashFunction);
+ } else {
+ String value = System.getProperty("bazel.DigestFunction", "SHA256");
+ DigestHashFunction jvmPropertyHash;
+ try {
+ jvmPropertyHash = new DigestFunctionConverter().convert(value);
+ } catch (OptionsParsingException e) {
+ throw new AbruptExitException(ExitCode.COMMAND_LINE_ERROR, e);
+ }
+ DigestHashFunction.setDefault(jvmPropertyHash);
+ }
+ } catch (DefaultAlreadySetException e) {
+ throw new AbruptExitException(ExitCode.BLAZE_INTERNAL_ERROR, e);
}
+ }
+
+ @Override
+ public FileSystem getFileSystem(OptionsProvider startupOptions) {
if ("0".equals(System.getProperty("io.bazel.EnableJni"))) {
// Ignore UnixFileSystem, to be used for bootstrapping.
- return OS.getCurrent() == OS.WINDOWS
- ? new WindowsFileSystem(hashFunction)
- : new JavaIoFileSystem(hashFunction);
+ return OS.getCurrent() == OS.WINDOWS ? new WindowsFileSystem() : new JavaIoFileSystem();
}
// The JNI-based UnixFileSystem is faster, but on Windows it is not available.
- return OS.getCurrent() == OS.WINDOWS
- ? new WindowsFileSystem(hashFunction)
- : new UnixFileSystem(hashFunction);
+ return OS.getCurrent() == OS.WINDOWS ? new WindowsFileSystem() : new UnixFileSystem();
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java
index 8fdd14082d..6d434f8d56 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeServerStartupOptions.java
@@ -15,6 +15,7 @@ package com.google.devtools.build.lib.runtime;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.util.OptionsUtils;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.common.options.Converter;
import com.google.devtools.common.options.Option;
@@ -395,14 +396,28 @@ public class BlazeServerStartupOptions extends OptionsBase {
public boolean clientDebug;
@Option(
- name = "connect_timeout_secs",
- defaultValue = "30", // NOTE: only for documentation, value is set and used by the client.
- documentationCategory = OptionDocumentationCategory.BAZEL_CLIENT_OPTIONS,
- effectTags = {OptionEffectTag.BAZEL_INTERNAL_CONFIGURATION},
- help = "The amount of time the client waits for each attempt to connect to the server"
- )
+ name = "connect_timeout_secs",
+ defaultValue = "30", // NOTE: only for documentation, value is set and used by the client.
+ documentationCategory = OptionDocumentationCategory.BAZEL_CLIENT_OPTIONS,
+ effectTags = {OptionEffectTag.BAZEL_INTERNAL_CONFIGURATION},
+ help = "The amount of time the client waits for each attempt to connect to the server")
public int connectTimeoutSecs;
+ // TODO(b/109764197): Add OptionDocumentationCategory.BAZEL_CLIENT_OPTIONS & remove the
+ // experimental tag once this has been tested and is ready for use.
+ @Option(
+ name = "digest_function",
+ defaultValue = "null",
+ converter = DigestHashFunction.DigestFunctionConverter.class,
+ documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
+ effectTags = {
+ OptionEffectTag.LOSES_INCREMENTAL_STATE,
+ OptionEffectTag.BAZEL_INTERNAL_CONFIGURATION
+ },
+ metadataTags = OptionMetadataTag.EXPERIMENTAL,
+ help = "The hash function to use when computing file digests.")
+ public DigestHashFunction digestHashFunction;
+
@Deprecated
@Option(
name = "expand_configs_in_place",