Search in sources :

Example 66 with BuckBuildLog

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

the class CxxBinaryIntegrationTest method testInferCxxBinaryWithDeps.

@Test
public void testInferCxxBinaryWithDeps() 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:binary_with_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 all the required build targets have been generated.
     */
    String sourceName = "src_with_deps.c";
    CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactoryHelper.of(workspace.getDestPath(), inputBuildTarget, cxxPlatform, cxxBuckConfig);
    // 1. create the targets of binary_with_deps
    // this is unflavored, but bounded to the InferCapture build rule
    BuildTarget topCaptureBuildTarget = cxxSourceRuleFactory.createInferCaptureBuildTarget(sourceName);
    BuildTarget topSandboxTreeTarget = CxxDescriptionEnhancer.createSandboxSymlinkTreeTarget(inputBuildTarget, cxxPlatform.getFlavor());
    // this is unflavored, but necessary to run the compiler successfully
    BuildTarget topHeaderSymlinkTreeTarget = CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(inputBuildTarget, HeaderVisibility.PRIVATE, cxxPlatform.getFlavor());
    // this is flavored, and denotes the analysis step (generates a local report)
    BuildTarget topInferAnalysisTarget = 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 topInferReportTarget = inputBuildTarget.withFlavors(CxxInferEnhancer.InferFlavors.INFER.get());
    BuildTarget topAggregatedDepsTarget = cxxSourceRuleFactory.createAggregatedPreprocessDepsBuildTarget();
    // 2. create the targets of dep_one
    BuildTarget depOneBuildTarget = BuildTargetFactory.newInstance(workspace.getDestPath(), "//foo:dep_one");
    String depOneSourceName = "dep_one.c";
    String depOneSourceFull = "foo/" + depOneSourceName;
    CxxSourceRuleFactory depOneSourceRuleFactory = CxxSourceRuleFactoryHelper.of(workspace.getDestPath(), depOneBuildTarget, cxxPlatform, cxxBuckConfig);
    BuildTarget depOneCaptureBuildTarget = depOneSourceRuleFactory.createInferCaptureBuildTarget(depOneSourceName);
    BuildTarget depOneSandboxTreeTarget = CxxDescriptionEnhancer.createSandboxSymlinkTreeTarget(depOneBuildTarget, cxxPlatform.getFlavor());
    BuildTarget depOneHeaderSymlinkTreeTarget = CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(depOneBuildTarget, HeaderVisibility.PRIVATE, cxxPlatform.getFlavor());
    BuildTarget depOneExportedHeaderSymlinkTreeTarget = CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(depOneBuildTarget, HeaderVisibility.PUBLIC, CxxPlatformUtils.getHeaderModeForDefaultPlatform(tmp.getRoot()).getFlavor());
    BuildTarget depOneInferAnalysisTarget = depOneCaptureBuildTarget.withFlavors(cxxPlatform.getFlavor(), CxxInferEnhancer.InferFlavors.INFER_ANALYZE.get());
    BuildTarget depOneAggregatedDepsTarget = depOneSourceRuleFactory.createAggregatedPreprocessDepsBuildTarget();
    // 3. create the targets of dep_two
    BuildTarget depTwoBuildTarget = BuildTargetFactory.newInstance(workspace.getDestPath(), "//foo:dep_two");
    CxxSourceRuleFactory depTwoSourceRuleFactory = CxxSourceRuleFactoryHelper.of(workspace.getDestPath(), depTwoBuildTarget, cxxPlatform, cxxBuckConfig);
    BuildTarget depTwoCaptureBuildTarget = depTwoSourceRuleFactory.createInferCaptureBuildTarget("dep_two.c");
    BuildTarget depTwoSandboxTreeTarget = CxxDescriptionEnhancer.createSandboxSymlinkTreeTarget(depTwoBuildTarget, cxxPlatform.getFlavor());
    BuildTarget depTwoHeaderSymlinkTreeTarget = CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(depTwoBuildTarget, HeaderVisibility.PRIVATE, cxxPlatform.getFlavor());
    BuildTarget depTwoExportedHeaderSymlinkTreeTarget = CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(depTwoBuildTarget, HeaderVisibility.PUBLIC, CxxPlatformUtils.getHeaderModeForDefaultPlatform(tmp.getRoot()).getFlavor());
    BuildTarget depTwoInferAnalysisTarget = depTwoCaptureBuildTarget.withFlavors(cxxPlatform.getFlavor(), CxxInferEnhancer.InferFlavors.INFER_ANALYZE.get());
    BuildTarget depTwoAggregatedDepsTarget = depTwoSourceRuleFactory.createAggregatedPreprocessDepsBuildTarget();
    ImmutableSet.Builder<BuildTarget> buildTargets = ImmutableSortedSet.<BuildTarget>naturalOrder().add(topAggregatedDepsTarget, topCaptureBuildTarget, topHeaderSymlinkTreeTarget, topInferAnalysisTarget, topInferReportTarget, depOneAggregatedDepsTarget, depOneCaptureBuildTarget, depOneHeaderSymlinkTreeTarget, depOneExportedHeaderSymlinkTreeTarget, depOneInferAnalysisTarget, depTwoAggregatedDepsTarget, depTwoCaptureBuildTarget, depTwoHeaderSymlinkTreeTarget, depTwoExportedHeaderSymlinkTreeTarget, depTwoInferAnalysisTarget);
    if (sandboxSources) {
        buildTargets.add(topSandboxTreeTarget, depOneSandboxTreeTarget, depTwoSandboxTreeTarget);
    }
    // Check all the targets are in the buildLog
    assertEquals(buildTargets.build(), ImmutableSet.copyOf(workspace.getBuildLog().getAllTargets()));
    /*
     * 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();
    BuckBuildLog buildLog = workspace.getBuildLog();
    assertEquals(ImmutableSet.of(topInferReportTarget), buildLog.getAllTargets());
    buildLog.assertTargetHadMatchingRuleKey(topInferReportTarget.toString());
    /*
     * Check that if a library source file changes then the capture/analysis rules run again on
     * the main target and on dep_one only.
     */
    workspace.resetBuildLogFile();
    workspace.replaceFileContents(depOneSourceFull, "flag > 0", "flag < 0");
    workspace.runBuckCommand("build", inputBuildTargetName).assertSuccess();
    buildLog = workspace.getBuildLog();
    buildTargets = ImmutableSortedSet.<BuildTarget>naturalOrder().add(// analysis runs again
    topInferAnalysisTarget, // report runs again
    topInferReportTarget, // cached
    topCaptureBuildTarget, // cached
    depTwoInferAnalysisTarget, depOneAggregatedDepsTarget, // capture of the changed file runs again
    depOneCaptureBuildTarget, // analysis of the library runs again
    depOneInferAnalysisTarget);
    if (sandboxSources) {
        buildTargets.add(depOneSandboxTreeTarget, depOneHeaderSymlinkTreeTarget, depOneExportedHeaderSymlinkTreeTarget);
    }
    assertEquals(buildTargets.build(), buildLog.getAllTargets());
    buildLog.assertTargetBuiltLocally(topInferAnalysisTarget.toString());
    buildLog.assertTargetBuiltLocally(topInferReportTarget.toString());
    buildLog.assertTargetHadMatchingRuleKey(topCaptureBuildTarget.toString());
    buildLog.assertTargetHadMatchingRuleKey(depTwoInferAnalysisTarget.toString());
    buildLog.assertTargetBuiltLocally(depOneCaptureBuildTarget.toString());
    buildLog.assertTargetBuiltLocally(depOneInferAnalysisTarget.toString());
    if (sandboxSources) {
        buildLog.assertTargetHadMatchingInputRuleKey(depOneSandboxTreeTarget.toString());
        buildLog.assertTargetHadMatchingRuleKey(depOneHeaderSymlinkTreeTarget.toString());
        buildLog.assertTargetHadMatchingRuleKey(depOneExportedHeaderSymlinkTreeTarget.toString());
        buildLog.assertTargetBuiltLocally(depOneAggregatedDepsTarget.toString());
    } else {
        buildLog.assertTargetHadMatchingRuleKey(depOneAggregatedDepsTarget.toString());
    }
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) BuckBuildLog(com.facebook.buck.testutil.integration.BuckBuildLog) Test(org.junit.Test)

Example 67 with BuckBuildLog

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

the class CxxBinaryIntegrationTest method testLinkMapIsCached.

@Test
public void testLinkMapIsCached() throws Exception {
    // Currently we only support Apple platforms for generating link maps.
    assumeTrue(Platform.detect() == Platform.MACOS);
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "simple", tmp);
    workspace.setUp();
    workspace.enableDirCache();
    workspace.setupCxxSandboxing(sandboxSources);
    ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath());
    BuildTarget target = BuildTargetFactory.newInstance("//foo:simple");
    workspace.runBuckCommand("build", target.getFullyQualifiedName()).assertSuccess();
    Path outputPath = workspace.getPath(BuildTargets.getGenPath(filesystem, target, "%s"));
    /*
     * Check that building after clean will use the cache
     */
    workspace.runBuckCommand("clean").assertSuccess();
    workspace.runBuckCommand("build", target.toString()).assertSuccess();
    BuckBuildLog buildLog = workspace.getBuildLog();
    buildLog.assertTargetWasFetchedFromCache(target.toString());
    assertThat(Files.exists(Paths.get(outputPath.toString() + "-LinkMap.txt")), is(true));
}
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 68 with BuckBuildLog

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

the class CxxBinaryIntegrationTest method testSimpleCxxBinaryWithDependencyOnCxxLibraryWithHeader.

@Test
public void testSimpleCxxBinaryWithDependencyOnCxxLibraryWithHeader() throws IOException, InterruptedException {
    Assume.assumeFalse("Test should be modified for sandboxing", sandboxSources);
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "simple", tmp);
    workspace.setUp();
    workspace.setupCxxSandboxing(sandboxSources);
    // Setup variables pointing to the sources and targets of the top-level binary rule.
    CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(workspace.asCell().getBuckConfig());
    CxxPlatform cxxPlatform = CxxPlatformUtils.build(cxxBuckConfig);
    BuildTarget target = BuildTargetFactory.newInstance(workspace.getDestPath(), "//foo:binary_with_dep");
    CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactoryHelper.of(workspace.getDestPath(), target, cxxPlatform, cxxBuckConfig);
    BuildTarget binaryTarget = CxxDescriptionEnhancer.createCxxLinkTarget(target, Optional.<LinkerMapMode>empty());
    String sourceName = "foo.cpp";
    BuildTarget compileTarget = cxxSourceRuleFactory.createCompileBuildTarget(sourceName);
    BuildTarget headerSymlinkTreeTarget = CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(target, HeaderVisibility.PRIVATE, cxxPlatform.getFlavor());
    BuildTarget aggregatedDepsTarget = cxxSourceRuleFactory.createAggregatedPreprocessDepsBuildTarget();
    // Setup variables pointing to the sources and targets of the library dep.
    BuildTarget depTarget = BuildTargetFactory.newInstance(workspace.getDestPath(), "//foo:library_with_header");
    CxxSourceRuleFactory depCxxSourceRuleFactory = CxxSourceRuleFactoryHelper.of(workspace.getDestPath(), depTarget, cxxPlatform, cxxBuckConfig);
    String depSourceName = "bar.cpp";
    String depSourceFull = "foo/" + depSourceName;
    String depHeaderName = "bar.h";
    String depHeaderFull = "foo/" + depHeaderName;
    BuildTarget depCompileTarget = depCxxSourceRuleFactory.createCompileBuildTarget(depSourceName);
    BuildTarget depHeaderSymlinkTreeTarget = CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(depTarget, HeaderVisibility.PRIVATE, cxxPlatform.getFlavor());
    BuildTarget depHeaderExportedSymlinkTreeTarget = CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(depTarget, HeaderVisibility.PUBLIC, CxxPlatformUtils.getHeaderModeForDefaultPlatform(tmp.getRoot()).getFlavor());
    BuildTarget depSandboxTarget = CxxDescriptionEnhancer.createSandboxSymlinkTreeTarget(depTarget, cxxPlatform.getFlavor());
    BuildTarget depArchiveTarget = CxxDescriptionEnhancer.createStaticLibraryBuildTarget(depTarget, cxxPlatform.getFlavor(), CxxSourceRuleFactory.PicType.PDC);
    BuildTarget depAggregatedDepsTarget = depCxxSourceRuleFactory.createAggregatedPreprocessDepsBuildTarget();
    ImmutableList.Builder<BuildTarget> builder = ImmutableList.builder();
    builder.add(depAggregatedDepsTarget, depHeaderSymlinkTreeTarget, depHeaderExportedSymlinkTreeTarget, depCompileTarget, depArchiveTarget, depTarget, aggregatedDepsTarget, headerSymlinkTreeTarget, compileTarget, binaryTarget, target);
    if (cxxBuckConfig.sandboxSources()) {
        builder.add(depSandboxTarget);
    }
    // Do a clean build, verify that it succeeds, and check that all expected targets built
    // successfully.
    workspace.runBuckCommand("build", target.toString()).assertSuccess();
    BuckBuildLog buildLog = workspace.getBuildLog();
    assertThat(buildLog.getAllTargets(), containsInAnyOrder(builder.build().toArray(new BuildTarget[] {})));
    buildLog.assertTargetBuiltLocally(depHeaderSymlinkTreeTarget.toString());
    buildLog.assertTargetBuiltLocally(depCompileTarget.toString());
    buildLog.assertTargetBuiltLocally(depArchiveTarget.toString());
    buildLog.assertTargetBuiltLocally(depTarget.toString());
    buildLog.assertTargetBuiltLocally(headerSymlinkTreeTarget.toString());
    buildLog.assertTargetBuiltLocally(compileTarget.toString());
    buildLog.assertTargetBuiltLocally(binaryTarget.toString());
    buildLog.assertTargetBuiltLocally(target.toString());
    // Clear for new build.
    workspace.resetBuildLogFile();
    // Update the source file.
    workspace.replaceFileContents(depHeaderFull, "int x", "int y");
    // Check that running a build again makes the source get recompiled and the binary
    // re-linked, but does not cause the header rules to re-run.
    workspace.runBuckCommand("build", target.toString()).assertSuccess();
    buildLog = workspace.getBuildLog();
    builder = ImmutableList.builder();
    builder.add(depAggregatedDepsTarget, depCompileTarget, depArchiveTarget, depTarget, depHeaderSymlinkTreeTarget, depHeaderExportedSymlinkTreeTarget, headerSymlinkTreeTarget, aggregatedDepsTarget, compileTarget, binaryTarget, target);
    if (cxxBuckConfig.sandboxSources()) {
        builder.add(depSandboxTarget);
    }
    assertThat(buildLog.getAllTargets(), containsInAnyOrder(builder.build().toArray(new BuildTarget[] {})));
    buildLog.assertTargetBuiltLocally(depAggregatedDepsTarget.toString());
    buildLog.assertTargetBuiltLocally(depCompileTarget.toString());
    buildLog.assertTargetHadMatchingInputRuleKey(depArchiveTarget.toString());
    buildLog.assertTargetHadMatchingRuleKey(depHeaderSymlinkTreeTarget.toString());
    buildLog.assertTargetHadMatchingInputRuleKey(depHeaderExportedSymlinkTreeTarget.toString());
    buildLog.assertTargetHadMatchingRuleKey(headerSymlinkTreeTarget.toString());
    buildLog.assertTargetHadMatchingRuleKey(depTarget.toString());
    buildLog.assertTargetBuiltLocally(aggregatedDepsTarget.toString());
    buildLog.assertTargetBuiltLocally(compileTarget.toString());
    assertThat(buildLog.getLogEntry(binaryTarget).getSuccessType().get(), Matchers.not(Matchers.equalTo(BuildRuleSuccessType.MATCHING_RULE_KEY)));
    // Clear for new build.
    workspace.resetBuildLogFile();
    // Update the source file.
    workspace.replaceFileContents(depSourceFull, "x + 5", "x + 6");
    // Check that running a build again makes the source get recompiled and the binary
    // re-linked, but does not cause the header rules to re-run.
    workspace.runBuckCommand("build", target.toString()).assertSuccess();
    buildLog = workspace.getBuildLog();
    builder = ImmutableList.builder();
    builder.add(depAggregatedDepsTarget, depCompileTarget, depArchiveTarget, depTarget, compileTarget, binaryTarget, target);
    if (cxxBuckConfig.sandboxSources()) {
        builder.add(depSandboxTarget);
    }
    assertThat(buildLog.getAllTargets(), containsInAnyOrder(builder.build().toArray(new BuildTarget[] {})));
    buildLog.assertTargetHadMatchingRuleKey(depAggregatedDepsTarget.toString());
    buildLog.assertTargetBuiltLocally(depCompileTarget.toString());
    buildLog.assertTargetBuiltLocally(depArchiveTarget.toString());
    buildLog.assertTargetHadMatchingRuleKey(depTarget.toString());
    buildLog.assertTargetHadMatchingRuleKey(compileTarget.toString());
    buildLog.assertTargetBuiltLocally(binaryTarget.toString());
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) ImmutableList(com.google.common.collect.ImmutableList) BuckBuildLog(com.facebook.buck.testutil.integration.BuckBuildLog) Test(org.junit.Test)

Example 69 with BuckBuildLog

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

the class AndroidReactNativeLibraryIntegrationTest method testEditingUnusedJSFileDoesNotTriggerRebuild.

@Test
public void testEditingUnusedJSFileDoesNotTriggerRebuild() throws IOException {
    workspace.runBuckBuild("//apps/sample:app").assertSuccess();
    workspace.replaceFileContents("js/app/unused.js", "anotherFunction", "someOtherFunction");
    workspace.resetBuildLogFile();
    workspace.runBuckBuild("//apps/sample:app").assertSuccess();
    BuckBuildLog buildLog = workspace.getBuildLog();
    buildLog.assertTargetHadMatchingDepfileRuleKey("//js:app#bundle,dev");
}
Also used : BuckBuildLog(com.facebook.buck.testutil.integration.BuckBuildLog) Test(org.junit.Test)

Example 70 with BuckBuildLog

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

the class AndroidReactNativeLibraryIntegrationTest method testEditingUsedJSFileTriggersRebuild.

@Test
public void testEditingUsedJSFileTriggersRebuild() throws IOException {
    workspace.runBuckBuild("//apps/sample:app").assertSuccess();
    workspace.replaceFileContents("js/app/helpers.js", "something", "nothing");
    workspace.resetBuildLogFile();
    workspace.runBuckBuild("//apps/sample:app").assertSuccess();
    BuckBuildLog buildLog = workspace.getBuildLog();
    buildLog.assertTargetBuiltLocally("//js:app#bundle,dev");
}
Also used : BuckBuildLog(com.facebook.buck.testutil.integration.BuckBuildLog) 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