aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/exec/BinTools.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/exec/SpawnLogContext.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/remote/util/DigestUtil.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BazelFileSystemModule.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/unix/UnixFileSystem.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystem.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystemWithCustomStat.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/DigestHashFunction.java101
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java58
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/Path.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/UnionFileSystem.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystem.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/windows/WindowsFileSystem.java3
-rw-r--r--src/test/java/com/google/devtools/build/lib/actions/DigestUtilsTest.java37
-rw-r--r--src/test/java/com/google/devtools/build/lib/exec/SingleBuildFileCacheTest.java33
-rw-r--r--src/test/java/com/google/devtools/build/lib/remote/AbstractRemoteActionCacheTests.java6
-rw-r--r--src/test/java/com/google/devtools/build/lib/remote/ByteStreamUploaderTest.java4
-rw-r--r--src/test/java/com/google/devtools/build/lib/remote/CasPathConverterTest.java10
-rw-r--r--src/test/java/com/google/devtools/build/lib/remote/ChunkerTest.java4
-rw-r--r--src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteCacheTest.java6
-rw-r--r--src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteExecutionClientTest.java6
-rw-r--r--src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnCacheTest.java6
-rw-r--r--src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java6
-rw-r--r--src/test/java/com/google/devtools/build/lib/remote/SimpleBlobStoreActionCacheTest.java6
-rw-r--r--src/test/java/com/google/devtools/build/lib/remote/TreeNodeRepositoryTest.java6
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java3
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java3
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/FileArtifactValueTest.java25
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java9
-rw-r--r--src/test/java/com/google/devtools/build/lib/vfs/DigestHashFunctionTest.java67
-rw-r--r--src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java7
-rw-r--r--src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/RemoteWorker.java7
34 files changed, 310 insertions, 153 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/exec/BinTools.java b/src/main/java/com/google/devtools/build/lib/exec/BinTools.java
index 651fea5238..46991b3f85 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/BinTools.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/BinTools.java
@@ -26,8 +26,8 @@ import com.google.devtools.build.lib.actions.ExecException;
import com.google.devtools.build.lib.actions.FileArtifactValue;
import com.google.devtools.build.lib.actions.cache.VirtualActionInput;
import com.google.devtools.build.lib.analysis.BlazeDirectories;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.Dirent;
-import com.google.devtools.build.lib.vfs.FileSystem.HashFunction;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -261,7 +261,7 @@ public final class BinTools {
}
private static FileArtifactValue hash(Path path) throws IOException {
- HashFunction hashFn = path.getFileSystem().getDigestFunction();
+ DigestHashFunction hashFn = path.getFileSystem().getDigestFunction();
Hasher hasher = hashFn.getHash().newHasher();
int bytesCopied = 0;
try (InputStream in = path.getInputStream()) {
diff --git a/src/main/java/com/google/devtools/build/lib/exec/SpawnLogContext.java b/src/main/java/com/google/devtools/build/lib/exec/SpawnLogContext.java
index 89d91e4b68..1b5e82096e 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/SpawnLogContext.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/SpawnLogContext.java
@@ -31,8 +31,8 @@ import com.google.devtools.build.lib.exec.Protos.File;
import com.google.devtools.build.lib.exec.Protos.Platform;
import com.google.devtools.build.lib.exec.Protos.SpawnExec;
import com.google.devtools.build.lib.util.io.MessageOutputStream;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.Dirent;
-import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.Symlinks;
@@ -213,7 +213,7 @@ public class SpawnLogContext implements ActionContext {
@Nullable ActionInput input, @Nullable Path path, MetadataProvider metadataProvider)
throws IOException {
Preconditions.checkArgument(input != null || path != null);
- FileSystem.HashFunction hashFunction = execRoot.getFileSystem().getDigestFunction();
+ DigestHashFunction hashFunction = execRoot.getFileSystem().getDigestFunction();
Digest.Builder digest = Digest.newBuilder().setHashFunctionName(hashFunction.toString());
if (input != null) {
if (input instanceof VirtualActionInput) {
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 d5b0db5965..607b6379b5 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
@@ -34,7 +34,7 @@ import com.google.devtools.build.lib.runtime.ServerBuilder;
import com.google.devtools.build.lib.util.AbruptExitException;
import com.google.devtools.build.lib.util.ExitCode;
import com.google.devtools.build.lib.util.io.AsynchronousFileOutputStream;
-import com.google.devtools.build.lib.vfs.FileSystem.HashFunction;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.common.options.OptionsBase;
@@ -129,7 +129,7 @@ public final class RemoteModule extends BlazeModule {
}
RemoteOptions remoteOptions = env.getOptions().getOptions(RemoteOptions.class);
AuthAndTLSOptions authAndTlsOptions = env.getOptions().getOptions(AuthAndTLSOptions.class);
- HashFunction hashFn = env.getRuntime().getFileSystem().getDigestFunction();
+ DigestHashFunction hashFn = env.getRuntime().getFileSystem().getDigestFunction();
DigestUtil digestUtil = new DigestUtil(hashFn);
converter.options = remoteOptions;
converter.digestUtil = digestUtil;
diff --git a/src/main/java/com/google/devtools/build/lib/remote/util/DigestUtil.java b/src/main/java/com/google/devtools/build/lib/remote/util/DigestUtil.java
index defc0652cc..5759568e79 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/util/DigestUtil.java
+++ b/src/main/java/com/google/devtools/build/lib/remote/util/DigestUtil.java
@@ -24,7 +24,7 @@ import com.google.devtools.build.lib.actions.FileArtifactValue;
import com.google.devtools.build.lib.actions.MetadataProvider;
import com.google.devtools.build.lib.actions.cache.DigestUtils;
import com.google.devtools.build.lib.actions.cache.VirtualActionInput;
-import com.google.devtools.build.lib.vfs.FileSystem.HashFunction;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.remoteexecution.v1test.Action;
import com.google.devtools.remoteexecution.v1test.Digest;
@@ -52,9 +52,9 @@ public class DigestUtil {
}
}
- private final HashFunction hashFn;
+ private final DigestHashFunction hashFn;
- public DigestUtil(HashFunction hashFn) {
+ public DigestUtil(DigestHashFunction hashFn) {
this.hashFn = hashFn;
}
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 e6576238ca..a734424a03 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
@@ -17,8 +17,9 @@ 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.DigestFunctionConverter;
import com.google.devtools.build.lib.vfs.FileSystem;
-import com.google.devtools.build.lib.vfs.FileSystem.HashFunction;
import com.google.devtools.build.lib.vfs.JavaIoFileSystem;
import com.google.devtools.build.lib.windows.WindowsFileSystem;
import com.google.devtools.common.options.OptionsParsingException;
@@ -34,11 +35,11 @@ public class BazelFileSystemModule extends BlazeModule {
@Override
public FileSystem getFileSystem(OptionsProvider startupOptions) throws AbruptExitException {
- final HashFunction hashFunction;
+ final DigestHashFunction hashFunction;
String value = null;
try {
value = System.getProperty("bazel.DigestFunction", "SHA256");
- hashFunction = new HashFunction.Converter().convert(value);
+ hashFunction = new DigestFunctionConverter().convert(value);
} catch (OptionsParsingException e) {
throw new AbruptExitException(
"The specified hash function '" + value + "' is not supported.",
diff --git a/src/main/java/com/google/devtools/build/lib/unix/UnixFileSystem.java b/src/main/java/com/google/devtools/build/lib/unix/UnixFileSystem.java
index d5a74ebaf6..16d44a1dff 100644
--- a/src/main/java/com/google/devtools/build/lib/unix/UnixFileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/unix/UnixFileSystem.java
@@ -22,6 +22,7 @@ import com.google.devtools.build.lib.profiler.ProfilerTask;
import com.google.devtools.build.lib.unix.NativePosixFiles.Dirents;
import com.google.devtools.build.lib.unix.NativePosixFiles.ReadTypes;
import com.google.devtools.build.lib.vfs.AbstractFileSystemWithCustomStat;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.Dirent;
import com.google.devtools.build.lib.vfs.FileStatus;
import com.google.devtools.build.lib.vfs.Path;
@@ -40,7 +41,7 @@ public class UnixFileSystem extends AbstractFileSystemWithCustomStat {
public UnixFileSystem() {
}
- public UnixFileSystem(HashFunction hashFunction) {
+ public UnixFileSystem(DigestHashFunction hashFunction) {
super(hashFunction);
}
@@ -398,11 +399,11 @@ public class UnixFileSystem extends AbstractFileSystemWithCustomStat {
}
@Override
- protected byte[] getDigest(Path path, HashFunction hashFunction) throws IOException {
+ protected byte[] getDigest(Path path, DigestHashFunction hashFunction) throws IOException {
String name = path.toString();
long startTime = Profiler.nanoTimeMaybe();
try {
- if (hashFunction == HashFunction.MD5) {
+ if (hashFunction == DigestHashFunction.MD5) {
return NativePosixFiles.md5sum(name).asBytes();
}
return super.getDigest(path, hashFunction);
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystem.java
index 3159c21d34..096ca500f4 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystem.java
@@ -32,7 +32,7 @@ public abstract class AbstractFileSystem extends FileSystem {
public AbstractFileSystem() {}
- public AbstractFileSystem(HashFunction digestFunction) {
+ public AbstractFileSystem(DigestHashFunction digestFunction) {
super(digestFunction);
}
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystemWithCustomStat.java b/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystemWithCustomStat.java
index 875df98bab..2a2b06b50a 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystemWithCustomStat.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/AbstractFileSystemWithCustomStat.java
@@ -24,7 +24,7 @@ public abstract class AbstractFileSystemWithCustomStat extends AbstractFileSyste
public AbstractFileSystemWithCustomStat() {}
- public AbstractFileSystemWithCustomStat(HashFunction hashFunction) {
+ public AbstractFileSystemWithCustomStat(DigestHashFunction hashFunction) {
super(hashFunction);
}
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/DigestHashFunction.java b/src/main/java/com/google/devtools/build/lib/vfs/DigestHashFunction.java
new file mode 100644
index 0000000000..be18f0ac92
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/vfs/DigestHashFunction.java
@@ -0,0 +1,101 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.vfs;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.hash.HashFunction;
+import com.google.common.hash.Hashing;
+import com.google.devtools.common.options.Converter;
+import com.google.devtools.common.options.OptionsParsingException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map.Entry;
+
+/** Type of hash function to use for digesting files. */
+// The underlying HashFunctions are immutable and thread safe.
+public class DigestHashFunction {
+ private static final HashMap<String, DigestHashFunction> hashFunctionRegistry = new HashMap<>();
+
+ public static final DigestHashFunction MD5 = DigestHashFunction.register(Hashing.md5(), "MD5");
+ public static final DigestHashFunction SHA1 =
+ DigestHashFunction.register(Hashing.sha1(), "SHA-1", "SHA1");
+ public static final DigestHashFunction SHA256 =
+ DigestHashFunction.register(Hashing.sha256(), "SHA-256", "SHA256");
+
+ private final HashFunction hash;
+ private final String name;
+
+ private DigestHashFunction(HashFunction hash, String name) {
+ this.hash = hash;
+ this.name = name;
+ }
+
+ public HashFunction getHash() {
+ return hash;
+ }
+
+ public boolean isValidDigest(byte[] digest) {
+ // TODO(b/109764197): Remove this check to accept variable-length hashes.
+ return digest != null && digest.length * 8 == hash.bits();
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ /**
+ * Creates a new DigestHashFunction that is registered to be recognized by its name in {@link
+ * DigestFunctionConverter}.
+ *
+ * @param hashName the canonical name for this hash function.
+ * @param altNames alternative names that will be mapped to this function by the converter but
+ * will not serve as the canonical name for the DigestHashFunction.
+ * @param hash The {@link HashFunction} to register.
+ * @throws IllegalArgumentException if the name is already registered.
+ */
+ public static DigestHashFunction register(
+ HashFunction hash, String hashName, String... altNames) {
+ DigestHashFunction hashFunction = new DigestHashFunction(hash, hashName);
+ List<String> names = ImmutableList.<String>builder().add(hashName).add(altNames).build();
+ synchronized (hashFunctionRegistry) {
+ for (String name : names) {
+ if (hashFunctionRegistry.containsKey(name)) {
+ throw new IllegalArgumentException("Hash function " + name + " is already registered.");
+ }
+ hashFunctionRegistry.put(name, hashFunction);
+ }
+ }
+ return hashFunction;
+ }
+
+ /** Converts a string to its registered {@link DigestHashFunction}. */
+ public static class DigestFunctionConverter implements Converter<DigestHashFunction> {
+ @Override
+ public DigestHashFunction convert(String input) throws OptionsParsingException {
+ for (Entry<String, DigestHashFunction> possibleFunctions : hashFunctionRegistry.entrySet()) {
+ if (possibleFunctions.getKey().equalsIgnoreCase(input)) {
+ return possibleFunctions.getValue();
+ }
+ }
+ throw new OptionsParsingException("Not a valid hash function.");
+ }
+
+ @Override
+ public String getTypeDescription() {
+ return "hash function";
+ }
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java
index 2169c18b9c..8258dccfc0 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java
@@ -18,11 +18,9 @@ import static java.nio.charset.StandardCharsets.ISO_8859_1;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-import com.google.common.hash.Hashing;
import com.google.common.io.ByteSource;
import com.google.common.io.CharStreams;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
-import com.google.devtools.common.options.EnumConverter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -38,47 +36,17 @@ import java.util.List;
@ThreadSafe
public abstract class FileSystem {
- /** Type of hash function to use for digesting files. */
- // The underlying HashFunctions are immutable and thread safe.
- @SuppressWarnings("ImmutableEnumChecker")
- public enum HashFunction {
- MD5(Hashing.md5()),
- SHA1(Hashing.sha1()),
- SHA256(Hashing.sha256());
-
- private final com.google.common.hash.HashFunction hash;
-
- HashFunction(com.google.common.hash.HashFunction hash) {
- this.hash = hash;
- }
-
- /** Converts to {@link HashFunction}. */
- public static class Converter extends EnumConverter<HashFunction> {
- public Converter() {
- super(HashFunction.class, "hash function");
- }
- }
-
- public com.google.common.hash.HashFunction getHash() {
- return hash;
- }
-
- public boolean isValidDigest(byte[] digest) {
- return digest != null && digest.length * 8 == hash.bits();
- }
- }
-
- private final HashFunction digestFunction;
+ private final DigestHashFunction digestFunction;
public FileSystem() {
- this(HashFunction.MD5);
+ this(DigestHashFunction.MD5);
}
- public FileSystem(HashFunction digestFunction) {
+ public FileSystem(DigestHashFunction digestFunction) {
this.digestFunction = Preconditions.checkNotNull(digestFunction);
}
- public HashFunction getDigestFunction() {
+ public DigestHashFunction getDigestFunction() {
return digestFunction;
}
@@ -266,11 +234,11 @@ public abstract class FileSystem {
}
/**
- * Gets a fast digest for the given path and hash function type, or {@code null} if there
- * isn't one available or the filesystem doesn't support them. This digest should be
- * suitable for detecting changes to the file.
+ * Gets a fast digest for the given path and hash function type, or {@code null} if there isn't
+ * one available or the filesystem doesn't support them. This digest should be suitable for
+ * detecting changes to the file.
*/
- protected byte[] getFastDigest(Path path, HashFunction hashFunction) throws IOException {
+ protected byte[] getFastDigest(Path path, DigestHashFunction hashFunction) throws IOException {
return null;
}
@@ -291,15 +259,15 @@ public abstract class FileSystem {
}
/**
- * Returns the digest of the file denoted by the path, following
- * symbolic links, for the given hash digest function.
+ * Returns the digest of the file denoted by the path, following symbolic links, for the given
+ * hash digest function.
+ *
+ * <p>Subclasses may (and do) optimize this computation for particular digest functions.
*
* @return a new byte array containing the file's digest
* @throws IOException if the digest could not be computed for any reason
- *
- * Subclasses may (and do) optimize this computation for particular digest functions.
*/
- protected byte[] getDigest(final Path path, HashFunction hashFunction) throws IOException {
+ protected byte[] getDigest(final Path path, DigestHashFunction hashFunction) throws IOException {
return new ByteSource() {
@Override
public InputStream openStream() throws IOException {
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java
index ecda1b4ba1..ea541b4a1e 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/JavaIoFileSystem.java
@@ -56,7 +56,7 @@ public class JavaIoFileSystem extends AbstractFileSystemWithCustomStat {
this(new JavaClock());
}
- public JavaIoFileSystem(HashFunction hashFunction) {
+ public JavaIoFileSystem(DigestHashFunction hashFunction) {
super(hashFunction);
this.clock = new JavaClock();
}
@@ -392,7 +392,7 @@ public class JavaIoFileSystem extends AbstractFileSystemWithCustomStat {
}
@Override
- protected byte[] getDigest(Path path, HashFunction hashFunction) throws IOException {
+ protected byte[] getDigest(Path path, DigestHashFunction hashFunction) throws IOException {
String name = path.toString();
long startTime = Profiler.nanoTimeMaybe();
try {
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/Path.java b/src/main/java/com/google/devtools/build/lib/vfs/Path.java
index f9bc9d18fc..6928f0de19 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/Path.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/Path.java
@@ -19,7 +19,6 @@ import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.skylarkinterface.SkylarkPrintable;
import com.google.devtools.build.lib.skylarkinterface.SkylarkPrinter;
import com.google.devtools.build.lib.util.FileType;
-import com.google.devtools.build.lib.vfs.FileSystem.HashFunction;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -766,7 +765,7 @@ public class Path
* @return a new byte array containing the file's digest
* @throws IOException if the digest could not be computed for any reason
*/
- public byte[] getDigest(HashFunction hashFunction) throws IOException {
+ public byte[] getDigest(DigestHashFunction hashFunction) throws IOException {
return fileSystem.getDigest(this, hashFunction);
}
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/UnionFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/UnionFileSystem.java
index a929f1435d..2136633bc6 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/UnionFileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/UnionFileSystem.java
@@ -193,7 +193,7 @@ public final class UnionFileSystem extends FileSystem {
}
@Override
- protected byte[] getDigest(Path path, HashFunction hashFunction) throws IOException {
+ protected byte[] getDigest(Path path, DigestHashFunction hashFunction) throws IOException {
path = internalResolveSymlink(path);
FileSystem delegate = getDelegate(path);
return delegate.getDigest(adjustPath(path, delegate), hashFunction);
@@ -425,7 +425,7 @@ public final class UnionFileSystem extends FileSystem {
}
@Override
- protected byte[] getFastDigest(Path path, HashFunction hashFunction) throws IOException {
+ protected byte[] getFastDigest(Path path, DigestHashFunction hashFunction) throws IOException {
path = internalResolveSymlink(path);
FileSystem delegate = getDelegate(path);
return delegate.getFastDigest(adjustPath(path, delegate), hashFunction);
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystem.java
index c2a52a5b3d..bebe5b380c 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs/InMemoryFileSystem.java
@@ -19,6 +19,7 @@ import com.google.devtools.build.lib.clock.Clock;
import com.google.devtools.build.lib.clock.JavaClock;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.devtools.build.lib.util.OS;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileAccessException;
import com.google.devtools.build.lib.vfs.FileStatus;
import com.google.devtools.build.lib.vfs.FileSystem;
@@ -78,7 +79,7 @@ public class InMemoryFileSystem extends FileSystem {
* Creates a new InMemoryFileSystem with scope checking disabled (all paths are considered to be
* within scope).
*/
- public InMemoryFileSystem(Clock clock, HashFunction hashFunction) {
+ public InMemoryFileSystem(Clock clock, DigestHashFunction hashFunction) {
super(hashFunction);
this.clock = clock;
this.rootInode = newRootInode(clock);
diff --git a/src/main/java/com/google/devtools/build/lib/windows/WindowsFileSystem.java b/src/main/java/com/google/devtools/build/lib/windows/WindowsFileSystem.java
index 961465ec6d..0fd7028d6b 100644
--- a/src/main/java/com/google/devtools/build/lib/windows/WindowsFileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/windows/WindowsFileSystem.java
@@ -15,6 +15,7 @@ package com.google.devtools.build.lib.windows;
import com.google.common.annotations.VisibleForTesting;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileStatus;
import com.google.devtools.build.lib.vfs.JavaIoFileSystem;
import com.google.devtools.build.lib.vfs.Path;
@@ -36,7 +37,7 @@ public class WindowsFileSystem extends JavaIoFileSystem {
public WindowsFileSystem() {}
- public WindowsFileSystem(HashFunction hashFunction) {
+ public WindowsFileSystem(DigestHashFunction hashFunction) {
super(hashFunction);
}
diff --git a/src/test/java/com/google/devtools/build/lib/actions/DigestUtilsTest.java b/src/test/java/com/google/devtools/build/lib/actions/DigestUtilsTest.java
index 259e0f2088..e4609416bd 100644
--- a/src/test/java/com/google/devtools/build/lib/actions/DigestUtilsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/actions/DigestUtilsTest.java
@@ -22,8 +22,8 @@ import com.google.devtools.build.lib.actions.cache.DigestUtils;
import com.google.devtools.build.lib.clock.BlazeClock;
import com.google.devtools.build.lib.testutil.TestThread;
import com.google.devtools.build.lib.testutil.TestUtils;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileSystem;
-import com.google.devtools.build.lib.vfs.FileSystem.HashFunction;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
@@ -49,16 +49,21 @@ public class DigestUtilsTest {
DigestUtils.configureCache(0);
}
- private static void assertDigestCalculationConcurrency(boolean expectConcurrent,
- final boolean fastDigest, final int fileSize1, final int fileSize2,
- HashFunction hf) throws Exception {
+ private static void assertDigestCalculationConcurrency(
+ boolean expectConcurrent,
+ final boolean fastDigest,
+ final int fileSize1,
+ final int fileSize2,
+ DigestHashFunction hf)
+ throws Exception {
final CountDownLatch barrierLatch = new CountDownLatch(2); // Used to block test threads.
final CountDownLatch readyLatch = new CountDownLatch(1); // Used to block main thread.
FileSystem myfs =
new InMemoryFileSystem(BlazeClock.instance(), hf) {
@Override
- protected byte[] getDigest(Path path, HashFunction hashFunction) throws IOException {
+ protected byte[] getDigest(Path path, DigestHashFunction hashFunction)
+ throws IOException {
try {
barrierLatch.countDown();
readyLatch.countDown();
@@ -72,7 +77,8 @@ public class DigestUtilsTest {
}
@Override
- protected byte[] getFastDigest(Path path, HashFunction hashFunction) throws IOException {
+ protected byte[] getFastDigest(Path path, DigestHashFunction hashFunction)
+ throws IOException {
return fastDigest ? super.getDigest(path, hashFunction) : null;
}
};
@@ -115,7 +121,7 @@ public class DigestUtilsTest {
*/
@Test
public void testCalculationConcurrency() throws Exception {
- for (HashFunction hf : Arrays.asList(HashFunction.MD5, HashFunction.SHA1)) {
+ for (DigestHashFunction hf : Arrays.asList(DigestHashFunction.MD5, DigestHashFunction.SHA1)) {
assertDigestCalculationConcurrency(true, true, 4096, 4096, hf);
assertDigestCalculationConcurrency(true, true, 4097, 4097, hf);
assertDigestCalculationConcurrency(true, false, 4096, 4096, hf);
@@ -125,13 +131,14 @@ public class DigestUtilsTest {
}
}
- public void assertRecoverFromMalformedDigest(HashFunction... hashFunctions) throws Exception {
- for (HashFunction hf : hashFunctions) {
+ public void assertRecoverFromMalformedDigest(DigestHashFunction... hashFunctions)
+ throws Exception {
+ for (DigestHashFunction hf : hashFunctions) {
final byte[] malformed = {0, 0, 0};
FileSystem myFS =
new InMemoryFileSystem(BlazeClock.instance(), hf) {
@Override
- protected byte[] getFastDigest(Path path, HashFunction hashFunction)
+ protected byte[] getFastDigest(Path path, DigestHashFunction hashFunction)
throws IOException {
// Digest functions have more than 3 bytes, usually at least 16.
return malformed;
@@ -153,7 +160,7 @@ public class DigestUtilsTest {
fail("Digests cache should remain disabled until configureCache is called");
} catch (NullPointerException expected) {
}
- assertRecoverFromMalformedDigest(HashFunction.MD5, HashFunction.SHA1);
+ assertRecoverFromMalformedDigest(DigestHashFunction.MD5, DigestHashFunction.SHA1);
try {
DigestUtils.getCacheStats();
fail("Digests cache was unexpectedly enabled through the test");
@@ -170,7 +177,7 @@ public class DigestUtilsTest {
// hash function is not part of the cache key. This is intentional: the hash function is
// essentially final and can only be changed for tests. Therefore, just test the same hash
// function twice to further exercise the cache code.
- assertRecoverFromMalformedDigest(HashFunction.MD5, HashFunction.MD5);
+ assertRecoverFromMalformedDigest(DigestHashFunction.MD5, DigestHashFunction.MD5);
assertThat(DigestUtils.getCacheStats()).isNotNull(); // Ensure the cache remains enabled.
}
@@ -221,13 +228,15 @@ public class DigestUtilsTest {
FileSystem tracingFileSystem =
new InMemoryFileSystem(BlazeClock.instance()) {
@Override
- protected byte[] getFastDigest(Path path, HashFunction hashFunction) throws IOException {
+ protected byte[] getFastDigest(Path path, DigestHashFunction hashFunction)
+ throws IOException {
getFastDigestCounter.incrementAndGet();
return null;
}
@Override
- protected byte[] getDigest(Path path, HashFunction hashFunction) throws IOException {
+ protected byte[] getDigest(Path path, DigestHashFunction hashFunction)
+ throws IOException {
getDigestCounter.incrementAndGet();
return super.getDigest(path, hashFunction);
}
diff --git a/src/test/java/com/google/devtools/build/lib/exec/SingleBuildFileCacheTest.java b/src/test/java/com/google/devtools/build/lib/exec/SingleBuildFileCacheTest.java
index 7a94c795f4..9386bcd137 100644
--- a/src/test/java/com/google/devtools/build/lib/exec/SingleBuildFileCacheTest.java
+++ b/src/test/java/com/google/devtools/build/lib/exec/SingleBuildFileCacheTest.java
@@ -23,6 +23,7 @@ import com.google.devtools.build.lib.actions.ActionInputHelper;
import com.google.devtools.build.lib.actions.DigestOfDirectoryException;
import com.google.devtools.build.lib.testutil.Suite;
import com.google.devtools.build.lib.testutil.TestSpec;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
@@ -54,23 +55,23 @@ public class SingleBuildFileCacheTest {
public final void setUp() throws Exception {
calls = new HashMap<>();
md5Overrides = new HashMap<>();
- fs = new InMemoryFileSystem() {
- @Override
- protected InputStream getInputStream(Path path) throws IOException {
- int c = calls.containsKey(path.toString())
- ? calls.get(path.toString()) : 0;
- c++;
- calls.put(path.toString(), c);
- return super.getInputStream(path);
- }
+ fs =
+ new InMemoryFileSystem() {
+ @Override
+ protected InputStream getInputStream(Path path) throws IOException {
+ int c = calls.containsKey(path.toString()) ? calls.get(path.toString()) : 0;
+ c++;
+ calls.put(path.toString(), c);
+ return super.getInputStream(path);
+ }
- @Override
- protected byte[] getDigest(Path path, HashFunction hf) throws IOException {
- assertThat(hf).isEqualTo(HashFunction.MD5);
- byte[] override = md5Overrides.get(path.getPathString());
- return override != null ? override : super.getDigest(path, hf);
- }
- };
+ @Override
+ protected byte[] getDigest(Path path, DigestHashFunction hf) throws IOException {
+ assertThat(hf).isEqualTo(DigestHashFunction.MD5);
+ byte[] override = md5Overrides.get(path.getPathString());
+ return override != null ? override : super.getDigest(path, hf);
+ }
+ };
underTest = new SingleBuildFileCache("/", fs);
Path file = fs.getPath("/empty");
file.getOutputStream().close();
diff --git a/src/test/java/com/google/devtools/build/lib/remote/AbstractRemoteActionCacheTests.java b/src/test/java/com/google/devtools/build/lib/remote/AbstractRemoteActionCacheTests.java
index 821bb17a94..fe4881c474 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/AbstractRemoteActionCacheTests.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/AbstractRemoteActionCacheTests.java
@@ -21,8 +21,8 @@ import com.google.devtools.build.lib.actions.ExecException;
import com.google.devtools.build.lib.clock.JavaClock;
import com.google.devtools.build.lib.remote.AbstractRemoteActionCache.UploadManifest;
import com.google.devtools.build.lib.remote.util.DigestUtil;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileSystem;
-import com.google.devtools.build.lib.vfs.FileSystem.HashFunction;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
@@ -38,11 +38,11 @@ public class AbstractRemoteActionCacheTests {
private FileSystem fs;
private Path execRoot;
- private final DigestUtil digestUtil = new DigestUtil(HashFunction.SHA256);
+ private final DigestUtil digestUtil = new DigestUtil(DigestHashFunction.SHA256);
@Before
public void setUp() throws Exception {
- fs = new InMemoryFileSystem(new JavaClock(), HashFunction.SHA256);
+ fs = new InMemoryFileSystem(new JavaClock(), DigestHashFunction.SHA256);
execRoot = fs.getPath("/execroot");
execRoot.createDirectory();
}
diff --git a/src/test/java/com/google/devtools/build/lib/remote/ByteStreamUploaderTest.java b/src/test/java/com/google/devtools/build/lib/remote/ByteStreamUploaderTest.java
index 8e543c4361..d48f2981b2 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/ByteStreamUploaderTest.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/ByteStreamUploaderTest.java
@@ -29,7 +29,7 @@ import com.google.devtools.build.lib.analysis.BlazeVersionInfo;
import com.google.devtools.build.lib.remote.Retrier.RetryException;
import com.google.devtools.build.lib.remote.util.DigestUtil;
import com.google.devtools.build.lib.remote.util.TracingMetadataUtils;
-import com.google.devtools.build.lib.vfs.FileSystem.HashFunction;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.remoteexecution.v1test.Digest;
import com.google.devtools.remoteexecution.v1test.RequestMetadata;
import com.google.protobuf.ByteString;
@@ -82,7 +82,7 @@ import org.mockito.MockitoAnnotations;
@RunWith(JUnit4.class)
public class ByteStreamUploaderTest {
- private static final DigestUtil DIGEST_UTIL = new DigestUtil(HashFunction.SHA256);
+ private static final DigestUtil DIGEST_UTIL = new DigestUtil(DigestHashFunction.SHA256);
private static final int CHUNK_SIZE = 10;
private static final String INSTANCE_NAME = "foo";
diff --git a/src/test/java/com/google/devtools/build/lib/remote/CasPathConverterTest.java b/src/test/java/com/google/devtools/build/lib/remote/CasPathConverterTest.java
index 21a5bb39a2..5c6dcf2627 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/CasPathConverterTest.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/CasPathConverterTest.java
@@ -17,8 +17,8 @@ import static com.google.common.truth.Truth.assertThat;
import com.google.devtools.build.lib.remote.RemoteModule.CasPathConverter;
import com.google.devtools.build.lib.remote.util.DigestUtil;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileSystem;
-import com.google.devtools.build.lib.vfs.FileSystem.HashFunction;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
@@ -36,7 +36,7 @@ public class CasPathConverterTest {
@Test
public void noOptionsShouldntCrash() {
- converter.digestUtil = new DigestUtil(HashFunction.SHA256);
+ converter.digestUtil = new DigestUtil(DigestHashFunction.SHA256);
assertThat(converter.apply(fs.getPath("/foo"))).isEqualTo("file:///foo");
}
@@ -49,7 +49,7 @@ public class CasPathConverterTest {
@Test
public void disabledRemote() {
converter.options = Options.getDefaults(RemoteOptions.class);
- converter.digestUtil = new DigestUtil(HashFunction.SHA256);
+ converter.digestUtil = new DigestUtil(DigestHashFunction.SHA256);
assertThat(converter.apply(fs.getPath("/foo"))).isEqualTo("file:///foo");
}
@@ -58,7 +58,7 @@ public class CasPathConverterTest {
OptionsParser parser = OptionsParser.newOptionsParser(RemoteOptions.class);
parser.parse("--remote_cache=machine");
converter.options = parser.getOptions(RemoteOptions.class);
- converter.digestUtil = new DigestUtil(HashFunction.SHA256);
+ converter.digestUtil = new DigestUtil(DigestHashFunction.SHA256);
Path path = fs.getPath("/foo");
FileSystemUtils.writeContentAsLatin1(path, "foobar");
assertThat(converter.apply(fs.getPath("/foo")))
@@ -70,7 +70,7 @@ public class CasPathConverterTest {
OptionsParser parser = OptionsParser.newOptionsParser(RemoteOptions.class);
parser.parse("--remote_cache=machine", "--remote_instance_name=projects/bazel");
converter.options = parser.getOptions(RemoteOptions.class);
- converter.digestUtil = new DigestUtil(HashFunction.SHA256);
+ converter.digestUtil = new DigestUtil(DigestHashFunction.SHA256);
Path path = fs.getPath("/foo");
FileSystemUtils.writeContentAsLatin1(path, "foobar");
assertThat(converter.apply(fs.getPath("/foo")))
diff --git a/src/test/java/com/google/devtools/build/lib/remote/ChunkerTest.java b/src/test/java/com/google/devtools/build/lib/remote/ChunkerTest.java
index 2634cc93a2..8857abbd85 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/ChunkerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/ChunkerTest.java
@@ -18,7 +18,7 @@ import static junit.framework.TestCase.fail;
import com.google.devtools.build.lib.remote.Chunker.Chunk;
import com.google.devtools.build.lib.remote.util.DigestUtil;
-import com.google.devtools.build.lib.vfs.FileSystem.HashFunction;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.remoteexecution.v1test.Digest;
import com.google.protobuf.ByteString;
import java.io.ByteArrayInputStream;
@@ -38,7 +38,7 @@ import org.mockito.Mockito;
@RunWith(JUnit4.class)
public class ChunkerTest {
- private final DigestUtil digestUtil = new DigestUtil(HashFunction.SHA256);
+ private final DigestUtil digestUtil = new DigestUtil(DigestHashFunction.SHA256);
@Test
public void chunkingShouldWork() throws IOException {
diff --git a/src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteCacheTest.java b/src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteCacheTest.java
index 25228a5124..29bfeb24fb 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteCacheTest.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteCacheTest.java
@@ -39,8 +39,8 @@ import com.google.devtools.build.lib.remote.util.DigestUtil.ActionKey;
import com.google.devtools.build.lib.remote.util.TracingMetadataUtils;
import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.util.io.FileOutErr;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileSystem;
-import com.google.devtools.build.lib.vfs.FileSystem.HashFunction;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
@@ -90,7 +90,7 @@ import org.mockito.stubbing.Answer;
@RunWith(JUnit4.class)
public class GrpcRemoteCacheTest {
- private static final DigestUtil DIGEST_UTIL = new DigestUtil(HashFunction.SHA256);
+ private static final DigestUtil DIGEST_UTIL = new DigestUtil(DigestHashFunction.SHA256);
private FileSystem fs;
private Path execRoot;
@@ -118,7 +118,7 @@ public class GrpcRemoteCacheTest {
.build()
.start();
Chunker.setDefaultChunkSizeForTesting(1000); // Enough for everything to be one chunk.
- fs = new InMemoryFileSystem(new JavaClock(), HashFunction.SHA256);
+ fs = new InMemoryFileSystem(new JavaClock(), DigestHashFunction.SHA256);
execRoot = fs.getPath("/exec/root");
FileSystemUtils.createDirectoryAndParents(execRoot);
fakeFileCache = new FakeActionInputFileCache(execRoot);
diff --git a/src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteExecutionClientTest.java b/src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteExecutionClientTest.java
index 89962f173b..e10d8c35dd 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteExecutionClientTest.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/GrpcRemoteExecutionClientTest.java
@@ -50,8 +50,8 @@ import com.google.devtools.build.lib.exec.util.FakeOwner;
import com.google.devtools.build.lib.remote.util.DigestUtil;
import com.google.devtools.build.lib.remote.util.TracingMetadataUtils;
import com.google.devtools.build.lib.util.io.FileOutErr;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileSystem;
-import com.google.devtools.build.lib.vfs.FileSystem.HashFunction;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -113,7 +113,7 @@ import org.mockito.stubbing.Answer;
@RunWith(JUnit4.class)
public class GrpcRemoteExecutionClientTest {
- private static final DigestUtil DIGEST_UTIL = new DigestUtil(HashFunction.SHA256);
+ private static final DigestUtil DIGEST_UTIL = new DigestUtil(DigestHashFunction.SHA256);
private static final ArtifactExpander SIMPLE_ARTIFACT_EXPANDER =
new ArtifactExpander() {
@@ -206,7 +206,7 @@ public class GrpcRemoteExecutionClientTest {
.start();
Chunker.setDefaultChunkSizeForTesting(1000); // Enough for everything to be one chunk.
- fs = new InMemoryFileSystem(new JavaClock(), HashFunction.SHA256);
+ fs = new InMemoryFileSystem(new JavaClock(), DigestHashFunction.SHA256);
execRoot = fs.getPath("/exec/root");
logDir = fs.getPath("/server-logs");
FileSystemUtils.createDirectoryAndParents(execRoot);
diff --git a/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnCacheTest.java b/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnCacheTest.java
index 4273792319..f432ffddf6 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnCacheTest.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnCacheTest.java
@@ -50,8 +50,8 @@ import com.google.devtools.build.lib.remote.util.DigestUtil.ActionKey;
import com.google.devtools.build.lib.remote.util.TracingMetadataUtils;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.util.io.FileOutErr;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileSystem;
-import com.google.devtools.build.lib.vfs.FileSystem.HashFunction;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -157,8 +157,8 @@ public class RemoteSpawnCacheTest {
@Before
public final void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- fs = new InMemoryFileSystem(new JavaClock(), HashFunction.SHA256);
- digestUtil = new DigestUtil(HashFunction.SHA256);
+ fs = new InMemoryFileSystem(new JavaClock(), DigestHashFunction.SHA256);
+ digestUtil = new DigestUtil(DigestHashFunction.SHA256);
execRoot = fs.getPath("/exec/root");
FileSystemUtils.createDirectoryAndParents(execRoot);
fakeFileCache = new FakeActionInputFileCache(execRoot);
diff --git a/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java b/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java
index 9eead3059d..283cc956bd 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/RemoteSpawnRunnerTest.java
@@ -59,8 +59,8 @@ import com.google.devtools.build.lib.remote.util.DigestUtil;
import com.google.devtools.build.lib.remote.util.DigestUtil.ActionKey;
import com.google.devtools.build.lib.util.ExitCode;
import com.google.devtools.build.lib.util.io.FileOutErr;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileSystem;
-import com.google.devtools.build.lib.vfs.FileSystem.HashFunction;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -116,8 +116,8 @@ public class RemoteSpawnRunnerTest {
@Before
public final void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- digestUtil = new DigestUtil(HashFunction.SHA256);
- FileSystem fs = new InMemoryFileSystem(new JavaClock(), HashFunction.SHA256);
+ digestUtil = new DigestUtil(DigestHashFunction.SHA256);
+ FileSystem fs = new InMemoryFileSystem(new JavaClock(), DigestHashFunction.SHA256);
execRoot = fs.getPath("/exec/root");
logDir = fs.getPath("/server-logs");
FileSystemUtils.createDirectoryAndParents(execRoot);
diff --git a/src/test/java/com/google/devtools/build/lib/remote/SimpleBlobStoreActionCacheTest.java b/src/test/java/com/google/devtools/build/lib/remote/SimpleBlobStoreActionCacheTest.java
index 83d5bc307a..81c7f7adc6 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/SimpleBlobStoreActionCacheTest.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/SimpleBlobStoreActionCacheTest.java
@@ -27,8 +27,8 @@ import com.google.devtools.build.lib.remote.Retrier.Backoff;
import com.google.devtools.build.lib.remote.blobstore.ConcurrentMapBlobStore;
import com.google.devtools.build.lib.remote.util.DigestUtil;
import com.google.devtools.build.lib.remote.util.TracingMetadataUtils;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileSystem;
-import com.google.devtools.build.lib.vfs.FileSystem.HashFunction;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
@@ -54,7 +54,7 @@ import org.junit.runners.JUnit4;
/** Tests for {@link SimpleBlobStoreActionCache}. */
@RunWith(JUnit4.class)
public class SimpleBlobStoreActionCacheTest {
- private static final DigestUtil DIGEST_UTIL = new DigestUtil(HashFunction.SHA256);
+ private static final DigestUtil DIGEST_UTIL = new DigestUtil(DigestHashFunction.SHA256);
private FileSystem fs;
private Path execRoot;
@@ -73,7 +73,7 @@ public class SimpleBlobStoreActionCacheTest {
@Before
public final void setUp() throws Exception {
Chunker.setDefaultChunkSizeForTesting(1000); // Enough for everything to be one chunk.
- fs = new InMemoryFileSystem(new JavaClock(), HashFunction.SHA256);
+ fs = new InMemoryFileSystem(new JavaClock(), DigestHashFunction.SHA256);
execRoot = fs.getPath("/exec/root");
FileSystemUtils.createDirectoryAndParents(execRoot);
fakeFileCache = new FakeActionInputFileCache(execRoot);
diff --git a/src/test/java/com/google/devtools/build/lib/remote/TreeNodeRepositoryTest.java b/src/test/java/com/google/devtools/build/lib/remote/TreeNodeRepositoryTest.java
index 0effbf86a6..2f19f4669a 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/TreeNodeRepositoryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/TreeNodeRepositoryTest.java
@@ -26,7 +26,7 @@ import com.google.devtools.build.lib.exec.SingleBuildFileCache;
import com.google.devtools.build.lib.remote.TreeNodeRepository.TreeNode;
import com.google.devtools.build.lib.remote.util.DigestUtil;
import com.google.devtools.build.lib.testutil.Scratch;
-import com.google.devtools.build.lib.vfs.FileSystem.HashFunction;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.Root;
@@ -52,8 +52,8 @@ public class TreeNodeRepositoryTest {
@Before
public final void setRootDir() throws Exception {
- digestUtil = new DigestUtil(HashFunction.SHA256);
- scratch = new Scratch(new InMemoryFileSystem(BlazeClock.instance(), HashFunction.SHA256));
+ digestUtil = new DigestUtil(DigestHashFunction.SHA256);
+ scratch = new Scratch(new InMemoryFileSystem(BlazeClock.instance(), DigestHashFunction.SHA256));
execRoot = scratch.getFileSystem().getPath("/exec/root");
rootDir = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.dir("/exec/root")));
}
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java
index 8dc33e22a7..21020148c0 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java
@@ -43,6 +43,7 @@ import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
import com.google.devtools.build.lib.actions.util.TestAction.DummyAction;
import com.google.devtools.build.lib.events.NullEventHandler;
import com.google.devtools.build.lib.util.Pair;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileStatus;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
@@ -107,7 +108,7 @@ public class ArtifactFunctionTest extends ArtifactFunctionTestCase {
setupRoot(
new CustomInMemoryFs() {
@Override
- public byte[] getDigest(Path path, HashFunction hf) throws IOException {
+ public byte[] getDigest(Path path, DigestHashFunction hf) throws IOException {
return path.getBaseName().equals("unreadable")
? expectedDigest
: super.getDigest(path, hf);
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java
index 436cdb5cdc..5a03f3efbf 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java
@@ -30,6 +30,7 @@ import com.google.devtools.build.lib.testutil.TestConstants;
import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
import com.google.devtools.build.lib.testutil.TestUtils;
import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.Root;
@@ -168,7 +169,7 @@ abstract class ArtifactFunctionTestCase {
/** InMemoryFileSystem that can pretend to do a fast digest. */
protected class CustomInMemoryFs extends InMemoryFileSystem {
@Override
- protected byte[] getFastDigest(Path path, HashFunction hashFunction) throws IOException {
+ protected byte[] getFastDigest(Path path, DigestHashFunction hashFunction) throws IOException {
return fastDigest ? getDigest(path, hashFunction) : null;
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FileArtifactValueTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FileArtifactValueTest.java
index 92ed59611f..f09883adf7 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/FileArtifactValueTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/FileArtifactValueTest.java
@@ -21,6 +21,7 @@ import com.google.common.io.BaseEncoding;
import com.google.common.testing.EqualsTester;
import com.google.devtools.build.lib.actions.FileArtifactValue;
import com.google.devtools.build.lib.testutil.ManualClock;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
@@ -158,17 +159,19 @@ public class FileArtifactValueTest {
@Test
public void testIOException() throws Exception {
final IOException exception = new IOException("beep");
- FileSystem fs = new InMemoryFileSystem() {
- @Override
- public byte[] getDigest(Path path, HashFunction hf) throws IOException {
- throw exception;
- }
-
- @Override
- protected byte[] getFastDigest(Path path, HashFunction hashFunction) throws IOException {
- throw exception;
- }
- };
+ FileSystem fs =
+ new InMemoryFileSystem() {
+ @Override
+ public byte[] getDigest(Path path, DigestHashFunction hf) throws IOException {
+ throw exception;
+ }
+
+ @Override
+ protected byte[] getFastDigest(Path path, DigestHashFunction hashFunction)
+ throws IOException {
+ throw exception;
+ }
+ };
Path path = fs.getPath("/some/path");
path.getParentDirectory().createDirectoryAndParents();
FileSystemUtils.writeContentAsLatin1(path, "content");
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java
index 390436b0c7..f583465cda 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java
@@ -52,6 +52,7 @@ import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
import com.google.devtools.build.lib.testutil.TestUtils;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.FileStatus;
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
@@ -451,7 +452,7 @@ public class FileFunctionTest {
createFsAndRoot(
new CustomInMemoryFs(manualClock) {
@Override
- protected byte[] getFastDigest(Path path, HashFunction hf) throws IOException {
+ protected byte[] getFastDigest(Path path, DigestHashFunction hf) throws IOException {
return digest;
}
});
@@ -490,7 +491,7 @@ public class FileFunctionTest {
createFsAndRoot(
new CustomInMemoryFs(manualClock) {
@Override
- protected byte[] getFastDigest(Path path, HashFunction hf) {
+ protected byte[] getFastDigest(Path path, DigestHashFunction hf) {
return path.getBaseName().equals("unreadable") ? expectedDigest : null;
}
});
@@ -826,7 +827,7 @@ public class FileFunctionTest {
fs =
new CustomInMemoryFs(manualClock) {
@Override
- protected byte[] getDigest(Path path, HashFunction hf) throws IOException {
+ protected byte[] getDigest(Path path, DigestHashFunction hf) throws IOException {
digestCalls.incrementAndGet();
return super.getDigest(path, hf);
}
@@ -1686,7 +1687,7 @@ public class FileFunctionTest {
}
@Override
- protected byte[] getFastDigest(Path path, HashFunction hashFunction) throws IOException {
+ protected byte[] getFastDigest(Path path, DigestHashFunction hashFunction) throws IOException {
if (stubbedFastDigestErrors.containsKey(path)) {
throw stubbedFastDigestErrors.get(path);
}
diff --git a/src/test/java/com/google/devtools/build/lib/vfs/DigestHashFunctionTest.java b/src/test/java/com/google/devtools/build/lib/vfs/DigestHashFunctionTest.java
new file mode 100644
index 0000000000..e39b3c0a54
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/vfs/DigestHashFunctionTest.java
@@ -0,0 +1,67 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.lib.vfs;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.common.hash.Hashing;
+import com.google.devtools.build.lib.vfs.DigestHashFunction.DigestFunctionConverter;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/**
+ * Tests for DigestHashFunction, notably that the static instances can be compared with reference
+ * equality.
+ */
+@RunWith(JUnit4.class)
+public class DigestHashFunctionTest {
+ private final DigestFunctionConverter converter = new DigestFunctionConverter();
+
+ @Test
+ public void convertReturnsTheSameValueAsTheConstant() throws Exception {
+ assertThat(converter.convert("sha-256")).isSameAs(DigestHashFunction.SHA256);
+ assertThat(converter.convert("SHA-256")).isSameAs(DigestHashFunction.SHA256);
+ assertThat(converter.convert("SHA256")).isSameAs(DigestHashFunction.SHA256);
+ assertThat(converter.convert("sha256")).isSameAs(DigestHashFunction.SHA256);
+
+ assertThat(converter.convert("SHA-1")).isSameAs(DigestHashFunction.SHA1);
+ assertThat(converter.convert("sha-1")).isSameAs(DigestHashFunction.SHA1);
+ assertThat(converter.convert("SHA1")).isSameAs(DigestHashFunction.SHA1);
+ assertThat(converter.convert("sha1")).isSameAs(DigestHashFunction.SHA1);
+
+ assertThat(converter.convert("MD5")).isSameAs(DigestHashFunction.MD5);
+ assertThat(converter.convert("md5")).isSameAs(DigestHashFunction.MD5);
+ }
+
+ @Test
+ public void lateRegistrationGetsPickedUpByConverter() throws Exception {
+ DigestHashFunction.register(Hashing.goodFastHash(32), "goodFastHash32");
+
+ assertThat(converter.convert("goodFastHash32")).isSameAs(converter.convert("GOODFASTHASH32"));
+ }
+
+ @Test
+ public void lateRegistrationWithAlternativeNamesGetsPickedUpByConverter() throws Exception {
+ DigestHashFunction.register(
+ Hashing.goodFastHash(64), "goodFastHash64", "goodFastHash-64", "good-fast-hash-64");
+
+ assertThat(converter.convert("goodFastHash64")).isSameAs(converter.convert("GOODFASTHASH64"));
+ assertThat(converter.convert("goodFastHash64")).isSameAs(converter.convert("goodFastHash-64"));
+ assertThat(converter.convert("goodFastHash64"))
+ .isSameAs(converter.convert("good-fast-hash-64"));
+ assertThat(converter.convert("goodFastHash64"))
+ .isSameAs(converter.convert("GOOD-fast-HASH-64"));
+ }
+}
diff --git a/src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java b/src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java
index 39c75eaeaa..fdf94298d3 100644
--- a/src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java
+++ b/src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java
@@ -23,7 +23,6 @@ import com.google.devtools.build.lib.testutil.MoreAsserts;
import com.google.devtools.build.lib.testutil.TestUtils;
import com.google.devtools.build.lib.unix.NativePosixFiles;
import com.google.devtools.build.lib.util.Fingerprint;
-import com.google.devtools.build.lib.vfs.FileSystem.HashFunction;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -1305,7 +1304,8 @@ public abstract class FileSystemTest {
Fingerprint fp = new Fingerprint();
fp.addBytes(new byte[0]);
assertThat(fp.hexDigestAndReset())
- .isEqualTo(BaseEncoding.base16().lowerCase().encode(xFile.getDigest(HashFunction.MD5)));
+ .isEqualTo(
+ BaseEncoding.base16().lowerCase().encode(xFile.getDigest(DigestHashFunction.MD5)));
}
@Test
@@ -1318,7 +1318,8 @@ public abstract class FileSystemTest {
Fingerprint fp = new Fingerprint();
fp.addBytes(buffer);
assertThat(fp.hexDigestAndReset())
- .isEqualTo(BaseEncoding.base16().lowerCase().encode(xFile.getDigest(HashFunction.MD5)));
+ .isEqualTo(
+ BaseEncoding.base16().lowerCase().encode(xFile.getDigest(DigestHashFunction.MD5)));
}
@Test
diff --git a/src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/RemoteWorker.java b/src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/RemoteWorker.java
index 6f6b2c111e..bf4d89123d 100644
--- a/src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/RemoteWorker.java
+++ b/src/tools/remote/src/main/java/com/google/devtools/build/remote/worker/RemoteWorker.java
@@ -43,8 +43,9 @@ import com.google.devtools.build.lib.shell.CommandResult;
import com.google.devtools.build.lib.util.OS;
import com.google.devtools.build.lib.util.ProcessUtils;
import com.google.devtools.build.lib.util.SingleLineFormatter;
+import com.google.devtools.build.lib.vfs.DigestHashFunction;
+import com.google.devtools.build.lib.vfs.DigestHashFunction.DigestFunctionConverter;
import com.google.devtools.build.lib.vfs.FileSystem;
-import com.google.devtools.build.lib.vfs.FileSystem.HashFunction;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.JavaIoFileSystem;
import com.google.devtools.build.lib.vfs.Path;
@@ -93,11 +94,11 @@ public final class RemoteWorker {
private final ExecutionImplBase execServer;
static FileSystem getFileSystem() {
- final HashFunction hashFunction;
+ final DigestHashFunction hashFunction;
String value = null;
try {
value = System.getProperty("bazel.DigestFunction", "SHA256");
- hashFunction = new HashFunction.Converter().convert(value);
+ hashFunction = new DigestFunctionConverter().convert(value);
} catch (OptionsParsingException e) {
throw new Error("The specified hash function '" + value + "' is not supported.");
}