diff options
author | ccalvarin <ccalvarin@google.com> | 2018-08-01 19:25:22 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-08-01 19:26:50 -0700 |
commit | 78142a6bf3dbf802e3140c1098cf3fda8d4be883 (patch) | |
tree | 0cabf6381320a3c39fecbc14926ee1196e1182bf /src/main/java/com/google/devtools/build/lib/runtime/BazelFileSystemModule.java | |
parent | c82074a3848e4b7340a85ce855f3d5b9fb157fd7 (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/BazelFileSystemModule.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/BazelFileSystemModule.java | 43 |
1 files changed, 27 insertions, 16 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(); } } |