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");
}
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");
}
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)));
}
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());
}
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);
}
}
Aggregations