use of com.google.devtools.build.lib.actions.cache.Metadata in project bazel by bazelbuild.
the class ActionCacheChecker method afterExecution.
public void afterExecution(Action action, Token token, MetadataHandler metadataHandler, Map<String, String> clientEnv) throws IOException {
if (!cacheConfig.enabled()) {
// Action cache is disabled, don't generate digests.
return;
}
Preconditions.checkArgument(token != null);
String key = token.cacheKey;
if (actionCache.get(key) != null) {
// This cache entry has already been updated by a shared action. We don't need to do it again.
return;
}
Map<String, String> usedClientEnv = computeUsedClientEnv(action, clientEnv);
ActionCache.Entry entry = new ActionCache.Entry(action.getKey(), usedClientEnv, action.discoversInputs());
for (Artifact output : action.getOutputs()) {
// Remove old records from the cache if they used different key.
String execPath = output.getExecPathString();
if (!key.equals(execPath)) {
actionCache.remove(execPath);
}
if (!metadataHandler.artifactOmitted(output)) {
// Output files *must* exist and be accessible after successful action execution.
Metadata metadata = metadataHandler.getMetadata(output);
Preconditions.checkState(metadata != null);
entry.addFile(output.getExecPath(), metadata);
}
}
for (Artifact input : action.getInputs()) {
entry.addFile(input.getExecPath(), metadataHandler.getMetadataMaybe(input));
}
entry.getFileDigest();
actionCache.put(key, entry);
}
use of com.google.devtools.build.lib.actions.cache.Metadata in project bazel by bazelbuild.
the class TreeArtifactMetadataTest method doTestTreeArtifacts.
private TreeArtifactValue doTestTreeArtifacts(Artifact tree, Iterable<PathFragment> children) throws Exception {
TreeArtifactValue value = evaluateTreeArtifact(tree, children);
assertThat(value.getChildPaths()).containsExactlyElementsIn(ImmutableSet.copyOf(children));
assertThat(value.getChildren()).containsExactlyElementsIn(asTreeFileArtifacts(tree, children));
// Assertions about digest. As of this writing this logic is essentially the same
// as that in TreeArtifact, but it's good practice to unit test anyway to guard against
// breaking changes.
Map<String, Metadata> digestBuilder = new HashMap<>();
for (PathFragment child : children) {
Metadata subdigest = new Metadata(tree.getPath().getRelative(child).getMD5Digest());
digestBuilder.put(child.getPathString(), subdigest);
}
assertThat(DigestUtils.fromMetadata(digestBuilder).getDigestBytesUnsafe()).isEqualTo(value.getDigest());
return value;
}
Aggregations