Search in sources :

Example 1 with Metadata

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);
}
Also used : ActionCache(com.google.devtools.build.lib.actions.cache.ActionCache) Entry(com.google.devtools.build.lib.actions.cache.ActionCache.Entry) Entry(com.google.devtools.build.lib.actions.cache.ActionCache.Entry) Metadata(com.google.devtools.build.lib.actions.cache.Metadata)

Example 2 with Metadata

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;
}
Also used : HashMap(java.util.HashMap) Metadata(com.google.devtools.build.lib.actions.cache.Metadata) ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Aggregations

Metadata (com.google.devtools.build.lib.actions.cache.Metadata)2 ActionAnalysisMetadata (com.google.devtools.build.lib.actions.ActionAnalysisMetadata)1 ActionCache (com.google.devtools.build.lib.actions.cache.ActionCache)1 Entry (com.google.devtools.build.lib.actions.cache.ActionCache.Entry)1 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)1 HashMap (java.util.HashMap)1