Search in sources :

Example 61 with BuckBuildLog

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

the class CxxBinaryIntegrationTest method headersShouldBeSetUpCorrectlyOnRebuild.

/**
   * Tests that, if a file has to be rebuilt, but its header dependencies do not, that the header
   * tree is still generated into the correct location.
   */
@Test
public void headersShouldBeSetUpCorrectlyOnRebuild() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "cxx_binary_dep_header_tree_materialize", tmp);
    workspace.setUp();
    workspace.enableDirCache();
    workspace.setupCxxSandboxing(sandboxSources);
    workspace.runBuckBuild("//:bin").assertSuccess();
    workspace.runBuckCommand("clean");
    workspace.copyFile("bin.c.new", "bin.c");
    workspace.runBuckBuild("//:bin").assertSuccess();
    BuckBuildLog log = workspace.getBuildLog();
    log.assertTargetBuiltLocally("//:bin#binary");
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuckBuildLog(com.facebook.buck.testutil.integration.BuckBuildLog) Test(org.junit.Test)

Example 62 with BuckBuildLog

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

the class CxxBinaryIntegrationTest method testCxxBinaryDepfileBuildWithChangedHeader.

@Test
public void testCxxBinaryDepfileBuildWithChangedHeader() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "cxx_binary_depfile_build_with_changed_header", tmp);
    workspace.setUp();
    workspace.setupCxxSandboxing(sandboxSources);
    ProjectWorkspace.ProcessResult result = workspace.runBuckCommand("build", "//:bin");
    result.assertSuccess();
    BuckBuildLog buildLog = workspace.getBuildLog();
    buildLog.assertTargetBuiltLocally("//:bin#binary");
    buildLog.assertTargetBuiltLocally("//:bin#compile-" + sanitize("bin.c.o") + ",default");
    buildLog.assertTargetBuiltLocally("//:lib1#default,static");
    workspace.resetBuildLogFile();
    workspace.replaceFileContents("lib2.h", "hello", "world");
    result = workspace.runBuckCommand("build", "//:bin");
    result.assertSuccess();
    buildLog = workspace.getBuildLog();
    buildLog.assertTargetBuiltLocally("//:bin#binary");
    buildLog.assertTargetHadMatchingDepfileRuleKey("//:bin#compile-" + sanitize("bin.c.o") + ",default");
    buildLog.assertTargetBuiltLocally("//:lib1#default,static");
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuckBuildLog(com.facebook.buck.testutil.integration.BuckBuildLog) Test(org.junit.Test)

Example 63 with BuckBuildLog

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

the class CxxBinaryIntegrationTest method testSimpleCxxBinaryWithHeader.

@Test
public void testSimpleCxxBinaryWithHeader() throws IOException, InterruptedException {
    Assume.assumeFalse("Test should be modified for sandboxing", sandboxSources);
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "simple", tmp);
    workspace.setUp();
    workspace.setupCxxSandboxing(sandboxSources);
    CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(workspace.asCell().getBuckConfig());
    CxxPlatform cxxPlatform = CxxPlatformUtils.build(cxxBuckConfig);
    BuildTarget target = BuildTargetFactory.newInstance(workspace.getDestPath(), "//foo:simple_with_header");
    CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactoryHelper.of(workspace.getDestPath(), target, cxxPlatform, cxxBuckConfig);
    BuildTarget binaryTarget = CxxDescriptionEnhancer.createCxxLinkTarget(target, Optional.<LinkerMapMode>empty());
    String sourceName = "simple_with_header.cpp";
    String headerName = "simple_with_header.h";
    String headerFull = "foo/" + headerName;
    BuildTarget compileTarget = cxxSourceRuleFactory.createCompileBuildTarget(sourceName);
    BuildTarget headerSymlinkTreeTarget = CxxDescriptionEnhancer.createHeaderSymlinkTreeTarget(target, HeaderVisibility.PRIVATE, cxxPlatform.getFlavor());
    BuildTarget aggregatedDepsTarget = cxxSourceRuleFactory.createAggregatedPreprocessDepsBuildTarget();
    // 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();
    assertEquals(ImmutableSet.of(aggregatedDepsTarget, headerSymlinkTreeTarget, compileTarget, binaryTarget, target), buildLog.getAllTargets());
    buildLog.assertTargetBuiltLocally(aggregatedDepsTarget.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(headerFull, "blah = 5", "blah = 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();
    assertEquals(ImmutableSet.of(headerSymlinkTreeTarget, aggregatedDepsTarget, compileTarget, binaryTarget, target), buildLog.getAllTargets());
    buildLog.assertTargetHadMatchingInputRuleKey(headerSymlinkTreeTarget.toString());
    buildLog.assertTargetBuiltLocally(aggregatedDepsTarget.toString());
    buildLog.assertTargetBuiltLocally(compileTarget.toString());
    assertThat(buildLog.getLogEntry(binaryTarget).getSuccessType().get(), Matchers.not(Matchers.equalTo(BuildRuleSuccessType.MATCHING_RULE_KEY)));
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) BuckBuildLog(com.facebook.buck.testutil.integration.BuckBuildLog) Test(org.junit.Test)

Example 64 with BuckBuildLog

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

the class CxxBinaryIntegrationTest method testInferCxxBinaryWithUnusedDepsDoesNotRebuildWhenUnusedHeaderChanges.

@Test
public void testInferCxxBinaryWithUnusedDepsDoesNotRebuildWhenUnusedHeaderChanges() throws IOException, InterruptedException {
    assumeTrue(Platform.detect() != Platform.WINDOWS);
    ProjectWorkspace workspace = InferHelper.setupCxxInferWorkspace(this, tmp, Optional.empty());
    workspace.enableDirCache();
    workspace.setupCxxSandboxing(sandboxSources);
    BuildTarget inputBuildTarget = BuildTargetFactory.newInstance("//foo:binary_with_unused_header");
    String inputBuildTargetName = inputBuildTarget.withFlavors(CxxInferEnhancer.InferFlavors.INFER_CAPTURE_ALL.get()).getFullyQualifiedName();
    CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(workspace.asCell().getBuckConfig());
    CxxPlatform cxxPlatform = CxxPlatformUtils.build(cxxBuckConfig);
    CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactoryHelper.of(workspace.getDestPath(), inputBuildTarget, cxxPlatform, cxxBuckConfig);
    BuildTarget simpleOneCppCaptureTarget = cxxSourceRuleFactory.createInferCaptureBuildTarget("simple_one.cpp");
    workspace.runBuckCommand("build", inputBuildTargetName).assertSuccess();
    /*
     * Check that when the unused-header is changed, no builds are triggered
     */
    workspace.resetBuildLogFile();
    workspace.replaceFileContents("foo/unused_header.h", "int* input", "int* input, int* input2");
    workspace.runBuckCommand("clean").assertSuccess();
    workspace.runBuckCommand("build", inputBuildTargetName).assertSuccess();
    BuckBuildLog buildLog = workspace.getBuildLog();
    BuckBuildLog.BuildLogEntry simpleOnceCppCaptureTargetEntry = buildLog.getLogEntry(simpleOneCppCaptureTarget);
    assertThat(simpleOnceCppCaptureTargetEntry.getSuccessType(), Matchers.equalTo(Optional.of(BuildRuleSuccessType.FETCHED_FROM_CACHE_MANIFEST_BASED)));
    /*
     * Check that when the used-header is changed, then a build is triggered
     */
    workspace.resetBuildLogFile();
    workspace.replaceFileContents("foo/used_header.h", "int* input", "int* input, int* input2");
    workspace.runBuckCommand("clean").assertSuccess();
    workspace.runBuckCommand("build", inputBuildTargetName).assertSuccess();
    buildLog = workspace.getBuildLog();
    buildLog.assertTargetBuiltLocally(simpleOneCppCaptureTarget.toString());
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) BuckBuildLog(com.facebook.buck.testutil.integration.BuckBuildLog) Test(org.junit.Test)

Example 65 with BuckBuildLog

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

the class CxxBinaryIntegrationTest method testInferCxxBinaryDepsInvalidateCacheWhenVersionChanges.

@Test
public void testInferCxxBinaryDepsInvalidateCacheWhenVersionChanges() throws IOException, InterruptedException {
    assumeTrue(Platform.detect() != Platform.WINDOWS);
    ProjectWorkspace workspace = InferHelper.setupCxxInferWorkspace(this, tmp, Optional.empty());
    workspace.enableDirCache();
    workspace.setupCxxSandboxing(sandboxSources);
    CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(workspace.asCell().getBuckConfig());
    CxxPlatform cxxPlatform = CxxPlatformUtils.build(cxxBuckConfig);
    BuildTarget inputBuildTarget = BuildTargetFactory.newInstance("//foo:binary_with_deps");
    final 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 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 if the version of infer changes, then all the infer-related targets are
     * recomputed
     */
    workspace.resetBuildLogFile();
    workspace.replaceFileContents("fake-infer/fake-bin/infer", "0.12345", "9.9999");
    workspace.runBuckCommand("clean").assertSuccess();
    workspace.runBuckCommand("build", inputBuildTargetName).assertSuccess();
    buildLog = workspace.getBuildLog();
    String sourceName = "src_with_deps.c";
    CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactoryHelper.of(workspace.getDestPath(), inputBuildTarget, cxxPlatform, cxxBuckConfig);
    BuildTarget topCaptureBuildTarget = cxxSourceRuleFactory.createInferCaptureBuildTarget(sourceName);
    BuildTarget topInferAnalysisTarget = inputBuildTarget.withFlavors(CxxInferEnhancer.InferFlavors.INFER_ANALYZE.get());
    BuildTarget topInferReportTarget = inputBuildTarget.withFlavors(CxxInferEnhancer.InferFlavors.INFER.get());
    BuildTarget depOneBuildTarget = BuildTargetFactory.newInstance(workspace.getDestPath(), "//foo:dep_one");
    String depOneSourceName = "dep_one.c";
    CxxSourceRuleFactory depOneSourceRuleFactory = CxxSourceRuleFactoryHelper.of(workspace.getDestPath(), depOneBuildTarget, cxxPlatform, cxxBuckConfig);
    BuildTarget depOneCaptureBuildTarget = depOneSourceRuleFactory.createInferCaptureBuildTarget(depOneSourceName);
    BuildTarget depOneInferAnalysisTarget = depOneCaptureBuildTarget.withFlavors(cxxPlatform.getFlavor(), CxxInferEnhancer.InferFlavors.INFER_ANALYZE.get());
    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 depTwoInferAnalysisTarget = depTwoCaptureBuildTarget.withFlavors(cxxPlatform.getFlavor(), CxxInferEnhancer.InferFlavors.INFER_ANALYZE.get());
    ImmutableSet<String> locallyBuiltTargets = ImmutableSet.of(cxxSourceRuleFactory.createAggregatedPreprocessDepsBuildTarget().toString(), topCaptureBuildTarget.toString(), topInferAnalysisTarget.toString(), topInferReportTarget.toString(), depOneSourceRuleFactory.createAggregatedPreprocessDepsBuildTarget().toString(), depOneCaptureBuildTarget.toString(), depOneInferAnalysisTarget.toString(), depTwoSourceRuleFactory.createAggregatedPreprocessDepsBuildTarget().toString(), depTwoCaptureBuildTarget.toString(), depTwoInferAnalysisTarget.toString());
    // check that infer-related targets are getting rebuilt
    for (String t : locallyBuiltTargets) {
        buildLog.assertTargetBuiltLocally(t);
    }
    Set<String> builtFromCacheTargets = FluentIterable.from(buildLog.getAllTargets()).filter(target -> (!target.getFlavors().contains(CxxDescriptionEnhancer.EXPORTED_HEADER_SYMLINK_TREE_FLAVOR) && !target.getFlavors().contains(CxxDescriptionEnhancer.HEADER_SYMLINK_TREE_FLAVOR) && !target.getFlavors().contains(CxxDescriptionEnhancer.SANDBOX_TREE_FLAVOR))).transform(Object::toString).filter(Predicates.not(locallyBuiltTargets::contains)).toSet();
    // check that all the other targets are fetched from the cache
    for (String t : builtFromCacheTargets) {
        buildLog.assertTargetWasFetchedFromCache(t);
    }
}
Also used : TestDataHelper(com.facebook.buck.testutil.integration.TestDataHelper) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AssumeAndroidPlatform(com.facebook.buck.android.AssumeAndroidPlatform) InferHelper(com.facebook.buck.testutil.integration.InferHelper) FluentIterable(com.google.common.collect.FluentIterable) PathMatcher(java.nio.file.PathMatcher) BuckBuildLog(com.facebook.buck.testutil.integration.BuckBuildLog) Path(java.nio.file.Path) Parameterized(org.junit.runners.Parameterized) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) ImmutableSet(com.google.common.collect.ImmutableSet) CxxFlavorSanitizer.sanitize(com.facebook.buck.cxx.CxxFlavorSanitizer.sanitize) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Platform(com.facebook.buck.util.environment.Platform) Set(java.util.Set) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) Assume.assumeTrue(org.junit.Assume.assumeTrue) Joiner(com.google.common.base.Joiner) Assume.assumeThat(org.junit.Assume.assumeThat) RunWith(org.junit.runner.RunWith) TemporaryPaths(com.facebook.buck.testutil.integration.TemporaryPaths) Assert.assertSame(org.junit.Assert.assertSame) BuildRuleStatus(com.facebook.buck.rules.BuildRuleStatus) ImmutableList(com.google.common.collect.ImmutableList) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) File.pathSeparator(java.io.File.pathSeparator) Predicates(com.google.common.base.Predicates) Assume(org.junit.Assume) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Matchers.oneOf(org.hamcrest.Matchers.oneOf) Files(java.nio.file.Files) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) BuildRuleSuccessType(com.facebook.buck.rules.BuildRuleSuccessType) File(java.io.File) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) Rule(org.junit.Rule) Paths(java.nio.file.Paths) MoreFiles(com.facebook.buck.io.MoreFiles) BuildTargets(com.facebook.buck.model.BuildTargets) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) 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