Search in sources :

Example 91 with ProjectFilesystem

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);
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) BuckBuildLog(com.facebook.buck.testutil.integration.BuckBuildLog) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 92 with ProjectFilesystem

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);
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 93 with ProjectFilesystem

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"))));
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 94 with ProjectFilesystem

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);
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 95 with ProjectFilesystem

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"));
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Aggregations

ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)654 Test (org.junit.Test)542 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)401 Path (java.nio.file.Path)324 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)207 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)204 BuildTarget (com.facebook.buck.model.BuildTarget)203 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)126 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)121 TargetGraph (com.facebook.buck.rules.TargetGraph)119 PathSourcePath (com.facebook.buck.rules.PathSourcePath)96 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)92 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)90 SourcePath (com.facebook.buck.rules.SourcePath)79 ExecutionContext (com.facebook.buck.step.ExecutionContext)67 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)67 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)63 BuildRule (com.facebook.buck.rules.BuildRule)56 RuleKey (com.facebook.buck.rules.RuleKey)43 ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)42