use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer in project buck by facebook.
the class ApplePackageDescriptionTest method descriptionExpandsLocationMacrosAndTracksDependencies.
@Test
public void descriptionExpandsLocationMacrosAndTracksDependencies() throws Exception {
ApplePackageDescription description = descriptionWithCommand("echo $(location :exportfile)");
BuildTarget binaryBuildTarget = BuildTargetFactory.newInstance("//foo:binary");
BuildTarget bundleBuildTarget = BuildTargetFactory.newInstance("//foo:bundle");
BuildTarget exportFileBuildTarget = BuildTargetFactory.newInstance("//foo:exportfile");
TargetGraph graph = TargetGraphFactory.newInstance(ExportFileBuilder.newExportFileBuilder(exportFileBuildTarget).build(), AppleBinaryBuilder.createBuilder(binaryBuildTarget).build(), AppleBundleBuilder.createBuilder(bundleBuildTarget).setBinary(binaryBuildTarget).setExtension(Either.ofLeft(AppleBundleExtension.APP)).build());
ApplePackageDescription.Arg arg = description.createUnpopulatedConstructorArg();
arg.bundle = bundleBuildTarget;
BuildTarget packageBuildTarget = BuildTargetFactory.newInstance("//foo:package#macosx-x86_64");
BuildRuleResolver resolver = new BuildRuleResolver(graph, new DefaultTargetNodeToBuildRuleTransformer());
BuildRuleParams params = new FakeBuildRuleParamsBuilder(packageBuildTarget).build();
resolver.requireAllRules(description.findDepsForTargetFromConstructorArgs(packageBuildTarget, params.getCellRoots(), arg));
BuildRule rule = description.createBuildRule(graph, params, resolver, arg);
assertThat(rule.getDeps(), hasItem(resolver.getRule(exportFileBuildTarget)));
}
use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer in project buck by facebook.
the class ApplePackageDescriptionTest method descriptionCreatesExternallyBuiltPackageRuleIfConfigExists.
@Test
public void descriptionCreatesExternallyBuiltPackageRuleIfConfigExists() throws Exception {
ApplePackageDescription description = descriptionWithCommand("echo");
BuildTarget binaryBuildTarget = BuildTargetFactory.newInstance("//foo:binary");
BuildTarget bundleBuildTarget = BuildTargetFactory.newInstance("//foo:bundle");
TargetGraph graph = TargetGraphFactory.newInstance(AppleBinaryBuilder.createBuilder(binaryBuildTarget).build(), AppleBundleBuilder.createBuilder(bundleBuildTarget).setBinary(binaryBuildTarget).setExtension(Either.ofLeft(AppleBundleExtension.APP)).build());
ApplePackageDescription.Arg arg = description.createUnpopulatedConstructorArg();
arg.bundle = bundleBuildTarget;
BuildTarget packageBuildTarget = BuildTargetFactory.newInstance("//foo:package#macosx-x86_64");
BuildRuleResolver resolver = new BuildRuleResolver(graph, new DefaultTargetNodeToBuildRuleTransformer());
BuildRuleParams params = new FakeBuildRuleParamsBuilder(packageBuildTarget).build();
resolver.requireAllRules(description.findDepsForTargetFromConstructorArgs(packageBuildTarget, params.getCellRoots(), arg));
BuildRule rule = description.createBuildRule(graph, new FakeBuildRuleParamsBuilder(packageBuildTarget).build(), resolver, arg);
assertThat(rule, instanceOf(ExternallyBuiltApplePackage.class));
assertThat(rule.getDeps(), hasItem(resolver.getRule(bundleBuildTarget.withFlavors(InternalFlavor.of("macosx-x86_64")))));
}
use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer in project buck by facebook.
the class AppleDescriptionsTest method parseAppleHeadersForUseFromTheSameTargetFromMap.
@Test
public void parseAppleHeadersForUseFromTheSameTargetFromMap() {
ImmutableSortedMap<String, SourcePath> headerMap = ImmutableSortedMap.of("virtual/path.h", new FakeSourcePath("path/to/some_file.h"), "another/path.h", new FakeSourcePath("path/to/another_file.h"), "another/file.h", new FakeSourcePath("different/path/to/a_file.h"), "file.h", new FakeSourcePath("file.h"));
SourcePathResolver resolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
assertEquals(ImmutableMap.of(), AppleDescriptions.parseAppleHeadersForUseFromTheSameTarget(resolver::getRelativePath, SourceList.ofNamedSources(headerMap)));
}
use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer in project buck by facebook.
the class ProjectGeneratorTest method getBuildRuleResolverNodeFunction.
private Function<TargetNode<?, ?>, BuildRuleResolver> getBuildRuleResolverNodeFunction(final TargetGraph targetGraph) {
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
AbstractBottomUpTraversal<TargetNode<?, ?>, RuntimeException> bottomUpTraversal = new AbstractBottomUpTraversal<TargetNode<?, ?>, RuntimeException>(targetGraph) {
@Override
@SuppressWarnings("PMD.EmptyCatchBlock")
public void visit(TargetNode<?, ?> node) {
try {
resolver.requireRule(node.getBuildTarget());
} catch (Exception e) {
// NOTE(agallagher): A large number of the tests appear to setup their target nodes
// incorrectly, causing action graph creation to fail with lots of missing expected
// Apple C/C++ platform flavors. This is gross, but to support tests that need a
// complete sub-action graph, just skip over the errors.
}
}
};
bottomUpTraversal.traverse();
return input -> resolver;
}
use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer in project buck by facebook.
the class RuleUtilsTest method creatingGroupsFromEntryMapsKeepsLongestCommonPrefix.
@Test
public void creatingGroupsFromEntryMapsKeepsLongestCommonPrefix() {
ImmutableMultimap<Path, String> subgroups = ImmutableMultimap.<Path, String>builder().put(Paths.get("root"), "Lib").put(Paths.get("root/Lib"), "Bar").put(Paths.get("root/Lib"), "Foo").build();
ImmutableMultimap<Path, GroupedSource> entries = ImmutableMultimap.<Path, GroupedSource>builder().put(Paths.get("root/Lib/Foo"), GroupedSource.ofPrivateHeader(new FakeSourcePath("Lib/Foo/File2.h"))).put(Paths.get("root/Lib/Bar"), GroupedSource.ofPrivateHeader(new FakeSourcePath("Lib/Bar/File1.h"))).put(Paths.get("root/Lib/Foo"), GroupedSource.ofPrivateHeader(new FakeSourcePath("Lib/Foo/File1.h"))).build();
ImmutableList<GroupedSource> expected = ImmutableList.of(GroupedSource.ofSourceGroup("Lib", Paths.get("Lib"), ImmutableList.of(GroupedSource.ofSourceGroup("Bar", Paths.get("Lib/Bar"), ImmutableList.of(GroupedSource.ofPrivateHeader(new FakeSourcePath("Lib/Bar/File1.h")))), GroupedSource.ofSourceGroup("Foo", Paths.get("Lib/Foo"), ImmutableList.of(GroupedSource.ofPrivateHeader(new FakeSourcePath("Lib/Foo/File1.h")), GroupedSource.ofPrivateHeader(new FakeSourcePath("Lib/Foo/File2.h")))))));
SourcePathResolver resolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
ImmutableList<GroupedSource> actual = RuleUtils.createGroupsFromEntryMaps(subgroups, entries, new RuleUtils.GroupedSourceNameComparator(resolver::getRelativePath), Paths.get("root"), Paths.get("root"));
assertEquals(expected, actual);
}
Aggregations