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