Search in sources :

Example 86 with DefaultTargetNodeToBuildRuleTransformer

use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer in project buck by facebook.

the class CxxPreprocessablesTest method getTransitiveCxxPreprocessorInput.

@Test
public void getTransitiveCxxPreprocessorInput() throws Exception {
    FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    CxxPlatform cxxPlatform = CxxPlatformUtils.build(new CxxBuckConfig(FakeBuckConfig.builder().setFilesystem(filesystem).build()));
    // Setup a simple CxxPreprocessorDep which contributes components to preprocessing.
    BuildTarget cppDepTarget1 = BuildTargetFactory.newInstance(filesystem, "//:cpp1");
    CxxPreprocessorInput input1 = CxxPreprocessorInput.builder().addRules(cppDepTarget1).putPreprocessorFlags(CxxSource.Type.C, "-Dtest=yes").putPreprocessorFlags(CxxSource.Type.CXX, "-Dtest=yes").build();
    BuildTarget depTarget1 = BuildTargetFactory.newInstance(filesystem, "//:dep1");
    FakeCxxPreprocessorDep dep1 = createFakeCxxPreprocessorDep(depTarget1, pathResolver, input1);
    // Setup another simple CxxPreprocessorDep which contributes components to preprocessing.
    BuildTarget cppDepTarget2 = BuildTargetFactory.newInstance(filesystem, "//:cpp2");
    CxxPreprocessorInput input2 = CxxPreprocessorInput.builder().addRules(cppDepTarget2).putPreprocessorFlags(CxxSource.Type.C, "-DBLAH").putPreprocessorFlags(CxxSource.Type.CXX, "-DBLAH").build();
    BuildTarget depTarget2 = BuildTargetFactory.newInstance("//:dep2");
    FakeCxxPreprocessorDep dep2 = createFakeCxxPreprocessorDep(depTarget2, pathResolver, input2);
    // Create a normal dep which depends on the two CxxPreprocessorDep rules above.
    BuildTarget depTarget3 = BuildTargetFactory.newInstance(filesystem, "//:dep3");
    CxxPreprocessorInput nothing = CxxPreprocessorInput.EMPTY;
    FakeCxxPreprocessorDep dep3 = createFakeCxxPreprocessorDep(depTarget3, pathResolver, nothing, dep1, dep2);
    // Verify that getTransitiveCxxPreprocessorInput gets all CxxPreprocessorInput objects
    // from the relevant rules above.
    ImmutableList<CxxPreprocessorInput> expected = ImmutableList.of(nothing, input1, input2);
    ImmutableList<CxxPreprocessorInput> actual = ImmutableList.copyOf(CxxPreprocessables.getTransitiveCxxPreprocessorInput(cxxPlatform, ImmutableList.<BuildRule>of(dep3)));
    assertEquals(expected, actual);
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 87 with DefaultTargetNodeToBuildRuleTransformer

use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer in project buck by facebook.

the class CxxPreprocessablesTest method createHeaderSymlinkTreeBuildRuleHasNoDeps.

@Test
public void createHeaderSymlinkTreeBuildRuleHasNoDeps() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
    // Setup up the main build target and build params, which some random dep.  We'll make
    // sure the dep doesn't get propagated to the symlink rule below.
    FakeBuildRule dep = createFakeBuildRule(BuildTargetFactory.newInstance(filesystem, "//random:dep"), pathResolver);
    BuildTarget target = BuildTargetFactory.newInstance(filesystem, "//foo:bar");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).setDeclaredDeps(ImmutableSortedSet.of(dep)).setProjectFilesystem(filesystem).build();
    Path root = Paths.get("root");
    // Setup a simple genrule we can wrap in a ExplicitBuildTargetSourcePath to model a input source
    // that is built by another rule.
    Genrule genrule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance(filesystem, "//:genrule")).setOut("foo/bar.o").build(resolver);
    // Setup the link map with both a regular path-based source path and one provided by
    // another build rule.
    ImmutableMap<Path, SourcePath> links = ImmutableMap.of(Paths.get("link1"), new FakeSourcePath("hello"), Paths.get("link2"), genrule.getSourcePathToOutput());
    // Build our symlink tree rule using the helper method.
    HeaderSymlinkTree symlinkTree = CxxPreprocessables.createHeaderSymlinkTreeBuildRule(target, params.getProjectFilesystem(), root, links, CxxPreprocessables.HeaderMode.SYMLINK_TREE_ONLY, ruleFinder);
    // Verify that the symlink tree has no deps.  This is by design, since setting symlinks can
    // be done completely independently from building the source that the links point to and
    // independently from the original deps attached to the input build rule params.
    assertTrue(symlinkTree.getDeps().isEmpty());
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildTarget(com.facebook.buck.model.BuildTarget) Genrule(com.facebook.buck.shell.Genrule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 88 with DefaultTargetNodeToBuildRuleTransformer

use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer in project buck by facebook.

the class CxxSourceRuleFactoryHelper method of.

public static CxxSourceRuleFactory of(Path cellRoot, BuildTarget target, CxxPlatform cxxPlatform, CxxBuckConfig cxxBuckConfig) {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    return CxxSourceRuleFactory.builder().setParams(new FakeBuildRuleParamsBuilder(target).setProjectFilesystem(new FakeProjectFilesystem(cellRoot)).build()).setResolver(resolver).setPathResolver(pathResolver).setRuleFinder(ruleFinder).setCxxBuckConfig(cxxBuckConfig).setCxxPlatform(cxxPlatform).setPicType(CxxSourceRuleFactory.PicType.PDC).build();
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver)

Example 89 with DefaultTargetNodeToBuildRuleTransformer

use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer in project buck by facebook.

the class CxxTestDescriptionTest method platformLinkerFlagsLocationMacroWithoutMatch.

@Test
public void platformLinkerFlagsLocationMacroWithoutMatch() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    Genrule dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out").build(resolver);
    addFramework(resolver, filesystem);
    CxxTestBuilder builder = createTestBuilder().setPlatformLinkerFlags(new PatternMatchedCollection.Builder<ImmutableList<StringWithMacros>>().add(Pattern.compile("nothing matches this string"), ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(dep.getBuildTarget())))).build());
    assertThat(builder.build().getExtraDeps(), Matchers.hasItem(dep.getBuildTarget()));
    addSandbox(resolver, filesystem, builder.getTarget());
    CxxTest test = builder.build(resolver);
    CxxLink binary = (CxxLink) resolver.getRule(CxxDescriptionEnhancer.createCxxLinkTarget(test.getBuildTarget(), Optional.empty()));
    assertThat(Arg.stringify(binary.getArgs(), pathResolver), Matchers.not(Matchers.hasItem(String.format("--linker-script=%s", dep.getAbsoluteOutputFilePath(pathResolver)))));
    assertThat(binary.getDeps(), Matchers.not(Matchers.hasItem(dep)));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PatternMatchedCollection(com.facebook.buck.rules.coercer.PatternMatchedCollection) ImmutableList(com.google.common.collect.ImmutableList) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Genrule(com.facebook.buck.shell.Genrule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 90 with DefaultTargetNodeToBuildRuleTransformer

use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer in project buck by facebook.

the class CxxTestDescriptionTest method environmentIsPropagated.

@Test
public void environmentIsPropagated() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    addFramework(resolver, filesystem);
    BuildRule someRule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:some_rule")).setOut("someRule").build(resolver);
    CxxTestBuilder builder = createTestBuilder().setEnv(ImmutableMap.of("TEST", "value $(location //:some_rule)"));
    addSandbox(resolver, filesystem, builder.getTarget());
    CxxTest cxxTest = builder.build(resolver);
    TestRunningOptions options = TestRunningOptions.builder().setTestSelectorList(TestSelectorList.empty()).build();
    ImmutableList<Step> steps = cxxTest.runTests(TestExecutionContext.newInstance(), options, pathResolver, TestRule.NOOP_REPORTING_CALLBACK);
    CxxTestStep testStep = (CxxTestStep) Iterables.getLast(steps);
    assertThat(testStep.getEnv(), Matchers.equalTo(Optional.of(ImmutableMap.of("TEST", "value " + pathResolver.getAbsolutePath(Preconditions.checkNotNull(someRule.getSourcePathToOutput()))))));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TestRunningOptions(com.facebook.buck.test.TestRunningOptions) Step(com.facebook.buck.step.Step) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Aggregations

DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)579 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)578 Test (org.junit.Test)527 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)375 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)352 BuildTarget (com.facebook.buck.model.BuildTarget)257 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)238 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)211 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)204 TargetGraph (com.facebook.buck.rules.TargetGraph)182 BuildRule (com.facebook.buck.rules.BuildRule)161 Path (java.nio.file.Path)115 SourcePath (com.facebook.buck.rules.SourcePath)110 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)101 PathSourcePath (com.facebook.buck.rules.PathSourcePath)90 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)73 RuleKey (com.facebook.buck.rules.RuleKey)70 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)68 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)62 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)49