Search in sources :

Example 1 with Fingerprint

use of com.google.devtools.build.lib.util.Fingerprint in project bazel by bazelbuild.

the class Environment method computeTransitiveContentHashCode.

private static String computeTransitiveContentHashCode(@Nullable String baseHashCode, Map<String, Extension> importedExtensions) {
    // Calculate a new hash from the hash of the loaded Extension-s.
    Fingerprint fingerprint = new Fingerprint();
    if (baseHashCode != null) {
        fingerprint.addString(Preconditions.checkNotNull(baseHashCode));
    }
    TreeSet<String> importStrings = new TreeSet<>(importedExtensions.keySet());
    for (String importString : importStrings) {
        fingerprint.addString(importedExtensions.get(importString).getTransitiveContentHashCode());
    }
    return fingerprint.hexDigestAndReset();
}
Also used : Fingerprint(com.google.devtools.build.lib.util.Fingerprint) TreeSet(java.util.TreeSet)

Example 2 with Fingerprint

use of com.google.devtools.build.lib.util.Fingerprint in project bazel by bazelbuild.

the class CrosstoolConfigurationLoader method getCrosstoolProtofromBuildFile.

private static CrosstoolProto getCrosstoolProtofromBuildFile(ConfigurationEnvironment env, Label crosstoolTop) throws InterruptedException {
    Target target;
    try {
        target = env.getTarget(crosstoolTop);
    } catch (NoSuchThingException e) {
        // Should have beeen evaluated by RedirectChaser
        throw new IllegalStateException(e);
    }
    if (!(target instanceof Rule)) {
        return null;
    }
    Rule rule = (Rule) target;
    if (!(rule.getRuleClass().equals("cc_toolchain_suite")) || !rule.isAttributeValueExplicitlySpecified("proto")) {
        return null;
    }
    final String contents = NonconfigurableAttributeMapper.of(rule).get("proto", Type.STRING);
    byte[] md5 = new Fingerprint().addBytes(contents.getBytes(UTF_8)).digestAndReset();
    return new CrosstoolProto(md5, "cc_toolchain_suite rule " + crosstoolTop.toString()) {

        @Override
        public String getContents() throws IOException {
            return contents;
        }
    };
}
Also used : Target(com.google.devtools.build.lib.packages.Target) NoSuchThingException(com.google.devtools.build.lib.packages.NoSuchThingException) Fingerprint(com.google.devtools.build.lib.util.Fingerprint) Rule(com.google.devtools.build.lib.packages.Rule)

Example 3 with Fingerprint

use of com.google.devtools.build.lib.util.Fingerprint in project bazel by bazelbuild.

the class CppCompileAction method computeKey.

@Override
public String computeKey() {
    Fingerprint f = new Fingerprint();
    f.addUUID(actionClassId);
    f.addStringMap(getEnvironment());
    f.addStringMap(executionInfo);
    // For the argv part of the cache key, ignore all compiler flags that explicitly denote module
    // file (.pcm) inputs. Depending on input discovery, some of the unused ones are removed from
    // the command line. However, these actually don't have an influence on the compile itself and
    // so ignoring them for the cache key calculation does not affect correctness. The compile
    // itself is fully determined by the input source files and module maps.
    // A better long-term solution would be to make the compiler to find them automatically and
    // never hand in the .pcm files explicitly on the command line in the first place.
    f.addStrings(cppCompileCommandLine.getArgv(getInternalOutputFile(), null));
    /*
     * getArgv() above captures all changes which affect the compilation
     * command and hence the contents of the object file.  But we need to
     * also make sure that we reexecute the action if any of the fields
     * that affect whether validateIncludes() will report an error or warning
     * have changed, otherwise we might miss some errors.
     */
    f.addPaths(context.getDeclaredIncludeDirs());
    f.addPaths(context.getDeclaredIncludeWarnDirs());
    for (Artifact declaredIncludeSrc : context.getDeclaredIncludeSrcs()) {
        f.addPath(declaredIncludeSrc.getExecPath());
    }
    // mark the boundary between input types
    f.addInt(0);
    for (Artifact input : getMandatoryInputs()) {
        f.addPath(input.getExecPath());
    }
    f.addInt(0);
    for (Artifact input : prunableInputs) {
        f.addPath(input.getExecPath());
    }
    return f.hexDigestAndReset();
}
Also used : Fingerprint(com.google.devtools.build.lib.util.Fingerprint) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 4 with Fingerprint

use of com.google.devtools.build.lib.util.Fingerprint in project bazel by bazelbuild.

the class DigestUtils method fromEnv.

/**
   * @param env A collection of (String, String) pairs.
   * @return an order-independent digest of the given set of pairs.
   */
public static Md5Digest fromEnv(Map<String, String> env) {
    byte[] result = new byte[Md5Digest.MD5_SIZE];
    Fingerprint fp = new Fingerprint();
    for (Map.Entry<String, String> entry : env.entrySet()) {
        fp.addString(entry.getKey());
        fp.addString(entry.getValue());
        xorWith(result, fp.digestAndReset());
    }
    return new Md5Digest(result);
}
Also used : Fingerprint(com.google.devtools.build.lib.util.Fingerprint) Map(java.util.Map)

Example 5 with Fingerprint

use of com.google.devtools.build.lib.util.Fingerprint in project bazel by bazelbuild.

the class DigestUtils method fromMetadata.

/**
   * @param mdMap A collection of (execPath, Metadata) pairs. Values may be null.
   * @return an <b>order-independent</b> digest from the given "set" of (path, metadata) pairs.
   */
public static Md5Digest fromMetadata(Map<String, Metadata> mdMap) {
    byte[] result = new byte[Md5Digest.MD5_SIZE];
    // Profiling showed that MD5 engine instantiation was a hotspot, so create one instance for
    // this computation to amortize its cost.
    Fingerprint fp = new Fingerprint();
    for (Map.Entry<String, Metadata> entry : mdMap.entrySet()) {
        xorWith(result, getDigest(fp, entry.getKey(), entry.getValue()));
    }
    return new Md5Digest(result);
}
Also used : Fingerprint(com.google.devtools.build.lib.util.Fingerprint) Map(java.util.Map)

Aggregations

Fingerprint (com.google.devtools.build.lib.util.Fingerprint)38 Artifact (com.google.devtools.build.lib.actions.Artifact)9 IOException (java.io.IOException)6 Map (java.util.Map)6 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)5 RepositoryFunctionException (com.google.devtools.build.lib.rules.repository.RepositoryFunction.RepositoryFunctionException)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Rule (com.google.devtools.build.lib.packages.Rule)2 InputStream (java.io.InputStream)2 TreeMap (java.util.TreeMap)2 Nullable (javax.annotation.Nullable)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)1 BlazeDirectories (com.google.devtools.build.lib.analysis.BlazeDirectories)1 RunUnder (com.google.devtools.build.lib.analysis.config.RunUnder)1 MavenServerRule (com.google.devtools.build.lib.bazel.rules.workspace.MavenServerRule)1 AspectDescriptor (com.google.devtools.build.lib.packages.AspectDescriptor)1 NoSuchThingException (com.google.devtools.build.lib.packages.NoSuchThingException)1