use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.
the class DefaultJavaLibraryIntegrationTest method testFileChangeThatDoesNotModifyAbiOfAUsedClassAvoidsRebuild.
@Test
public void testFileChangeThatDoesNotModifyAbiOfAUsedClassAvoidsRebuild() throws IOException {
workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "dep_file_rule_key", tmp);
workspace.setUp();
// Run `buck build` to create the dep file
BuildTarget bizTarget = BuildTargetFactory.newInstance("//:biz");
// Warm the used classes file
ProcessResult buildResult = workspace.runBuckCommand("build", bizTarget.getFullyQualifiedName());
buildResult.assertSuccess("Successful build should exit with 0.");
workspace.getBuildLog().assertTargetBuiltLocally("//:biz");
workspace.getBuildLog().assertTargetBuiltLocally("//:util");
// Edit MoreUtil.java in a way that changes its ABI
workspace.replaceFileContents("MoreUtil.java", "printHelloWorld", "printHelloWorld2");
// Run `buck build` again.
ProcessResult buildResult2 = workspace.runBuckCommand("build", "//:biz");
buildResult2.assertSuccess("Successful build should exit with 0.");
// If all goes well, we'll fetch //:biz's dep file from the cache and realize we don't need
// to rebuild it because //:biz didn't use MoreUtil.
workspace.getBuildLog().assertTargetBuiltLocally("//:util");
workspace.getBuildLog().assertTargetHadMatchingDepfileRuleKey("//:biz");
}
use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.
the class DefaultJavaLibraryIntegrationTest method testBuildJavaLibraryWithoutSrcsAndVerifyAbi.
@Test
public void testBuildJavaLibraryWithoutSrcsAndVerifyAbi() throws IOException {
workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "abi", tmp);
workspace.setUp();
workspace.enableDirCache();
// Run `buck build`.
BuildTarget target = BuildTargetFactory.newInstance("//:no_srcs");
ProcessResult buildResult = workspace.runBuckCommand("build", target.getFullyQualifiedName());
buildResult.assertSuccess("Successful build should exit with 0.");
Path outputPath = BuildTargets.getGenPath(filesystem, target, "lib__%s__output/" + target.getShortName() + ".jar");
Path outputFile = workspace.getPath(outputPath);
assertTrue(Files.exists(outputFile));
// TODO(bolinfest): When we produce byte-for-byte identical JAR files across builds, do:
//
// HashCode hashOfOriginalJar = Files.hash(outputFile, Hashing.sha1());
//
// And then compare that to the output when //:no_srcs is built again with --no-cache.
long sizeOfOriginalJar = Files.size(outputFile);
// This verifies that the ABI key was written correctly.
workspace.verify();
// Verify the build cache.
Path buildCache = workspace.getPath(filesystem.getBuckPaths().getCacheDir());
assertTrue(Files.isDirectory(buildCache));
ArtifactCache dirCache = TestArtifactCaches.createDirCacheForTest(workspace.getDestPath(), buildCache);
int totalArtifactsCount = DirArtifactCacheTestUtil.getAllFilesInCache(dirCache).size();
assertEquals("There should be two entries (a zip and metadata) in the build cache.", 2, totalArtifactsCount);
// Run `buck clean`.
ProcessResult cleanResult = workspace.runBuckCommand("clean");
cleanResult.assertSuccess("Successful clean should exit with 0.");
totalArtifactsCount = getAllFilesInPath(buildCache).size();
assertEquals("The build cache should still exist.", 2, totalArtifactsCount);
// Corrupt the build cache!
File artifactZip = FluentIterable.from(ImmutableList.copyOf(DirArtifactCacheTestUtil.getAllFilesInCache(dirCache))).toSortedList(Ordering.natural()).get(0).toFile();
FileSystem zipFs = FileSystems.newFileSystem(artifactZip.toPath(), /* loader */
null);
Path outputInZip = zipFs.getPath("/" + outputPath.toString());
Files.write(outputInZip, "Hello world!".getBytes(), WRITE);
zipFs.close();
// Run `buck build` again.
ProcessResult buildResult2 = workspace.runBuckCommand("build", target.getFullyQualifiedName());
buildResult2.assertSuccess("Successful build should exit with 0.");
assertTrue(Files.isRegularFile(outputFile));
assertEquals("The content of the output file will be 'Hello World!' if it is read from the build cache.", "Hello world!", new String(Files.readAllBytes(outputFile), UTF_8));
// Run `buck clean` followed by `buck build` yet again, but this time, specify `--no-cache`.
ProcessResult cleanResult2 = workspace.runBuckCommand("clean");
cleanResult2.assertSuccess("Successful clean should exit with 0.");
ProcessResult buildResult3 = workspace.runBuckCommand("build", "--no-cache", target.getFullyQualifiedName());
buildResult3.assertSuccess();
assertNotEquals("The contents of the file should no longer be pulled from the corrupted build cache.", "Hello world!", new String(Files.readAllBytes(outputFile), UTF_8));
assertEquals("We cannot do a byte-for-byte comparision with the original JAR because timestamps might " + "have changed, but we verify that they are the same size, as a proxy.", sizeOfOriginalJar, Files.size(outputFile));
}
use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.
the class DefaultJavaLibraryIntegrationTest method ensureThatSourcePathIsSetSensibly.
@Test
public void ensureThatSourcePathIsSetSensibly() throws IOException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "sourcepath", tmp);
workspace.setUp();
ProcessResult result = workspace.runBuckBuild("//:b");
// This should fail, since we expect the symbol for A not to be found.
result.assertFailure();
String stderr = result.getStderr();
assertTrue(stderr, stderr.contains("cannot find symbol"));
}
use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.
the class DefaultJavaLibraryIntegrationTest method testFileChangeThatDoesNotModifyAbiOfAUsedClassAvoidsRebuildEvenWithBuckClean.
@Test
public void testFileChangeThatDoesNotModifyAbiOfAUsedClassAvoidsRebuildEvenWithBuckClean() throws IOException {
workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "dep_file_rule_key", tmp);
workspace.setUp();
workspace.enableDirCache();
// Run `buck build` to warm the cache.
BuildTarget bizTarget = BuildTargetFactory.newInstance("//:biz");
// Warm the used classes file
ProcessResult buildResult = workspace.runBuckCommand("build", bizTarget.getFullyQualifiedName());
buildResult.assertSuccess("Successful build should exit with 0.");
workspace.getBuildLog().assertTargetBuiltLocally("//:biz");
workspace.getBuildLog().assertTargetBuiltLocally("//:util");
// Run `buck clean` so that we're forced to fetch the dep file from the cache.
ProcessResult cleanResult = workspace.runBuckCommand("clean");
cleanResult.assertSuccess("Successful clean should exit with 0.");
// Edit MoreUtil.java in a way that changes its ABI
workspace.replaceFileContents("MoreUtil.java", "printHelloWorld", "printHelloWorld2");
// Run `buck build` again.
ProcessResult buildResult2 = workspace.runBuckCommand("build", "//:biz");
buildResult2.assertSuccess("Successful build should exit with 0.");
// If all goes well, we'll fetch //:biz's dep file from the cache and realize we don't need
// to rebuild it because //:biz didn't use MoreUtil.
workspace.getBuildLog().assertTargetBuiltLocally("//:util");
workspace.getBuildLog().assertTargetWasFetchedFromCacheByManifestMatch("//:biz");
}
use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.
the class DefaultJavaLibraryIntegrationTest method testSpoolClassFilesDirectlyToJar.
@Test
public void testSpoolClassFilesDirectlyToJar() throws IOException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "spool_class_files_directly_to_jar", tmp);
workspace.setUp();
BuildTarget target = BuildTargetFactory.newInstance("//:a");
ProcessResult result = workspace.runBuckBuild(target.getFullyQualifiedName());
result.assertSuccess();
Path classesDir = workspace.getPath(BuildTargets.getScratchPath(filesystem, target, "lib__%s__classes"));
assertThat(Files.exists(classesDir), is(Boolean.TRUE));
assertThat("There should be no class files in disk", ImmutableList.copyOf(classesDir.toFile().listFiles()), hasSize(0));
Path jarPath = workspace.getPath(BuildTargets.getGenPath(filesystem, target, "lib__%s__output/a.jar"));
assertTrue(Files.exists(jarPath));
ZipInputStream zip = new ZipInputStream(new FileInputStream(jarPath.toFile()));
assertThat(zip.getNextEntry().getName(), is("A.class"));
assertThat(zip.getNextEntry().getName(), is("B.class"));
zip.close();
}
Aggregations