Search in sources :

Example 86 with ProjectFilesystem

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));
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 87 with ProjectFilesystem

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);
    }
}
Also used : Path(java.nio.file.Path) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) TestResultSummary(com.facebook.buck.test.TestResultSummary) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) CommandTool(com.facebook.buck.rules.CommandTool) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 88 with ProjectFilesystem

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());
}
Also used : FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 89 with ProjectFilesystem

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"))));
}
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 90 with ProjectFilesystem

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

Aggregations

ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)654 Test (org.junit.Test)542 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)401 Path (java.nio.file.Path)324 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)207 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)204 BuildTarget (com.facebook.buck.model.BuildTarget)203 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)126 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)121 TargetGraph (com.facebook.buck.rules.TargetGraph)119 PathSourcePath (com.facebook.buck.rules.PathSourcePath)96 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)92 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)90 SourcePath (com.facebook.buck.rules.SourcePath)79 ExecutionContext (com.facebook.buck.step.ExecutionContext)67 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)67 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)63 BuildRule (com.facebook.buck.rules.BuildRule)56 RuleKey (com.facebook.buck.rules.RuleKey)43 ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)42