Search in sources :

Example 1 with DxPseudoRule

use of com.facebook.buck.android.SmartDexingStep.DxPseudoRule in project buck by facebook.

the class SmartDexingStepTest method testDxPseudoRuleCaching.

/**
   * Tests whether pseudo rule cache detection is working properly.
   */
@Test
public void testDxPseudoRuleCaching() throws IOException {
    File testIn = new File(tmpDir.getRoot(), "testIn");
    try (ZipOutputStream zipOut = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(testIn)))) {
        zipOut.putNextEntry(new ZipEntry("foobar"));
        zipOut.write(new byte[] { 0 });
    }
    File outputFile = tmpDir.newFile("out.dex");
    Path outputHashFile = new File(tmpDir.getRoot(), "out.dex.hash").toPath();
    Files.write("dummy", outputHashFile.toFile(), Charsets.UTF_8);
    ProjectFilesystem filesystem = new ProjectFilesystem(tmpDir.getRoot().toPath());
    Sha1HashCode actualHashCode = Sha1HashCode.of(Strings.repeat("a", 40));
    DxPseudoRule rule = new DxPseudoRule(filesystem, ImmutableMap.of(testIn.toPath(), actualHashCode), ImmutableSet.of(testIn.toPath()), outputFile.toPath(), outputHashFile, EnumSet.of(DxStep.Option.NO_OPTIMIZE), Optional.empty(), Optional.empty());
    assertFalse("'dummy' is not a matching input hash", rule.checkIsCached());
    // Write the real hash into the output hash file and ensure that checkIsCached now
    // yields true.
    String actualHash = rule.hashInputs();
    assertFalse(actualHash.isEmpty());
    Files.write(actualHash, outputHashFile.toFile(), Charsets.UTF_8);
    assertTrue("Matching input hash should be considered cached", rule.checkIsCached());
}
Also used : Path(java.nio.file.Path) DxPseudoRule(com.facebook.buck.android.SmartDexingStep.DxPseudoRule) ZipOutputStream(java.util.zip.ZipOutputStream) Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) Test(org.junit.Test)

Aggregations

DxPseudoRule (com.facebook.buck.android.SmartDexingStep.DxPseudoRule)1 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)1 Sha1HashCode (com.facebook.buck.util.sha1.Sha1HashCode)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 Path (java.nio.file.Path)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 Test (org.junit.Test)1