use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class CxxBinaryIntegrationTest method testInferCaptureAllCxxBinaryWithDiamondDepsEmitsAllBuildRulesInvolvedWhenCacheHit.
@Test
public void testInferCaptureAllCxxBinaryWithDiamondDepsEmitsAllBuildRulesInvolvedWhenCacheHit() throws IOException {
assumeTrue(Platform.detect() != Platform.WINDOWS);
ProjectWorkspace workspace = InferHelper.setupCxxInferWorkspace(this, tmp, Optional.empty());
workspace.enableDirCache();
workspace.setupCxxSandboxing(sandboxSources);
ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath());
BuildTarget inputBuildTarget = BuildTargetFactory.newInstance("//foo:binary_with_diamond_deps").withFlavors(CxxInferEnhancer.InferFlavors.INFER_CAPTURE_ALL.get());
String buildTargetName = inputBuildTarget.getFullyQualifiedName();
/*
* Build the given target and check that it succeeds.
*/
workspace.runBuckCommand("build", buildTargetName).assertSuccess();
/*
* Check that building after clean will use the cache
*/
workspace.runBuckCommand("clean").assertSuccess();
workspace.runBuckCommand("build", buildTargetName).assertSuccess();
BuckBuildLog buildLog = workspace.getBuildLog();
ImmutableSet<BuildTarget> allInvolvedTargets = buildLog.getAllTargets();
for (BuildTarget bt : allInvolvedTargets) {
buildLog.assertTargetWasFetchedFromCache(bt.toString());
}
assertTrue(Files.exists(workspace.getPath(BuildTargets.getGenPath(filesystem, inputBuildTarget, "infer-%s/infer-deps.txt"))));
String loggedDeps = workspace.getFileContents(BuildTargets.getGenPath(filesystem, inputBuildTarget, "infer-%s/infer-deps.txt"));
String sanitizedSimpleCpp = sanitize("simple.cpp.o");
String sanitizedDepOne = sanitize("dep_one.c.o");
String sanitizedDepTwo = sanitize("dep_two.c.o");
String sanitizedSrcWithDeps = sanitize("src_with_deps.c.o");
BuildTarget simpleCppTarget = BuildTargetFactory.newInstance("//foo:simple_lib#default,infer-capture-" + sanitizedSimpleCpp);
BuildTarget depOneTarget = BuildTargetFactory.newInstance("//foo:diamond_dep_one#default,infer-capture-" + sanitizedDepOne);
BuildTarget depTwoTarget = BuildTargetFactory.newInstance("//foo:diamond_dep_two#default,infer-capture-" + sanitizedDepTwo);
BuildTarget srcWithDepsTarget = BuildTargetFactory.newInstance("//foo:binary_with_diamond_deps#default,infer-capture-" + sanitizedSrcWithDeps);
Path basePath = filesystem.getRootPath().toRealPath();
String expectedOutput = Joiner.on('\n').join(ImmutableList.of(InferLogLine.fromBuildTarget(srcWithDepsTarget, basePath.resolve(BuildTargets.getGenPath(filesystem, srcWithDepsTarget, "infer-out-%s"))).toString(), InferLogLine.fromBuildTarget(depOneTarget, basePath.resolve(BuildTargets.getGenPath(filesystem, depOneTarget, "infer-out-%s"))).toString(), InferLogLine.fromBuildTarget(depTwoTarget, basePath.resolve(BuildTargets.getGenPath(filesystem, depTwoTarget, "infer-out-%s"))).toString(), InferLogLine.fromBuildTarget(simpleCppTarget, basePath.resolve(BuildTargets.getGenPath(filesystem, simpleCppTarget, "infer-out-%s"))).toString()));
assertEquals(expectedOutput + "\n", loggedDeps);
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class CxxBinaryIntegrationTest method testInferCxxBinaryWithDiamondDepsEmitsAllTransitiveCaptureRulesOnce.
@Test
public void testInferCxxBinaryWithDiamondDepsEmitsAllTransitiveCaptureRulesOnce() throws IOException {
assumeTrue(Platform.detect() != Platform.WINDOWS);
ProjectWorkspace workspace = InferHelper.setupCxxInferWorkspace(this, tmp, Optional.empty());
workspace.setupCxxSandboxing(sandboxSources);
ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath());
BuildTarget inputBuildTarget = BuildTargetFactory.newInstance("//foo:binary_with_diamond_deps").withFlavors(CxxInferEnhancer.InferFlavors.INFER_CAPTURE_ALL.get());
// Build the given target and check that it succeeds.
workspace.runBuckCommand("build", inputBuildTarget.getFullyQualifiedName()).assertSuccess();
assertTrue(Files.exists(workspace.getPath(BuildTargets.getGenPath(filesystem, inputBuildTarget, "infer-%s/infer-deps.txt"))));
String loggedDeps = workspace.getFileContents(BuildTargets.getGenPath(filesystem, inputBuildTarget, "infer-%s/infer-deps.txt"));
String sanitizedSimpleCpp = sanitize("simple.cpp.o");
String sanitizedDepOne = sanitize("dep_one.c.o");
String sanitizedDepTwo = sanitize("dep_two.c.o");
String sanitizedSrcWithDeps = sanitize("src_with_deps.c.o");
BuildTarget simpleCppTarget = BuildTargetFactory.newInstance("//foo:simple_lib#default,infer-capture-" + sanitizedSimpleCpp);
BuildTarget depOneTarget = BuildTargetFactory.newInstance("//foo:diamond_dep_one#default,infer-capture-" + sanitizedDepOne);
BuildTarget depTwoTarget = BuildTargetFactory.newInstance("//foo:diamond_dep_two#default,infer-capture-" + sanitizedDepTwo);
BuildTarget srcWithDepsTarget = BuildTargetFactory.newInstance("//foo:binary_with_diamond_deps#default,infer-capture-" + sanitizedSrcWithDeps);
Path basePath = filesystem.getRootPath().toRealPath();
String expectedOutput = Joiner.on('\n').join(ImmutableList.of(srcWithDepsTarget.getFullyQualifiedName() + "\t" + "[default, infer-capture-" + sanitizedSrcWithDeps + "]\t" + basePath.resolve(BuildTargets.getGenPath(filesystem, srcWithDepsTarget, "infer-out-%s")), depOneTarget.getFullyQualifiedName() + "\t" + "[default, infer-capture-" + sanitizedDepOne + "]\t" + basePath.resolve(BuildTargets.getGenPath(filesystem, depOneTarget, "infer-out-%s")), depTwoTarget.getFullyQualifiedName() + "\t" + "[default, infer-capture-" + sanitizedDepTwo + "]\t" + basePath.resolve(BuildTargets.getGenPath(filesystem, depTwoTarget, "infer-out-%s")), simpleCppTarget.getFullyQualifiedName() + "\t" + "[default, infer-capture-" + sanitizedSimpleCpp + "]\t" + basePath.resolve(BuildTargets.getGenPath(filesystem, simpleCppTarget, "infer-out-%s"))));
assertEquals(expectedOutput + "\n", loggedDeps);
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class CxxBinaryIntegrationTest method testInferCxxBinarySkipsBlacklistedFiles.
@Test
public void testInferCxxBinarySkipsBlacklistedFiles() throws IOException {
assumeTrue(Platform.detect() != Platform.WINDOWS);
ProjectWorkspace workspace = InferHelper.setupCxxInferWorkspace(this, tmp, Optional.of(".*one\\.c"));
workspace.setupCxxSandboxing(sandboxSources);
ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath());
BuildTarget inputBuildTarget = BuildTargetFactory.newInstance("//foo:binary_with_chain_deps");
String inputBuildTargetName = inputBuildTarget.withFlavors(CxxInferEnhancer.InferFlavors.INFER.get()).getFullyQualifiedName();
// Build the given target and check that it succeeds.
workspace.runBuckCommand("build", inputBuildTargetName).assertSuccess();
// Check that the cfg associated with chain_dep_one.c does not exist
assertFalse("Cfg file for chain_dep_one.c should not exist", Files.exists(workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance("//foo:chain_dep_one#default,infer-capture-" + sanitize("chain_dep_one.c.o")), "infer-out-%s").resolve("captured/chain_dep_one.c_captured/chain_dep_one.c.cfg"))));
// Check that the remaining files still have their cfgs
assertTrue("Expected cfg for chain_dep_two.c not found", Files.exists(workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance("//foo:chain_dep_two#default,infer-capture-" + sanitize("chain_dep_two.c.o")), "infer-out-%s").resolve("captured/chain_dep_two.c_captured/chain_dep_two.c.cfg"))));
assertTrue("Expected cfg for top_chain.c not found", Files.exists(workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance("//foo:binary_with_chain_deps#infer-analyze"), "infer-analysis-%s").resolve("captured/top_chain.c_captured/top_chain.c.cfg"))));
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class CxxBinaryIntegrationTest method testInferCxxBinaryWithDepsEmitsAllTheDependenciesResultsDirs.
@Test
public void testInferCxxBinaryWithDepsEmitsAllTheDependenciesResultsDirs() throws IOException {
assumeTrue(Platform.detect() != Platform.WINDOWS);
ProjectWorkspace workspace = InferHelper.setupCxxInferWorkspace(this, tmp, Optional.empty());
workspace.setupCxxSandboxing(sandboxSources);
ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath());
BuildTarget inputBuildTarget = BuildTargetFactory.newInstance("//foo:binary_with_chain_deps").withFlavors(CxxInferEnhancer.InferFlavors.INFER.get());
// Build the given target and check that it succeeds.
workspace.runBuckCommand("build", inputBuildTarget.getFullyQualifiedName()).assertSuccess();
assertTrue(Files.exists(workspace.getPath(BuildTargets.getGenPath(filesystem, inputBuildTarget, "infer-%s/infer-deps.txt"))));
String loggedDeps = workspace.getFileContents(BuildTargets.getGenPath(filesystem, inputBuildTarget, "infer-%s/infer-deps.txt"));
String sanitizedChainDepOne = sanitize("chain_dep_one.c.o");
String sanitizedTopChain = sanitize("top_chain.c.o");
String sanitizedChainDepTwo = sanitize("chain_dep_two.c.o");
BuildTarget analyzeTopChainTarget = BuildTargetFactory.newInstance("//foo:binary_with_chain_deps#infer-analyze");
BuildTarget captureTopChainTarget = BuildTargetFactory.newInstance("//foo:binary_with_chain_deps#default,infer-capture-" + sanitizedTopChain);
BuildTarget analyzeChainDepOneTarget = BuildTargetFactory.newInstance("//foo:chain_dep_one#default,infer-analyze");
BuildTarget captureChainDepOneTarget = BuildTargetFactory.newInstance("//foo:chain_dep_one#default,infer-capture-" + sanitizedChainDepOne);
BuildTarget analyzeChainDepTwoTarget = BuildTargetFactory.newInstance("//foo:chain_dep_two#default,infer-analyze");
BuildTarget captureChainDepTwoTarget = BuildTargetFactory.newInstance("//foo:chain_dep_two#default,infer-capture-" + sanitizedChainDepTwo);
Path basePath = filesystem.getRootPath().toRealPath();
String expectedOutput = Joiner.on('\n').join(ImmutableList.of(analyzeTopChainTarget.getFullyQualifiedName() + "\t" + "[infer-analyze]\t" + basePath.resolve(BuildTargets.getGenPath(filesystem, analyzeTopChainTarget, "infer-analysis-%s")), captureTopChainTarget.getFullyQualifiedName() + "\t" + "[default, infer-capture-" + sanitizedTopChain + "]\t" + basePath.resolve(BuildTargets.getGenPath(filesystem, captureTopChainTarget, "infer-out-%s")), analyzeChainDepOneTarget.getFullyQualifiedName() + "\t" + "[default, infer-analyze]\t" + basePath.resolve(BuildTargets.getGenPath(filesystem, analyzeChainDepOneTarget, "infer-analysis-%s")), captureChainDepOneTarget.getFullyQualifiedName() + "\t" + "[default, infer-capture-" + sanitizedChainDepOne + "]\t" + basePath.resolve(BuildTargets.getGenPath(filesystem, captureChainDepOneTarget, "infer-out-%s")), analyzeChainDepTwoTarget.getFullyQualifiedName() + "\t" + "[default, infer-analyze]\t" + basePath.resolve(BuildTargets.getGenPath(filesystem, analyzeChainDepTwoTarget, "infer-analysis-%s")), captureChainDepTwoTarget.getFullyQualifiedName() + "\t" + "[default, infer-capture-" + sanitizedChainDepTwo + "]\t" + basePath.resolve(BuildTargets.getGenPath(filesystem, captureChainDepTwoTarget, "infer-out-%s"))));
assertEquals(expectedOutput + "\n", loggedDeps);
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class CxxBinaryIntegrationTest method resolveHeadersBehindSymlinkTreesInError.
@Test
public void resolveHeadersBehindSymlinkTreesInError() throws IOException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "resolved", tmp);
workspace.setUp();
workspace.setupCxxSandboxing(sandboxSources);
ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath());
workspace.writeContentsToPath("#invalid_pragma", "lib2.h");
BuildTarget target = BuildTargetFactory.newInstance("//:bin");
ProjectWorkspace.ProcessResult result = workspace.runBuckCommand("build", target.toString());
result.assertFailure();
// Verify that the preprocessed source contains no references to the symlink tree used to
// setup the headers.
String error = result.getStderr();
assertThat(error, Matchers.not(Matchers.containsString(filesystem.getBuckPaths().getScratchDir().toString())));
assertThat(error, Matchers.not(Matchers.containsString(filesystem.getBuckPaths().getGenDir().toString())));
assertThat(error, Matchers.containsString("In file included from lib1.h:1"));
assertThat(error, Matchers.containsString("from bin.h:1"));
assertThat(error, Matchers.containsString("from bin.cpp:1:"));
assertThat(error, Matchers.containsString("lib2.h:1:2: error: invalid preprocessing"));
}
Aggregations