Add #getFastDigest method to SyscallCache and use it in DigestUtils. Thread the real per-build SyscallCache through to everywhere that calls into DigestUtils.
This leaves FileStateValue's call of #getFastDigest as the main undelegated one. A follow-up change will get rid of that usage too.
There should be no observable difference from this change: the only new actual usage of SyscallCache is in DigestUtils, which calls getFastDigest, which just delegates back to the Path for now.
PiperOrigin-RevId: 424972494
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionContext.java b/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionContext.java
index 9230394..ce283b1 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionContext.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionContext.java
@@ -381,11 +381,7 @@
return discoveredModulesPruner;
}
- /**
- * This only exists for loose header checking (and shouldn't exist at all).
- *
- * <p>Do NOT use from any other place.
- */
+ /** This only exists for loose header checking and as a helper for digest computations. */
public SyscallCache getSyscallCache() {
return syscallCache;
}
diff --git a/src/main/java/com/google/devtools/build/lib/actions/FileArtifactValue.java b/src/main/java/com/google/devtools/build/lib/actions/FileArtifactValue.java
index d74ed51..4166cc0 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/FileArtifactValue.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/FileArtifactValue.java
@@ -29,6 +29,7 @@
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.Symlinks;
+import com.google.devtools.build.lib.vfs.SyscallCache;
import com.google.devtools.build.skyframe.SkyValue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -189,8 +190,8 @@
@SerializationConstant
public static final FileArtifactValue OMITTED_FILE_MARKER = new OmittedFileValue();
- public static FileArtifactValue createForSourceArtifact(Artifact artifact, FileValue fileValue)
- throws IOException {
+ public static FileArtifactValue createForSourceArtifact(
+ Artifact artifact, FileValue fileValue, SyscallCache syscallCache) throws IOException {
// Artifacts with known generating actions should obtain the derived artifact's SkyValue
// from the generating action, instead.
Preconditions.checkState(!artifact.hasKnownGeneratingAction());
@@ -201,7 +202,8 @@
isFile,
isFile ? fileValue.getSize() : 0,
isFile ? fileValue.realFileStateValue().getContentsProxy() : null,
- isFile ? fileValue.getDigest() : null);
+ isFile ? fileValue.getDigest() : null,
+ syscallCache);
}
public static FileArtifactValue createFromInjectedDigest(
@@ -219,16 +221,27 @@
// Caution: there's a race condition between stating the file and computing the digest. We need
// to stat first, since we're using the stat to detect changes. We follow symlinks here to be
// consistent with getDigest.
- return createFromStat(path, path.stat(Symlinks.FOLLOW));
+ return createFromStat(path, path.stat(Symlinks.FOLLOW), SyscallCache.NO_CACHE);
}
- public static FileArtifactValue createFromStat(Path path, FileStatus stat) throws IOException {
+ public static FileArtifactValue createFromStat(
+ Path path, FileStatus stat, SyscallCache syscallCache) throws IOException {
return create(
- path, stat.isFile(), stat.getSize(), FileContentsProxy.create(stat), /*digest=*/ null);
+ path,
+ stat.isFile(),
+ stat.getSize(),
+ FileContentsProxy.create(stat),
+ /*digest=*/ null,
+ syscallCache);
}
private static FileArtifactValue create(
- Path path, boolean isFile, long size, FileContentsProxy proxy, @Nullable byte[] digest)
+ Path path,
+ boolean isFile,
+ long size,
+ FileContentsProxy proxy,
+ @Nullable byte[] digest,
+ SyscallCache syscallCache)
throws IOException {
if (!isFile) {
// In this case, we need to store the mtime because the action cache uses mtime for
@@ -237,7 +250,7 @@
return new DirectoryArtifactValue(path.getLastModifiedTime());
}
if (digest == null) {
- digest = DigestUtils.getDigestWithManualFallback(path, size);
+ digest = DigestUtils.getDigestWithManualFallback(path, size, syscallCache);
}
Preconditions.checkState(digest != null, path);
return createForNormalFile(digest, proxy, size);
@@ -275,9 +288,9 @@
* Create a FileArtifactValue using the {@link Path} and size. FileArtifactValue#create will
* handle getting the digest using the Path and size values.
*/
- public static FileArtifactValue createForNormalFileUsingPath(Path path, long size)
- throws IOException {
- return create(path, /*isFile=*/ true, size, /*proxy=*/ null, /*digest=*/ null);
+ public static FileArtifactValue createForNormalFileUsingPath(
+ Path path, long size, SyscallCache syscallCache) throws IOException {
+ return create(path, /*isFile=*/ true, size, /*proxy=*/ null, /*digest=*/ null, syscallCache);
}
public static FileArtifactValue createForDirectoryWithHash(byte[] digest) {
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/BUILD b/src/main/java/com/google/devtools/build/lib/bazel/BUILD
index b6f8718..47e7e4e 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/bazel/BUILD
@@ -166,6 +166,7 @@
srcs = ["ResolvedEvent.java"],
deps = [
"//src/main/java/com/google/devtools/build/lib/events",
+ "//src/main/java/com/google/devtools/build/lib/vfs",
],
)
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java b/src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java
index ec7fd5a..12ab3a3 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/BazelRepositoryModule.java
@@ -270,6 +270,7 @@
ProcessWrapper processWrapper = ProcessWrapper.fromCommandEnvironment(env);
starlarkRepositoryFunction.setProcessWrapper(processWrapper);
+ starlarkRepositoryFunction.setSyscallCache(env.getSyscallCache());
singleExtensionEvalFunction.setProcessWrapper(processWrapper);
RepositoryOptions repoOptions = env.getOptions().getOptions(RepositoryOptions.class);
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/ResolvedEvent.java b/src/main/java/com/google/devtools/build/lib/bazel/ResolvedEvent.java
index 89c9cc1..af12b47 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/ResolvedEvent.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/ResolvedEvent.java
@@ -15,6 +15,7 @@
package com.google.devtools.build.lib.bazel;
import com.google.devtools.build.lib.events.ExtendedEventHandler;
+import com.google.devtools.build.lib.vfs.SyscallCache;
/** Interface for events reporting information to be added to a resolved file. */
public interface ResolvedEvent extends ExtendedEventHandler.ProgressLike {
@@ -22,5 +23,5 @@
String getName();
/** The entry for the list of resolved Information. */
- Object getResolvedInformation();
+ Object getResolvedInformation(SyscallCache syscallCache);
}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/SpawnLogModule.java b/src/main/java/com/google/devtools/build/lib/bazel/SpawnLogModule.java
index 051db54..030ea2d 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/SpawnLogModule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/SpawnLogModule.java
@@ -117,7 +117,10 @@
spawnLogContext =
new SpawnLogContext(
- env.getExecRoot(), outStream, env.getOptions().getOptions(RemoteOptions.class));
+ env.getExecRoot(),
+ outStream,
+ env.getOptions().getOptions(RemoteOptions.class),
+ env.getSyscallCache());
}
@Override
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/commands/SyncCommand.java b/src/main/java/com/google/devtools/build/lib/bazel/commands/SyncCommand.java
index bd29405..8c84cb0 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/commands/SyncCommand.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/commands/SyncCommand.java
@@ -52,6 +52,7 @@
import com.google.devtools.build.lib.util.ExitCode;
import com.google.devtools.build.lib.util.InterruptedFailureDetails;
import com.google.devtools.build.lib.vfs.RootedPath;
+import com.google.devtools.build.lib.vfs.SyscallCache;
import com.google.devtools.build.skyframe.EvaluationContext;
import com.google.devtools.build.skyframe.EvaluationResult;
import com.google.devtools.build.skyframe.SkyKey;
@@ -263,7 +264,7 @@
}
@Override
- public Object getResolvedInformation() {
+ public Object getResolvedInformation(SyscallCache syscallCache) {
return ImmutableMap.<String, Object>builder()
.put(ResolvedHashesFunction.ORIGINAL_RULE_CLASS, "bind")
.put(
@@ -295,7 +296,7 @@
}
@Override
- public Object getResolvedInformation() {
+ public Object getResolvedInformation(SyscallCache syscallCache) {
return ImmutableMap.<String, Object>builder()
.put(ResolvedHashesFunction.ORIGINAL_RULE_CLASS, ruleName)
.put(
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/LocalConfigPlatformFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/LocalConfigPlatformFunction.java
index f57f63c..2672784 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/LocalConfigPlatformFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/LocalConfigPlatformFunction.java
@@ -26,6 +26,7 @@
import com.google.devtools.build.lib.util.CPU;
import com.google.devtools.build.lib.util.OS;
import com.google.devtools.build.lib.vfs.Path;
+import com.google.devtools.build.lib.vfs.SyscallCache;
import com.google.devtools.build.skyframe.SkyFunction.Environment;
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
import com.google.devtools.build.skyframe.SkyKey;
@@ -85,7 +86,7 @@
}
@Override
- public Object getResolvedInformation() {
+ public Object getResolvedInformation(SyscallCache syscallCache) {
String repr = String.format("local_config_platform(name = '%s')", name);
return ImmutableMap.<String, Object>builder()
.put(ResolvedHashesFunction.ORIGINAL_RULE_CLASS, LocalConfigPlatformRule.NAME)
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedEvent.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedEvent.java
index 0d9d01f..97f8dca 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedEvent.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedEvent.java
@@ -30,6 +30,7 @@
import com.google.devtools.build.lib.packages.StructImpl;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.vfs.Path;
+import com.google.devtools.build.lib.vfs.SyscallCache;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@@ -164,13 +165,13 @@
* Ensure that the {@code resolvedInformation} and the {@code directoryDigest} fields are
* initialized properly. Does nothing, if the values are computed already.
*/
- private synchronized void finalizeResolvedInformation() {
+ private synchronized void finalizeResolvedInformation(SyscallCache syscallCache) {
if (resolvedInformation != null) {
return;
}
String digest = "[unavailable]";
try {
- digest = outputDirectory.getDirectoryDigest();
+ digest = outputDirectory.getDirectoryDigest(syscallCache);
repositoryBuilder.put(OUTPUT_TREE_HASH, digest);
} catch (IOException e) {
// Digest not available, but we still have to report that a repository rule
@@ -190,8 +191,8 @@
* Returns the entry for the given rule invocation in a format suitable for WORKSPACE.resolved.
*/
@Override
- public Object getResolvedInformation() {
- finalizeResolvedInformation();
+ public Object getResolvedInformation(SyscallCache syscallCache) {
+ finalizeResolvedInformation(syscallCache);
return resolvedInformation;
}
@@ -201,8 +202,8 @@
return name;
}
- public String getDirectoryDigest() {
- finalizeResolvedInformation();
+ public String getDirectoryDigest(SyscallCache syscallCache) {
+ finalizeResolvedInformation(syscallCache);
return directoryDigest;
}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedModule.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedModule.java
index ccbc982..5f17822 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedModule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryResolvedModule.java
@@ -24,6 +24,7 @@
import com.google.devtools.build.lib.runtime.BlazeModule;
import com.google.devtools.build.lib.runtime.Command;
import com.google.devtools.build.lib.runtime.CommandEnvironment;
+import com.google.devtools.build.lib.vfs.SyscallCache;
import com.google.devtools.common.options.OptionsBase;
import java.io.File;
import java.io.IOException;
@@ -41,6 +42,7 @@
private Map<String, Object> resolvedValues;
private String resolvedFile;
private ImmutableList<String> orderedNames;
+ private SyscallCache syscallCache;
@Override
public Iterable<Class<? extends OptionsBase>> getCommandOptions(Command command) {
@@ -61,6 +63,7 @@
} else {
this.resolvedFile = null;
}
+ this.syscallCache = env.getSyscallCache();
}
@Override
@@ -97,7 +100,7 @@
@Subscribe
public void resolved(ResolvedEvent event) {
if (resolvedValues != null) {
- resolvedValues.put(event.getName(), event.getResolvedInformation());
+ resolvedValues.put(event.getName(), event.getResolvedInformation(syscallCache));
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryFunction.java
index 90414eb..138c756 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryFunction.java
@@ -43,6 +43,7 @@
import com.google.devtools.build.lib.skyframe.PrecomputedValue;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
+import com.google.devtools.build.lib.vfs.SyscallCache;
import com.google.devtools.build.skyframe.SkyFunction.Environment;
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
import com.google.devtools.build.skyframe.SkyKey;
@@ -66,6 +67,7 @@
private double timeoutScaling = 1.0;
@Nullable private ProcessWrapper processWrapper = null;
@Nullable private RepositoryRemoteExecutor repositoryRemoteExecutor;
+ @Nullable private SyscallCache syscallCache;
public StarlarkRepositoryFunction(DownloadManager downloadManager) {
this.downloadManager = downloadManager;
@@ -79,6 +81,10 @@
this.processWrapper = processWrapper;
}
+ public void setSyscallCache(SyscallCache syscallCache) {
+ this.syscallCache = syscallCache;
+ }
+
static String describeSemantics(StarlarkSemantics semantics) {
// Here we use the hash code provided by AutoValue. This is unique, as long
// as the number of bits in the StarlarkSemantics is small enough. We will have to
@@ -236,7 +242,7 @@
if (verificationRules.contains(ruleClass)) {
String expectedHash = resolvedHashes.get(rule.getName());
if (expectedHash != null) {
- String actualHash = resolved.getDirectoryDigest();
+ String actualHash = resolved.getDirectoryDigest(syscallCache);
if (!expectedHash.equals(actualHash)) {
throw new RepositoryFunctionException(
new IOException(
diff --git a/src/main/java/com/google/devtools/build/lib/exec/RunfilesTreeUpdater.java b/src/main/java/com/google/devtools/build/lib/exec/RunfilesTreeUpdater.java
index 3316af9..57bdd64 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/RunfilesTreeUpdater.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/RunfilesTreeUpdater.java
@@ -24,6 +24,7 @@
import com.google.devtools.build.lib.vfs.DigestUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
+import com.google.devtools.build.lib.vfs.SyscallCache;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
@@ -66,7 +67,8 @@
BinTools binTools,
ImmutableMap<String, String> env,
OutErr outErr,
- boolean enableRunfiles)
+ boolean enableRunfiles,
+ SyscallCache syscallCache)
throws IOException, ExecException, InterruptedException {
Path runfilesDirPath = execRoot.getRelative(runfilesDir);
Path inputManifest = RunfilesSupport.inputManifestPath(runfilesDirPath);
@@ -82,8 +84,9 @@
// an up-to-date check.
if (!outputManifest.isSymbolicLink()
&& Arrays.equals(
- DigestUtils.getDigestWithManualFallbackWhenSizeUnknown(outputManifest),
- DigestUtils.getDigestWithManualFallbackWhenSizeUnknown(inputManifest))) {
+ DigestUtils.getDigestWithManualFallbackWhenSizeUnknown(outputManifest, syscallCache),
+ DigestUtils.getDigestWithManualFallbackWhenSizeUnknown(
+ inputManifest, syscallCache))) {
return;
}
} catch (IOException e) {
@@ -131,7 +134,8 @@
RunfilesSupplier runfilesSupplier,
BinTools binTools,
ImmutableMap<String, String> env,
- OutErr outErr)
+ OutErr outErr,
+ SyscallCache syscallCache)
throws ExecException, IOException, InterruptedException {
for (Map.Entry<PathFragment, Map<PathFragment, Artifact>> runfiles :
runfilesSupplier.getMappings().entrySet()) {
@@ -154,7 +158,8 @@
binTools,
env,
outErr,
- runfilesSupplier.isRunfileLinksEnabled(runfilesDir));
+ runfilesSupplier.isRunfileLinksEnabled(runfilesDir),
+ syscallCache);
}
} finally {
decrementRefcnt(runfilesDir);
diff --git a/src/main/java/com/google/devtools/build/lib/exec/SingleBuildFileCache.java b/src/main/java/com/google/devtools/build/lib/exec/SingleBuildFileCache.java
index 1a0ff62..cc4fda2 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/SingleBuildFileCache.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/SingleBuildFileCache.java
@@ -23,6 +23,7 @@
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.Symlinks;
+import com.google.devtools.build.lib.vfs.SyscallCache;
import java.io.IOException;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
@@ -46,8 +47,10 @@
// unlikely that this default will adversely affect memory in most cases.
.initialCapacity(10000)
.build();
+ private final SyscallCache syscallCache;
- public SingleBuildFileCache(String cwd, FileSystem fs) {
+ public SingleBuildFileCache(String cwd, FileSystem fs, SyscallCache syscallCache) {
+ this.syscallCache = syscallCache;
this.execRoot = fs.getPath(cwd);
}
@@ -60,7 +63,12 @@
Path path = ActionInputHelper.toInputPath(input, execRoot);
FileArtifactValue metadata;
try {
- metadata = FileArtifactValue.createFromStat(path, path.stat(Symlinks.FOLLOW));
+ metadata =
+ FileArtifactValue.createFromStat(
+ path,
+ // TODO(b/199940216): should we use syscallCache here since caching anyway?
+ path.stat(Symlinks.FOLLOW),
+ syscallCache);
} catch (IOException e) {
return new ActionInputMetadata(input, e);
}
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 b1eab17..1ca1e83 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
@@ -38,6 +38,7 @@
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.Symlinks;
+import com.google.devtools.build.lib.vfs.SyscallCache;
import com.google.protobuf.util.Durations;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -57,17 +58,22 @@
* A logging utility for spawns.
*/
public class SpawnLogContext implements ActionContext {
-
private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
+
private final Path execRoot;
private final MessageOutputStream executionLog;
@Nullable private final RemoteOptions remoteOptions;
+ private final SyscallCache syscallCache;
public SpawnLogContext(
- Path execRoot, MessageOutputStream executionLog, @Nullable RemoteOptions remoteOptions) {
+ Path execRoot,
+ MessageOutputStream executionLog,
+ @Nullable RemoteOptions remoteOptions,
+ SyscallCache syscallCache) {
this.execRoot = execRoot;
this.executionLog = executionLog;
this.remoteOptions = remoteOptions;
+ this.syscallCache = syscallCache;
}
/** Log the executed spawn to the output stream. */
@@ -99,7 +105,7 @@
if (inputPath.isDirectory()) {
listDirectoryContents(inputPath, builder::addInputs, metadataProvider);
} else {
- Digest digest = computeDigest(input, null, metadataProvider);
+ Digest digest = computeDigest(input, null, metadataProvider, syscallCache);
builder.addInputsBuilder().setPath(input.getExecPathString()).setDigest(digest);
}
}
@@ -120,7 +126,8 @@
File.Builder outputBuilder = builder.addActualOutputsBuilder();
outputBuilder.setPath(path.relativeTo(execRoot).toString());
try {
- outputBuilder.setDigest(computeDigest(e.getValue(), path, metadataProvider));
+ outputBuilder.setDigest(
+ computeDigest(e.getValue(), path, metadataProvider, syscallCache));
} catch (IOException ex) {
logger.atWarning().withCause(ex).log("Error computing spawn event output properties");
}
@@ -191,7 +198,7 @@
addFile.accept(
File.newBuilder()
.setPath(child.relativeTo(execRoot).toString())
- .setDigest(computeDigest(null, child, metadataProvider))
+ .setDigest(computeDigest(null, child, metadataProvider, syscallCache))
.build());
}
}
@@ -205,7 +212,10 @@
* Metadata cache first, if it is available, and fall back to digesting the contents manually.
*/
private Digest computeDigest(
- @Nullable ActionInput input, @Nullable Path path, MetadataProvider metadataProvider)
+ @Nullable ActionInput input,
+ @Nullable Path path,
+ MetadataProvider metadataProvider,
+ SyscallCache syscallCache)
throws IOException {
Preconditions.checkArgument(input != null || path != null);
DigestHashFunction hashFunction = execRoot.getFileSystem().getDigestFunction();
@@ -243,7 +253,9 @@
long fileSize = path.getFileSize();
return digest
.setHash(
- HashCode.fromBytes(DigestUtils.getDigestWithManualFallback(path, fileSize)).toString())
+ HashCode.fromBytes(
+ DigestUtils.getDigestWithManualFallback(path, fileSize, syscallCache))
+ .toString())
.setSizeBytes(fileSize)
.build();
}
diff --git a/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java
index 259b7e0..15e1b5d 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java
@@ -59,6 +59,7 @@
import com.google.devtools.build.lib.util.OS;
import com.google.devtools.build.lib.util.io.FileOutErr;
import com.google.devtools.build.lib.vfs.Path;
+import com.google.devtools.build.lib.vfs.SyscallCache;
import com.google.errorprone.annotations.FormatMethod;
import com.google.errorprone.annotations.FormatString;
import java.io.File;
@@ -91,6 +92,7 @@
private final String hostName;
private final LocalExecutionOptions localExecutionOptions;
+ private final SyscallCache syscallCache;
@Nullable private final ProcessWrapper processWrapper;
@@ -106,10 +108,12 @@
LocalEnvProvider localEnvProvider,
BinTools binTools,
ProcessWrapper processWrapper,
+ SyscallCache syscallCache,
RunfilesTreeUpdater runfilesTreeUpdater) {
this.execRoot = execRoot;
this.processWrapper = processWrapper;
this.localExecutionOptions = Preconditions.checkNotNull(localExecutionOptions);
+ this.syscallCache = syscallCache;
this.hostName = NetUtil.getCachedShortHostName();
this.resourceManager = resourceManager;
this.localEnvProvider = localEnvProvider;
@@ -134,7 +138,8 @@
spawn.getRunfilesSupplier(),
binTools,
spawn.getEnvironment(),
- context.getFileOutErr());
+ context.getFileOutErr(),
+ syscallCache);
spawnMetrics.addSetupTime(setupTimeStopwatch.elapsed());
try (SilentCloseable c =
diff --git a/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploader.java b/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploader.java
index 7c16c29..c1cfc69 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploader.java
+++ b/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploader.java
@@ -33,6 +33,7 @@
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.Path;
+import com.google.devtools.build.lib.vfs.SyscallCache;
import io.netty.util.AbstractReferenceCounted;
import io.netty.util.ReferenceCounted;
import io.reactivex.rxjava3.core.Flowable;
@@ -68,6 +69,7 @@
private final Set<Path> omittedFiles = Sets.newConcurrentHashSet();
private final Set<Path> omittedTreeRoots = Sets.newConcurrentHashSet();
+ private final SyscallCache syscallCache;
ByteStreamBuildEventArtifactUploader(
Executor executor,
@@ -76,7 +78,8 @@
RemoteCache remoteCache,
String remoteServerInstanceName,
String buildRequestId,
- String commandId) {
+ String commandId,
+ SyscallCache syscallCache) {
this.executor = executor;
this.reporter = reporter;
this.verboseFailures = verboseFailures;
@@ -85,6 +88,7 @@
this.commandId = commandId;
this.remoteServerInstanceName = remoteServerInstanceName;
this.scheduler = Schedulers.from(executor);
+ this.syscallCache = syscallCache;
}
public void omitFile(Path file) {
@@ -151,7 +155,7 @@
}
}
- DigestUtil digestUtil = new DigestUtil(file.getFileSystem().getDigestFunction());
+ DigestUtil digestUtil = new DigestUtil(syscallCache, file.getFileSystem().getDigestFunction());
Digest digest = digestUtil.compute(file);
return new PathMetadata(file, digest, /* directory= */ false, isRemoteFile(file));
}
diff --git a/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploaderFactory.java b/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploaderFactory.java
index 23fa5d5..5ff3cfa 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploaderFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploaderFactory.java
@@ -63,7 +63,8 @@
remoteCache.retain(),
remoteServerInstanceName,
buildRequestId,
- commandId);
+ commandId,
+ env.getSyscallCache());
return uploader;
}
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 30560a6..47bc77e 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
@@ -260,7 +260,7 @@
AuthAndTLSOptions authAndTlsOptions = env.getOptions().getOptions(AuthAndTLSOptions.class);
DigestHashFunction hashFn = env.getRuntime().getFileSystem().getDigestFunction();
- DigestUtil digestUtil = new DigestUtil(hashFn);
+ DigestUtil digestUtil = new DigestUtil(env.getSyscallCache(), hashFn);
boolean verboseFailures = false;
ExecutionOptions executionOptions = env.getOptions().getOptions(ExecutionOptions.class);
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 1f949e4..59d5faf 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
@@ -25,6 +25,7 @@
import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.DigestUtils;
import com.google.devtools.build.lib.vfs.Path;
+import com.google.devtools.build.lib.vfs.SyscallCache;
import com.google.protobuf.Message;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -32,10 +33,11 @@
/** Utility methods to work with {@link Digest}. */
public class DigestUtil {
-
+ private final SyscallCache syscallCache;
private final DigestHashFunction hashFn;
- public DigestUtil(DigestHashFunction hashFn) {
+ public DigestUtil(SyscallCache syscallCache, DigestHashFunction hashFn) {
+ this.syscallCache = syscallCache;
this.hashFn = hashFn;
}
@@ -60,7 +62,8 @@
}
public Digest compute(Path file, long fileSize) throws IOException {
- return buildDigest(DigestUtils.getDigestWithManualFallback(file, fileSize), fileSize);
+ return buildDigest(
+ DigestUtils.getDigestWithManualFallback(file, fileSize, syscallCache), fileSize);
}
public Digest compute(VirtualActionInput input) throws IOException {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java
index 53b619a..79e623f 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java
@@ -21,6 +21,7 @@
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
+import com.google.devtools.build.lib.vfs.SyscallCache;
import com.google.devtools.build.skyframe.SkyFunction.Environment;
import com.google.devtools.build.skyframe.SkyKey;
import java.util.Map;
@@ -90,7 +91,7 @@
}
@Override
- public Object getResolvedInformation() {
+ public Object getResolvedInformation(SyscallCache syscallCache) {
return ImmutableMap.<String, Object>builder()
.put(ResolvedHashesFunction.ORIGINAL_RULE_CLASS, "local_repository")
.put(
diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java
index c2e0de3..c119225 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java
@@ -28,6 +28,7 @@
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.Root;
import com.google.devtools.build.lib.vfs.RootedPath;
+import com.google.devtools.build.lib.vfs.SyscallCache;
import com.google.devtools.build.skyframe.SkyFunction.Environment;
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
import com.google.devtools.build.skyframe.SkyKey;
@@ -204,7 +205,7 @@
}
@Override
- public Object getResolvedInformation() {
+ public Object getResolvedInformation(SyscallCache syscallCache) {
return ImmutableMap.<String, Object>builder()
.put(ResolvedHashesFunction.ORIGINAL_RULE_CLASS, "new_local_repository")
.put(ResolvedHashesFunction.ORIGINAL_ATTRIBUTES, orig)
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java b/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java
index 7d2fce9..de0b296e 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java
@@ -791,7 +791,8 @@
synchronized (fileCacheLock) {
if (fileCache == null) {
fileCache =
- new SingleBuildFileCache(getExecRoot().getPathString(), getRuntime().getFileSystem());
+ new SingleBuildFileCache(
+ getExecRoot().getPathString(), getRuntime().getFileSystem(), syscallCache);
}
return fileCache;
}
diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxModule.java b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxModule.java
index 1f2b1c1..f5ecba2 100644
--- a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxModule.java
+++ b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxModule.java
@@ -33,7 +33,6 @@
import com.google.devtools.build.lib.exec.ExecutionOptions;
import com.google.devtools.build.lib.exec.RunfilesTreeUpdater;
import com.google.devtools.build.lib.exec.SpawnRunner;
-import com.google.devtools.build.lib.exec.SpawnRunner.SpawnExecutionContext;
import com.google.devtools.build.lib.exec.SpawnStrategyRegistry;
import com.google.devtools.build.lib.exec.TreeDeleter;
import com.google.devtools.build.lib.exec.local.LocalEnvProvider;
@@ -453,6 +452,7 @@
env.getBlazeWorkspace().getBinTools(),
ProcessWrapper.fromCommandEnvironment(env),
// TODO(buchgr): Replace singleton by a command-scoped RunfilesTreeUpdater
+ env.getSyscallCache(),
RunfilesTreeUpdater.INSTANCE);
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
index e8cd2c9..f170fee 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
@@ -47,6 +47,7 @@
import com.google.devtools.build.lib.util.Fingerprint;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.vfs.RootedPath;
+import com.google.devtools.build.lib.vfs.SyscallCache;
import com.google.devtools.build.skyframe.SkyFunction;
import com.google.devtools.build.skyframe.SkyFunctionException;
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
@@ -68,6 +69,7 @@
class ArtifactFunction implements SkyFunction {
private final Supplier<Boolean> mkdirForTreeArtifacts;
private final MetadataConsumerForMetrics sourceArtifactsSeen;
+ private final Supplier<SyscallCache> syscallCache;
static final class MissingArtifactValue implements SkyValue {
private final DetailedExitCode detailedExitCode;
@@ -92,9 +94,12 @@
}
public ArtifactFunction(
- Supplier<Boolean> mkdirForTreeArtifacts, MetadataConsumerForMetrics sourceArtifactsSeen) {
+ Supplier<Boolean> mkdirForTreeArtifacts,
+ MetadataConsumerForMetrics sourceArtifactsSeen,
+ Supplier<SyscallCache> syscallCache) {
this.mkdirForTreeArtifacts = mkdirForTreeArtifacts;
this.sourceArtifactsSeen = sourceArtifactsSeen;
+ this.syscallCache = syscallCache;
}
@Override
@@ -274,7 +279,8 @@
if (!fileValue.isDirectory() || !TrackSourceDirectoriesFlag.trackSourceDirectories()) {
FileArtifactValue metadata;
try {
- metadata = FileArtifactValue.createForSourceArtifact(artifact, fileValue);
+ metadata =
+ FileArtifactValue.createForSourceArtifact(artifact, fileValue, syscallCache.get());
} catch (IOException e) {
throw new ArtifactFunctionException(
SourceArtifactException.create(artifact, e), Transience.TRANSIENT);
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
index 2683512..12f56ec 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
@@ -66,6 +66,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.function.Supplier;
import javax.annotation.Nullable;
/** A {@link SkyFunction} to build {@link RecursiveFilesystemTraversalValue}s. */
@@ -144,6 +145,12 @@
}
}
+ private final Supplier<SyscallCache> syscallCache;
+
+ RecursiveFilesystemTraversalFunction(Supplier<SyscallCache> syscallCache) {
+ this.syscallCache = syscallCache;
+ }
+
@Nullable
@Override
public SkyValue compute(SkyKey skyKey, Environment env)
@@ -153,7 +160,7 @@
Profiler.instance()
.profile(ProfilerTask.FILESYSTEM_TRAVERSAL, traversal.getRoot().toString())) {
// Stat the traversal root.
- FileInfo rootInfo = lookUpFileInfo(env, traversal);
+ FileInfo rootInfo = lookUpFileInfo(env, traversal, syscallCache.get());
if (rootInfo == null) {
return null;
}
@@ -188,7 +195,8 @@
}
// Otherwise the root is a directory or a symlink to one.
- PkgLookupResult pkgLookupResult = checkIfPackage(env, traversal, rootInfo);
+ PkgLookupResult pkgLookupResult =
+ checkIfPackage(env, traversal, rootInfo, syscallCache.get());
if (pkgLookupResult == null) {
return null;
}
@@ -306,7 +314,8 @@
}
@Nullable
- private static FileInfo lookUpFileInfo(Environment env, TraversalRequest traversal)
+ private static FileInfo lookUpFileInfo(
+ Environment env, TraversalRequest traversal, SyscallCache syscallCache)
throws IOException, InterruptedException {
if (traversal.isRootGenerated) {
HasDigest fsVal = null;
@@ -366,7 +375,8 @@
if (fsVal == null) {
fsVal = fileState;
}
- return new FileInfo(type, withDigest(fsVal, path), realPath, unresolvedLinkTarget);
+ return new FileInfo(
+ type, withDigest(fsVal, path, syscallCache), realPath, unresolvedLinkTarget);
}
} else {
// Stat the file.
@@ -403,14 +413,14 @@
Path path = traversal.root.asRootedPath().asPath();
return new FileInfo(
type,
- withDigest(fileValue.realFileStateValue(), path),
+ withDigest(fileValue.realFileStateValue(), path, syscallCache),
fileValue.realRootedPath(),
unresolvedLinkTarget);
} else {
// If it doesn't exist, or it's a dangling symlink, we still want to handle that gracefully.
return new FileInfo(
fileValue.isSymlink() ? FileType.DANGLING_SYMLINK : FileType.NONEXISTENT,
- withDigest(fileValue.realFileStateValue(), null),
+ withDigest(fileValue.realFileStateValue(), null, syscallCache),
null,
fileValue.isSymlink() ? fileValue.getUnresolvedLinkTarget() : null);
}
@@ -430,7 +440,8 @@
* @return transformed HasDigest value based on the digest field and object type.
*/
@VisibleForTesting
- static HasDigest withDigest(HasDigest fsVal, Path path) throws IOException {
+ static HasDigest withDigest(HasDigest fsVal, Path path, SyscallCache syscallCache)
+ throws IOException {
if (fsVal instanceof FileStateValue) {
FileStateValue fsv = (FileStateValue) fsVal;
if (fsv instanceof RegularFileStateValue) {
@@ -440,7 +451,7 @@
? FileArtifactValue.createForVirtualActionInput(rfsv.getDigest(), rfsv.getSize())
// Otherwise, create a file FileArtifactValue (RegularFileArtifactValue) based on the
// path and size.
- : FileArtifactValue.createForNormalFileUsingPath(path, rfsv.getSize());
+ : FileArtifactValue.createForNormalFileUsingPath(path, rfsv.getSize(), syscallCache);
}
return new HasDigest.ByteStringDigest(fsv.getValueFingerprint());
} else if (fsVal instanceof FileArtifactValue) {
@@ -452,7 +463,7 @@
// In the case there is a directory, the HasDigest value should not be converted. Otherwise,
// if the HasDigest value is a file, convert it using the Path and size values.
return fav.getType().isFile()
- ? FileArtifactValue.createForNormalFileUsingPath(path, fav.getSize())
+ ? FileArtifactValue.createForNormalFileUsingPath(path, fav.getSize(), syscallCache)
: new HasDigest.ByteStringDigest(fav.getValueFingerprint());
}
return fsVal;
@@ -510,7 +521,7 @@
* a package is found, but under a different root than expected)
*/
private static PkgLookupResult checkIfPackage(
- Environment env, TraversalRequest traversal, FileInfo rootInfo)
+ Environment env, TraversalRequest traversal, FileInfo rootInfo, SyscallCache syscallCache)
throws IOException, InterruptedException, BuildFileNotFoundException {
Preconditions.checkArgument(rootInfo.type.exists() && !rootInfo.type.isFile(),
"{%s} {%s}", traversal, rootInfo);
@@ -540,7 +551,7 @@
// However the root of this package is different from what we expected. stat() the real
// BUILD file of that package.
traversal = traversal.forChangedRootPath(pkgRoot);
- rootInfo = lookUpFileInfo(env, traversal);
+ rootInfo = lookUpFileInfo(env, traversal, syscallCache);
Verify.verify(rootInfo.type.exists(), "{%s} {%s}", traversal, rootInfo);
}
return PkgLookupResult.pkg(traversal, rootInfo);
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
index ec1a6f8..5b6f252 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
@@ -599,7 +599,8 @@
Artifact.ARTIFACT,
new ArtifactFunction(
() -> !skyframeActionExecutor.actionFileSystemType().inMemoryFileSystem(),
- sourceArtifactsSeen));
+ sourceArtifactsSeen,
+ syscallCacheRef::get));
map.put(
SkyFunctions.BUILD_INFO_COLLECTION,
new BuildInfoCollectionFunction(actionKeyContext, artifactFactory));
@@ -610,7 +611,8 @@
map.put(SkyFunctions.ACTION_EXECUTION, actionExecutionFunction);
this.actionExecutionFunction = actionExecutionFunction;
map.put(
- SkyFunctions.RECURSIVE_FILESYSTEM_TRAVERSAL, new RecursiveFilesystemTraversalFunction());
+ SkyFunctions.RECURSIVE_FILESYSTEM_TRAVERSAL,
+ new RecursiveFilesystemTraversalFunction(syscallCacheRef::get));
map.put(SkyFunctions.FILESET_ENTRY, new FilesetEntryFunction(directories::getExecRoot));
map.put(
SkyFunctions.ACTION_TEMPLATE_EXPANSION,
diff --git a/src/main/java/com/google/devtools/build/lib/standalone/StandaloneModule.java b/src/main/java/com/google/devtools/build/lib/standalone/StandaloneModule.java
index 79b92a2..1fde342 100644
--- a/src/main/java/com/google/devtools/build/lib/standalone/StandaloneModule.java
+++ b/src/main/java/com/google/devtools/build/lib/standalone/StandaloneModule.java
@@ -82,6 +82,7 @@
LocalEnvProvider.forCurrentOs(env.getClientEnv()),
env.getBlazeWorkspace().getBinTools(),
ProcessWrapper.fromCommandEnvironment(env),
+ env.getSyscallCache(),
// TODO(buchgr): Replace singleton by a command-scoped RunfilesTreeUpdater
RunfilesTreeUpdater.INSTANCE);
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/DigestUtils.java b/src/main/java/com/google/devtools/build/lib/vfs/DigestUtils.java
index d3841ea..afb473a 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/DigestUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/DigestUtils.java
@@ -156,8 +156,9 @@
* serially or in parallel. Files larger than a certain threshold will be read serially, in
* order to avoid excessive disk seeks.
*/
- public static byte[] getDigestWithManualFallback(Path path, long fileSize) throws IOException {
- byte[] digest = path.getFastDigest();
+ public static byte[] getDigestWithManualFallback(Path path, long fileSize, SyscallCache syscalls)
+ throws IOException {
+ byte[] digest = syscalls.getFastDigest(path);
return digest != null ? digest : manuallyComputeDigest(path, fileSize);
}
@@ -171,8 +172,9 @@
*
* @param path Path of the file.
*/
- public static byte[] getDigestWithManualFallbackWhenSizeUnknown(Path path) throws IOException {
- return getDigestWithManualFallback(path, -1);
+ public static byte[] getDigestWithManualFallbackWhenSizeUnknown(Path path, SyscallCache syscalls)
+ throws IOException {
+ return getDigestWithManualFallback(path, -1, syscalls);
}
/**
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 efcdf58..e7b9213 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
@@ -703,7 +703,7 @@
* @return a string representation of the bash of the directory
* @throws IOException if the digest could not be computed for any reason
*/
- public String getDirectoryDigest() throws IOException {
+ public String getDirectoryDigest(SyscallCache syscallCache) throws IOException {
ImmutableList<String> entries =
ImmutableList.sortedCopyOf(fileSystem.getDirectoryEntries(asFragment()));
Hasher hasher = fileSystem.getDigestFunction().getHashFunction().newHasher();
@@ -717,9 +717,10 @@
} else {
hasher.putChar('-');
}
- hasher.putBytes(DigestUtils.getDigestWithManualFallback(path, stat.getSize()));
+ hasher.putBytes(
+ DigestUtils.getDigestWithManualFallback(path, stat.getSize(), syscallCache));
} else if (stat.isDirectory()) {
- hasher.putChar('d').putUnencodedChars(path.getDirectoryDigest());
+ hasher.putChar('d').putUnencodedChars(path.getDirectoryDigest(syscallCache));
} else if (stat.isSymbolicLink()) {
PathFragment link = path.readSymbolicLink();
if (link.isAbsolute()) {
@@ -731,7 +732,8 @@
} else {
hasher.putChar('-');
}
- hasher.putBytes(DigestUtils.getDigestWithManualFallbackWhenSizeUnknown(resolved));
+ hasher.putBytes(
+ DigestUtils.getDigestWithManualFallbackWhenSizeUnknown(resolved, syscallCache));
} else {
// link to a non-file: include the link itself in the hash
hasher.putChar('l').putUnencodedChars(link.toString());
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/SyscallCache.java b/src/main/java/com/google/devtools/build/lib/vfs/SyscallCache.java
index 752197a..a9d0264 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/SyscallCache.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/SyscallCache.java
@@ -53,6 +53,14 @@
*/
Dirent.Type getType(Path path, Symlinks symlinks) throws IOException;
+ default byte[] getFastDigest(Path path) throws IOException {
+ return path.getFastDigest();
+ }
+
+ default byte[] getDigest(Path path) throws IOException {
+ return path.getDigest();
+ }
+
static Dirent.Type statusToDirentType(FileStatus status) {
if (status == null) {
return null;
diff --git a/src/main/java/com/google/devtools/build/lib/worker/WorkerModule.java b/src/main/java/com/google/devtools/build/lib/worker/WorkerModule.java
index 0670f97..cf40bb3 100644
--- a/src/main/java/com/google/devtools/build/lib/worker/WorkerModule.java
+++ b/src/main/java/com/google/devtools/build/lib/worker/WorkerModule.java
@@ -160,7 +160,8 @@
RunfilesTreeUpdater.INSTANCE,
env.getOptions().getOptions(WorkerOptions.class),
env.getEventBus(),
- Runtime.getRuntime());
+ Runtime.getRuntime(),
+ env.getSyscallCache());
ExecutionOptions executionOptions =
checkNotNull(env.getOptions().getOptions(ExecutionOptions.class));
registryBuilder.registerStrategy(
diff --git a/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnRunner.java
index dc30adc..8914e3d 100644
--- a/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnRunner.java
+++ b/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnRunner.java
@@ -62,6 +62,7 @@
import com.google.devtools.build.lib.util.io.FileOutErr;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
+import com.google.devtools.build.lib.vfs.SyscallCache;
import com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest;
import com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse;
import com.google.protobuf.ByteString;
@@ -108,6 +109,7 @@
private final WorkerParser workerParser;
private final AtomicInteger requestIdCounter = new AtomicInteger(1);
private final Runtime runtime;
+ private final SyscallCache syscallCache;
/** Mapping of worker ids to their metrics. */
private Map<Integer, WorkerMetric> workerIdToWorkerMetric = new ConcurrentHashMap<>();
@@ -123,7 +125,8 @@
RunfilesTreeUpdater runfilesTreeUpdater,
WorkerOptions workerOptions,
EventBus eventBus,
- Runtime runtime) {
+ Runtime runtime,
+ SyscallCache syscallCache) {
this.helpers = helpers;
this.execRoot = execRoot;
this.workers = Preconditions.checkNotNull(workers);
@@ -131,6 +134,7 @@
this.binTools = binTools;
this.resourceManager = resourceManager;
this.runfilesTreeUpdater = runfilesTreeUpdater;
+ this.syscallCache = syscallCache;
this.workerParser = new WorkerParser(execRoot, workerOptions, localEnvProvider, binTools);
this.workerOptions = workerOptions;
this.runtime = runtime;
@@ -186,7 +190,8 @@
spawn.getRunfilesSupplier(),
binTools,
spawn.getEnvironment(),
- context.getFileOutErr());
+ context.getFileOutErr(),
+ syscallCache);
MetadataProvider inputFileCache = context.getMetadataProvider();