Search in sources :

Example 11 with Sha1HashCode

use of com.facebook.buck.util.sha1.Sha1HashCode in project buck by facebook.

the class Sha1Command method run.

@Override
public int run() throws EdenError, IOException, TException {
    Optional<EdenClient> client = EdenClient.newInstance();
    if (!client.isPresent()) {
        System.err.println("Could not connect to Eden");
        return 1;
    }
    Path mountPoint = Paths.get(this.mountPoint);
    EdenMount mount = client.get().getMountFor(mountPoint);
    for (String path : paths) {
        Path entry = mountPoint.relativize(Paths.get(path));
        Sha1HashCode sha1 = mount.getSha1(entry);
        System.out.printf("%s %s\n", entry, sha1);
    }
    return 0;
}
Also used : Path(java.nio.file.Path) EdenClient(com.facebook.buck.eden.EdenClient) EdenMount(com.facebook.buck.eden.EdenMount) Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode)

Example 12 with Sha1HashCode

use of com.facebook.buck.util.sha1.Sha1HashCode in project buck by facebook.

the class FakeProjectFilesystem method computeSha1.

/**
   * Does not support symlinks.
   */
@Override
public Sha1HashCode computeSha1(Path pathRelativeToProjectRootOrJustAbsolute) throws IOException {
    if (!exists(pathRelativeToProjectRootOrJustAbsolute)) {
        throw new NoSuchFileException(pathRelativeToProjectRootOrJustAbsolute.toString());
    }
    // Because this class is a fake, the file contents may not be available as a stream, so we load
    // all of the contents into memory as a byte[] and then hash them.
    byte[] fileContents = getFileBytes(pathRelativeToProjectRootOrJustAbsolute);
    HashCode hashCode = Hashing.sha1().newHasher().putBytes(fileContents).hash();
    return Sha1HashCode.fromHashCode(hashCode);
}
Also used : Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) HashCode(com.google.common.hash.HashCode) NoSuchFileException(java.nio.file.NoSuchFileException)

Example 13 with Sha1HashCode

use of com.facebook.buck.util.sha1.Sha1HashCode in project buck by facebook.

the class CxxPrecompiledHeaderRuleTest method deterministicHashesForSharedPCHs.

@Test
public void deterministicHashesForSharedPCHs() throws Exception {
    assumeTrue(platformOkForPCHTests());
    Sha1HashCode pchHashA = null;
    workspace.runBuckBuild("//determinism/a:main").assertSuccess();
    BuckBuildLog buildLogA = workspace.getBuildLog();
    for (BuildTarget target : buildLogA.getAllTargets()) {
        if (target.toString().startsWith("//determinism/lib:pch#default,pch-cxx-")) {
            pchHashA = buildLogA.getLogEntry(target).getRuleKey();
            System.err.println("A: " + pchHashA);
        }
    }
    assertNotNull(pchHashA);
    Sha1HashCode pchHashB = null;
    workspace.runBuckBuild("//determinism/b:main").assertSuccess();
    BuckBuildLog buildLogB = workspace.getBuildLog();
    for (BuildTarget target : buildLogB.getAllTargets()) {
        if (target.toString().startsWith("//determinism/lib:pch#default,pch-cxx-")) {
            pchHashB = buildLogB.getLogEntry(target).getRuleKey();
            System.err.println("B: " + pchHashB);
        }
    }
    assertNotNull(pchHashB);
    assertEquals(pchHashA, pchHashB);
    Sha1HashCode pchHashC = null;
    workspace.runBuckBuild("//determinism/c:main").assertSuccess();
    BuckBuildLog buildLogC = workspace.getBuildLog();
    for (BuildTarget target : buildLogC.getAllTargets()) {
        if (target.toString().startsWith("//determinism/lib:pch#default,pch-cxx-")) {
            pchHashC = buildLogC.getLogEntry(target).getRuleKey();
            System.err.println("C: " + pchHashC);
        }
    }
    assertNotNull(pchHashC);
    assertNotEquals(pchHashA, pchHashC);
}
Also used : Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) BuckBuildLog(com.facebook.buck.testutil.integration.BuckBuildLog) BuildTarget(com.facebook.buck.model.BuildTarget) Test(org.junit.Test)

Example 14 with Sha1HashCode

use of com.facebook.buck.util.sha1.Sha1HashCode in project buck by facebook.

the class StubJarTest method ordersChangesResultInADifferentOutputJar.

@Test
public void ordersChangesResultInADifferentOutputJar() throws IOException {
    JarPaths paths = createFullAndStubJars(EMPTY_CLASSPATH, "A.java", Joiner.on("\n").join(ImmutableList.of("package com.example.buck;", "public class A {", "  protected final static int count = 42;", "  public String getGreeting() { return \"hello\"; }", "  Class<?> clazz;", "  public int other;", "}")));
    Sha1HashCode originalHash = filesystem.computeSha1(paths.stubJar);
    paths = createFullAndStubJars(EMPTY_CLASSPATH, "A.java", Joiner.on("\n").join(ImmutableList.of("package com.example.buck;", "public class A {", "  Class<?> clazz;", "  public String getGreeting() { return \"hello\"; }", "  protected final static int count = 42;", "  public int other;", "}")));
    Sha1HashCode secondHash = filesystem.computeSha1(paths.stubJar);
    assertNotEquals(originalHash, secondHash);
}
Also used : Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) Test(org.junit.Test)

Example 15 with Sha1HashCode

use of com.facebook.buck.util.sha1.Sha1HashCode in project buck by facebook.

the class SmartDexingStep method generateDxCommands.

/**
   * Once the {@code .class} files have been split into separate zip files, each must be converted
   * to a {@code .dex} file.
   */
private ImmutableList<Step> generateDxCommands(ProjectFilesystem filesystem, Multimap<Path, Path> outputToInputs) {
    ImmutableList.Builder<DxPseudoRule> pseudoRules = ImmutableList.builder();
    ImmutableMap<Path, Sha1HashCode> dexInputHashes = dexInputHashesProvider.getDexInputHashes();
    for (Path outputFile : outputToInputs.keySet()) {
        pseudoRules.add(new DxPseudoRule(filesystem, dexInputHashes, ImmutableSet.copyOf(outputToInputs.get(outputFile)), outputFile, successDir.resolve(outputFile.getFileName()), dxOptions, xzCompressionLevel, dxMaxHeapSize));
    }
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    for (DxPseudoRule pseudoRule : pseudoRules.build()) {
        if (!pseudoRule.checkIsCached()) {
            steps.addAll(pseudoRule.buildInternal());
        }
    }
    return steps.build();
}
Also used : Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) RmStep(com.facebook.buck.step.fs.RmStep) Step(com.facebook.buck.step.Step) RepackZipEntriesStep(com.facebook.buck.zip.RepackZipEntriesStep) CompositeStep(com.facebook.buck.step.CompositeStep) XzStep(com.facebook.buck.step.fs.XzStep) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep)

Aggregations

Sha1HashCode (com.facebook.buck.util.sha1.Sha1HashCode)17 Path (java.nio.file.Path)10 Test (org.junit.Test)6 ImmutableList (com.google.common.collect.ImmutableList)4 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)3 SourcePath (com.facebook.buck.rules.SourcePath)3 AbstractExecutionStep (com.facebook.buck.step.AbstractExecutionStep)3 ExecutionContext (com.facebook.buck.step.ExecutionContext)3 Step (com.facebook.buck.step.Step)3 StepExecutionResult (com.facebook.buck.step.StepExecutionResult)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 HashCode (com.google.common.hash.HashCode)3 IOException (java.io.IOException)3 BuildTarget (com.facebook.buck.model.BuildTarget)2 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)2 MkdirStep (com.facebook.buck.step.fs.MkdirStep)2 BuckBuildLog (com.facebook.buck.testutil.integration.BuckBuildLog)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 AbstractMap (java.util.AbstractMap)2 List (java.util.List)2