use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class CxxBinaryIntegrationTest method testStrippedBinaryCanBeFetchedFromCacheAlone.
@Test
public void testStrippedBinaryCanBeFetchedFromCacheAlone() throws Exception {
assumeTrue(Platform.detect() == Platform.MACOS);
BuildTarget strippedTarget = BuildTargetFactory.newInstance("//:test").withFlavors(StripStyle.DEBUGGING_SYMBOLS.getFlavor());
BuildTarget unstrippedTarget = strippedTarget.withoutFlavors(StripStyle.FLAVOR_DOMAIN.getFlavors());
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "header_namespace", tmp);
workspace.setUp();
workspace.enableDirCache();
workspace.setupCxxSandboxing(sandboxSources);
ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath());
workspace.runBuckCommand("build", "--config", "cxx.cxxflags=-g", strippedTarget.getFullyQualifiedName()).assertSuccess();
workspace.runBuckCommand("clean").assertSuccess();
workspace.runBuckCommand("build", "--config", "cxx.cxxflags=-g", strippedTarget.getFullyQualifiedName()).assertSuccess();
Path strippedPath = workspace.getPath(BuildTargets.getGenPath(filesystem, strippedTarget.withAppendedFlavors(CxxStrip.RULE_FLAVOR), "%s"));
Path unstrippedPath = workspace.getPath(BuildTargets.getGenPath(filesystem, unstrippedTarget, "%s"));
assertThat(Files.exists(strippedPath), Matchers.equalTo(true));
assertThat(Files.exists(unstrippedPath), Matchers.equalTo(false));
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class CxxBoostTestTest method testParseResults.
@Test
public void testParseResults() throws Exception {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "boost_test", tmp);
workspace.setUp();
ImmutableList<String> samples = ImmutableList.of("simple_success", "simple_failure", "simple_failure_with_output");
BuildTarget target = BuildTargetFactory.newInstance("//:test");
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
CxxBoostTest test = new CxxBoostTest(new FakeBuildRuleParamsBuilder(target).setProjectFilesystem(new ProjectFilesystem(tmp.getRoot())).build(), ruleFinder, new CxxLink(new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//:link")).build(), CxxPlatformUtils.DEFAULT_PLATFORM.getLd().resolve(ruleResolver), Paths.get("output"), ImmutableList.of(), Optional.empty(), /* cacheable */
true), new CommandTool.Builder().addArg(StringArg.of("")).build(), ImmutableMap.of(), Suppliers.ofInstance(ImmutableList.of()), ImmutableSortedSet.of(), Suppliers.ofInstance(ImmutableSortedSet.of()), ImmutableSet.of(), ImmutableSet.of(), /* runTestSeparately */
false, /* testRuleTimeoutMs */
Optional.empty());
for (String sample : samples) {
Path exitCode = Paths.get("unused");
Path output = workspace.resolve(Paths.get(sample)).resolve("output");
Path results = workspace.resolve(Paths.get(sample)).resolve("results");
Path summaries = workspace.resolve(Paths.get(sample)).resolve("summaries");
List<TestResultSummary> expectedSummaries = mapper.readValue(summaries.toFile(), SUMMARIES_REFERENCE);
ImmutableList<TestResultSummary> actualSummaries = test.parseResults(exitCode, output, results);
assertEquals(sample, expectedSummaries, actualSummaries);
}
}
use of com.facebook.buck.io.ProjectFilesystem in project buck by facebook.
the class CxxCollectAndLogInferDependenciesStepTest method testStepWritesNoCellTokenInFileWhenCellIsAbsent.
@Test
public void testStepWritesNoCellTokenInFileWhenCellIsAbsent() throws IOException, InterruptedException {
assumeThat(Platform.detect(), is(not(WINDOWS)));
ProjectFilesystem filesystem = createFakeFilesystem("/Users/user/src");
BuildTarget testBuildTarget = BuildTarget.builder().setUnflavoredBuildTarget(UnflavoredBuildTarget.of(filesystem.getRootPath(), Optional.empty(), "//target", "short")).addFlavors(CxxInferEnhancer.InferFlavors.INFER.get()).build();
BuildRuleParams testBuildRuleParams = new FakeBuildRuleParamsBuilder(testBuildTarget).setProjectFilesystem(filesystem).build();
InferBuckConfig inferBuckConfig = new InferBuckConfig(FakeBuckConfig.builder().build());
CxxInferCaptureAndAggregatingRules<CxxInferAnalyze> captureAndAggregatingRules = new CxxInferCaptureAndAggregatingRules<>(ImmutableSet.of(), ImmutableSet.<CxxInferAnalyze>of());
CxxInferAnalyze analyzeRule = new CxxInferAnalyze(testBuildRuleParams, inferBuckConfig, captureAndAggregatingRules);
Path outputFile = Paths.get("infer-deps.txt");
CxxCollectAndLogInferDependenciesStep step = CxxCollectAndLogInferDependenciesStep.fromAnalyzeRule(analyzeRule, filesystem, outputFile);
ExecutionContext executionContext = TestExecutionContext.newInstance();
int exitCode = step.execute(executionContext).getExitCode();
assertThat(exitCode, is(StepExecutionResult.SUCCESS.getExitCode()));
String expectedOutput = InferLogLine.fromBuildTarget(testBuildTarget, analyzeRule.getAbsolutePathToResultsDir()).toString();
assertEquals(expectedOutput + "\n", filesystem.readFileIfItExists(outputFile).get());
}
use of com.facebook.buck.io.ProjectFilesystem 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"))));
}
use of com.facebook.buck.io.ProjectFilesystem 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"))));
}
Aggregations