Search in sources :

Example 21 with BuckBuildLog

use of com.facebook.buck.testutil.integration.BuckBuildLog in project buck by facebook.

the class CxxBinaryIntegrationTest method testInferCxxBinaryWithDiamondDepsEmitsAllBuildRulesInvolvedWhenCacheHit.

@Test
public void testInferCxxBinaryWithDiamondDepsEmitsAllBuildRulesInvolvedWhenCacheHit() 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.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();
    // Only main target should be fetched from cache
    assertEquals(1, allInvolvedTargets.size());
    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"));
    BuildTarget analyzeMainTarget = BuildTargetFactory.newInstance("//foo:binary_with_diamond_deps#infer-analyze");
    BuildTarget analyzeDepOneTarget = BuildTargetFactory.newInstance("//foo:diamond_dep_one#default,infer-analyze");
    BuildTarget analyzeDepTwoTarget = BuildTargetFactory.newInstance("//foo:diamond_dep_two#default,infer-analyze");
    BuildTarget analyzeSimpleLibTarget = BuildTargetFactory.newInstance("//foo:simple_lib#default,infer-analyze");
    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(analyzeMainTarget, basePath.resolve(BuildTargets.getGenPath(filesystem, analyzeMainTarget, "infer-analysis-%s"))).toString(), InferLogLine.fromBuildTarget(srcWithDepsTarget, basePath.resolve(BuildTargets.getGenPath(filesystem, srcWithDepsTarget, "infer-out-%s"))).toString(), InferLogLine.fromBuildTarget(analyzeDepOneTarget, basePath.resolve(BuildTargets.getGenPath(filesystem, analyzeDepOneTarget, "infer-analysis-%s"))).toString(), InferLogLine.fromBuildTarget(depOneTarget, basePath.resolve(BuildTargets.getGenPath(filesystem, depOneTarget, "infer-out-%s"))).toString(), InferLogLine.fromBuildTarget(analyzeDepTwoTarget, basePath.resolve(BuildTargets.getGenPath(filesystem, analyzeDepTwoTarget, "infer-analysis-%s"))).toString(), InferLogLine.fromBuildTarget(depTwoTarget, basePath.resolve(BuildTargets.getGenPath(filesystem, depTwoTarget, "infer-out-%s"))).toString(), InferLogLine.fromBuildTarget(analyzeSimpleLibTarget, basePath.resolve(BuildTargets.getGenPath(filesystem, analyzeSimpleLibTarget, "infer-analysis-%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 22 with BuckBuildLog

use of com.facebook.buck.testutil.integration.BuckBuildLog in project buck by facebook.

the class CxxBinaryIntegrationTest method testInferCxxBinaryWithDiamondDepsHasRuntimeDepsOfAllCaptureRulesWhenCacheHits.

@Test
public void testInferCxxBinaryWithDiamondDepsHasRuntimeDepsOfAllCaptureRulesWhenCacheHits() 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");
    String inputBuildTargetName = inputBuildTarget.withFlavors(CxxInferEnhancer.InferFlavors.INFER_CAPTURE_ALL.get()).getFullyQualifiedName();
    /*
     * Build the given target and check that it succeeds.
     */
    workspace.runBuckCommand("build", inputBuildTargetName).assertSuccess();
    /*
     * Check that building after clean will use the cache
     */
    workspace.runBuckCommand("clean").assertSuccess();
    workspace.runBuckCommand("build", inputBuildTargetName).assertSuccess();
    BuckBuildLog buildLog = workspace.getBuildLog();
    for (BuildTarget buildTarget : buildLog.getAllTargets()) {
        buildLog.assertTargetWasFetchedFromCache(buildTarget.toString());
    }
    /*
    * Check that runtime deps have been fetched from cache as well
    */
    assertTrue("This file was expected to exist because it's declared as runtime dep", Files.exists(workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance("//foo:simple_lib#default,infer-capture-" + sanitize("simple.cpp.o")), "infer-out-%s").resolve("captured/simple.cpp_captured/simple.cpp.cfg"))));
    assertTrue("This file was expected to exist because it's declared as runtime dep", Files.exists(workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance("//foo:diamond_dep_one#default,infer-capture-" + sanitize("dep_one.c.o")), "infer-out-%s").resolve("captured/dep_one.c_captured/dep_one.c.cfg"))));
    assertTrue("This file was expected to exist because it's declared as runtime dep", Files.exists(workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance("//foo:diamond_dep_two#default,infer-capture-" + sanitize("dep_two.c.o")), "infer-out-%s").resolve("captured/dep_two.c_captured/dep_two.c.cfg"))));
    assertTrue("This file was expected to exist because it's declared as runtime dep", Files.exists(workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance("//foo:binary_with_diamond_deps#default,infer-capture-" + sanitize("src_with_deps.c.o")), "infer-out-%s").resolve("captured/src_with_deps.c_captured/src_with_deps.c.cfg"))));
}
Also used : 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 23 with BuckBuildLog

use of com.facebook.buck.testutil.integration.BuckBuildLog in project buck by facebook.

the class CxxBinaryIntegrationTest method testInferCxxBinaryWithoutDeps.

@Test
public void testInferCxxBinaryWithoutDeps() throws IOException, InterruptedException {
    assumeTrue(Platform.detect() != Platform.WINDOWS);
    ProjectWorkspace workspace = InferHelper.setupCxxInferWorkspace(this, tmp, Optional.empty());
    workspace.setupCxxSandboxing(sandboxSources);
    CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(workspace.asCell().getBuckConfig());
    CxxPlatform cxxPlatform = CxxPlatformUtils.build(cxxBuckConfig);
    BuildTarget inputBuildTarget = BuildTargetFactory.newInstance(workspace.getDestPath(), "//foo:simple");
    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 all the required build targets have been generated.
     */
    String sourceName = "simple.cpp";
    String sourceFull = "foo/" + sourceName;
    CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactoryHelper.of(workspace.getDestPath(), inputBuildTarget, cxxPlatform, cxxBuckConfig);
    // this is unflavored, but bounded to the InferCapture build rule
    BuildTarget captureBuildTarget = cxxSourceRuleFactory.createInferCaptureBuildTarget(sourceName);
    // this is unflavored, but necessary to run the compiler successfully
    BuildTarget headerSymlinkTreeTarget = CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(inputBuildTarget, HeaderVisibility.PRIVATE, cxxPlatform.getFlavor());
    BuildTarget sandboxTreeTarget = CxxDescriptionEnhancer.createSandboxSymlinkTreeTarget(inputBuildTarget, cxxPlatform.getFlavor());
    // this is flavored, and denotes the analysis step (generates a local report)
    BuildTarget inferAnalysisTarget = inputBuildTarget.withFlavors(CxxInferEnhancer.InferFlavors.INFER_ANALYZE.get());
    // this is flavored and corresponds to the top level target (the one give in input to buck)
    BuildTarget inferReportTarget = inputBuildTarget.withFlavors(CxxInferEnhancer.InferFlavors.INFER.get());
    BuildTarget aggregatedDepsTarget = cxxSourceRuleFactory.createAggregatedPreprocessDepsBuildTarget();
    ImmutableSortedSet.Builder<BuildTarget> targetsBuilder = ImmutableSortedSet.<BuildTarget>naturalOrder().add(aggregatedDepsTarget, headerSymlinkTreeTarget, captureBuildTarget, inferAnalysisTarget, inferReportTarget);
    if (sandboxSources) {
        targetsBuilder.add(sandboxTreeTarget);
    }
    BuckBuildLog buildLog = workspace.getBuildLog();
    assertThat(buildLog.getAllTargets(), containsInAnyOrder(targetsBuilder.build().toArray()));
    buildLog.assertTargetBuiltLocally(aggregatedDepsTarget.toString());
    buildLog.assertTargetBuiltLocally(headerSymlinkTreeTarget.toString());
    buildLog.assertTargetBuiltLocally(captureBuildTarget.toString());
    buildLog.assertTargetBuiltLocally(inferAnalysisTarget.toString());
    buildLog.assertTargetBuiltLocally(inferReportTarget.toString());
    /*
     * Check that running a build again results in no builds since nothing has changed.
     */
    // clear for new build
    workspace.resetBuildLogFile();
    workspace.runBuckCommand("build", inputBuildTargetName).assertSuccess();
    buildLog = workspace.getBuildLog();
    assertEquals(ImmutableSet.of(inferReportTarget), buildLog.getAllTargets());
    buildLog.assertTargetHadMatchingRuleKey(inferReportTarget.toString());
    /*
     * Check that changing the source file results in running the capture/analysis rules again.
     */
    workspace.resetBuildLogFile();
    workspace.replaceFileContents(sourceFull, "*s = 42;", "");
    workspace.runBuckCommand("build", inputBuildTargetName).assertSuccess();
    buildLog = workspace.getBuildLog();
    targetsBuilder = ImmutableSortedSet.<BuildTarget>naturalOrder().add(aggregatedDepsTarget, captureBuildTarget, inferAnalysisTarget, inferReportTarget);
    if (sandboxSources) {
        targetsBuilder.add(headerSymlinkTreeTarget, sandboxTreeTarget);
    }
    assertEquals(buildLog.getAllTargets(), targetsBuilder.build());
    buildLog.assertTargetBuiltLocally(captureBuildTarget.toString());
    buildLog.assertTargetBuiltLocally(inferAnalysisTarget.toString());
    if (sandboxSources) {
        buildLog.assertTargetHadMatchingRuleKey(headerSymlinkTreeTarget.toString());
        buildLog.assertTargetHadMatchingInputRuleKey(sandboxTreeTarget.toString());
        buildLog.assertTargetBuiltLocally(aggregatedDepsTarget.toString());
    } else {
        buildLog.assertTargetHadMatchingRuleKey(aggregatedDepsTarget.toString());
    }
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) BuckBuildLog(com.facebook.buck.testutil.integration.BuckBuildLog) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Test(org.junit.Test)

Example 24 with BuckBuildLog

use of com.facebook.buck.testutil.integration.BuckBuildLog in project buck by facebook.

the class CxxBinaryIntegrationTest method testInferCxxBinaryWithCachedDepsGetsAllItsTransitiveDeps.

@Test
public void testInferCxxBinaryWithCachedDepsGetsAllItsTransitiveDeps() 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_chain_deps").withFlavors(CxxInferEnhancer.InferFlavors.INFER.get());
    /*
     * Build the given target and check that it succeeds.
     */
    workspace.runBuckCommand("build", inputBuildTarget.getFullyQualifiedName()).assertSuccess();
    /*
     * Check that building after clean will use the cache
     */
    workspace.runBuckCommand("clean").assertSuccess();
    workspace.runBuckCommand("build", inputBuildTarget.getFullyQualifiedName()).assertSuccess();
    BuckBuildLog buildLog = workspace.getBuildLog();
    for (BuildTarget buildTarget : buildLog.getAllTargets()) {
        buildLog.assertTargetWasFetchedFromCache(buildTarget.toString());
    }
    /*
     * Check that if the file in the top target changes, then all the transitive deps will be
     * fetched from the cache (even those that are not direct dependencies).
     * Make sure there's the specs file of the dependency that has distance 2 from
     * the binary target.
     */
    String sourceName = "top_chain.c";
    workspace.replaceFileContents("foo/" + sourceName, "*p += 1", "*p += 10");
    workspace.runBuckCommand("clean").assertSuccess();
    workspace.runBuckCommand("build", inputBuildTarget.getFullyQualifiedName()).assertSuccess();
    // Check all the buildrules were fetched from the cache (and there's the specs file)
    assertTrue("Expected specs file for func_ret_null() in chain_dep_two.c not found", Files.exists(workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance("//foo:chain_dep_two#default,infer-analyze"), "infer-analysis-%s/specs/mockedSpec.specs"))));
}
Also used : 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 25 with BuckBuildLog

use of com.facebook.buck.testutil.integration.BuckBuildLog 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)

Aggregations

BuckBuildLog (com.facebook.buck.testutil.integration.BuckBuildLog)88 Test (org.junit.Test)88 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)53 BuildTarget (com.facebook.buck.model.BuildTarget)32 OcamlRuleBuilder.createStaticLibraryBuildTarget (com.facebook.buck.ocaml.OcamlRuleBuilder.createStaticLibraryBuildTarget)10 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)9 Path (java.nio.file.Path)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)7 ExecutableFinder (com.facebook.buck.io.ExecutableFinder)2 Sha1HashCode (com.facebook.buck.util.sha1.Sha1HashCode)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)2 NSString (com.dd.plist.NSString)1 AssumeAndroidPlatform (com.facebook.buck.android.AssumeAndroidPlatform)1 ArtifactCache (com.facebook.buck.artifact_cache.ArtifactCache)1 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)1 CxxBuckConfig (com.facebook.buck.cxx.CxxBuckConfig)1 CxxFlavorSanitizer.sanitize (com.facebook.buck.cxx.CxxFlavorSanitizer.sanitize)1 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)1