Search in sources :

Example 26 with Fingerprint

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

the class FileSystemTest method testGetMD5Digest.

@Test
public void testGetMD5Digest() throws Exception {
    byte[] buffer = new byte[500000];
    for (int i = 0; i < buffer.length; ++i) {
        buffer[i] = 1;
    }
    FileSystemUtils.writeContent(xFile, buffer);
    Fingerprint fp = new Fingerprint();
    fp.addBytes(buffer);
    assertEquals(BaseEncoding.base16().lowerCase().encode(xFile.getMD5Digest()), fp.hexDigestAndReset());
}
Also used : Fingerprint(com.google.devtools.build.lib.util.Fingerprint) Fingerprint(com.google.devtools.build.lib.util.Fingerprint) Test(org.junit.Test)

Example 27 with Fingerprint

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

the class FileSystemTest method testGetMD5DigestForEmptyFile.

@Test
public void testGetMD5DigestForEmptyFile() throws Exception {
    Fingerprint fp = new Fingerprint();
    fp.addBytes(new byte[0]);
    assertEquals(BaseEncoding.base16().lowerCase().encode(xFile.getMD5Digest()), fp.hexDigestAndReset());
}
Also used : Fingerprint(com.google.devtools.build.lib.util.Fingerprint) Test(org.junit.Test)

Example 28 with Fingerprint

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

the class AndroidDeployInfoAction method computeKey.

@Override
protected String computeKey() {
    Fingerprint f = new Fingerprint().addString(GUID);
    try (InputStream in = byteString.newInput()) {
        byte[] buffer = new byte[512];
        int amountRead;
        while ((amountRead = in.read(buffer)) != -1) {
            f.addBytes(buffer, 0, amountRead);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return f.hexDigestAndReset();
}
Also used : Fingerprint(com.google.devtools.build.lib.util.Fingerprint) InputStream(java.io.InputStream) IOException(java.io.IOException) Fingerprint(com.google.devtools.build.lib.util.Fingerprint)

Example 29 with Fingerprint

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

the class ApkManifestAction method computeKey.

@Override
protected String computeKey() {
    // Use fake hashes for the purposes of the action's key, because the hashes are retrieved from
    // the MetadataHandler, which is available at only action-execution time. This should be ok
    // because if an input artifact changes (and hence its hash changes), the action should be rerun
    // anyway. This is more for the purpose of putting the structure of the output data into the
    // key.
    ApkManifestCreator manifestCreator = new ApkManifestCreator(new ArtifactDigester() {

        @Override
        public byte[] getDigest(Artifact artifact) {
            return Ints.toByteArray(artifact.getExecPathString().hashCode());
        }
    });
    ApkManifest manifest;
    try {
        manifest = manifestCreator.createManifest();
    } catch (IOException e) {
        // ArtifactDigester that uses the MetadataHandler.
        throw new IllegalStateException(e);
    }
    return new Fingerprint().addString(GUID).addBoolean(textOutput).addBytes(manifest.toByteArray()).hexDigestAndReset();
}
Also used : Fingerprint(com.google.devtools.build.lib.util.Fingerprint) ApkManifest(com.google.devtools.build.lib.rules.android.apkmanifest.ApkManifestOuterClass.ApkManifest) IOException(java.io.IOException) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 30 with Fingerprint

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

the class ExtraActionSpec method getOwnerDigest.

/**
   * Calculates a digest representing the rule context.  We use the digest instead of the
   * original value as the original value might lead to a filename that is too long.
   * By using a digest, tools can deterministically find all extra_action outputs for a given
   * target, without having to open every file in the package.
   */
private static String getOwnerDigest(RuleContext ruleContext) {
    Fingerprint f = new Fingerprint();
    f.addString(ruleContext.getLabel().toString());
    return f.hexDigestAndReset();
}
Also used : Fingerprint(com.google.devtools.build.lib.util.Fingerprint)

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