use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class AppleBuildRulesTest method testRecursiveTargetsIncludesBundleBinaryFromOutsideBundle.
@Test
public void testRecursiveTargetsIncludesBundleBinaryFromOutsideBundle() throws Exception {
BuildTarget libraryTarget = BuildTargetFactory.newInstance("//foo:lib");
TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).build();
BuildTarget bundleTarget = BuildTargetFactory.newInstance("//foo:bundle");
TargetNode<?, ?> bundleNode = AppleBundleBuilder.createBuilder(bundleTarget).setExtension(Either.ofLeft(AppleBundleExtension.XCTEST)).setBinary(libraryTarget).build();
BuildTarget rootTarget = BuildTargetFactory.newInstance("//foo:root");
TargetNode<?, ?> rootNode = AppleLibraryBuilder.createBuilder(rootTarget).setDeps(ImmutableSortedSet.of(libraryTarget, bundleTarget)).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(ImmutableSet.of(libraryNode, bundleNode, rootNode));
Optional<AppleDependenciesCache> cache = useCache ? Optional.of(new AppleDependenciesCache(targetGraph)) : Optional.empty();
for (int i = 0; i < (useCache ? 2 : 1); i++) {
Iterable<TargetNode<?, ?>> rules = AppleBuildRules.getRecursiveTargetNodeDependenciesOfTypes(targetGraph, cache, AppleBuildRules.RecursiveDependenciesMode.BUILDING, rootNode, Optional.empty());
assertTrue(Iterables.elementsEqual(ImmutableSortedSet.of(libraryNode, bundleNode), rules));
}
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class AppleBuildRulesTest method exportedDepsAreCollectedForCopying.
@Test
public void exportedDepsAreCollectedForCopying() throws Exception {
BuildTarget fooLibTarget = BuildTargetFactory.newInstance("//foo:lib#" + CxxDescriptionEnhancer.SHARED_FLAVOR);
TargetNode<?, ?> fooLibNode = AppleLibraryBuilder.createBuilder(fooLibTarget).build();
BuildTarget fooFrameworkTarget = BuildTargetFactory.newInstance("//foo:framework");
TargetNode<?, ?> fooFrameworkNode = AppleBundleBuilder.createBuilder(fooFrameworkTarget).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setBinary(fooLibTarget).build();
BuildTarget barLibTarget = BuildTargetFactory.newInstance("//bar:lib#" + CxxDescriptionEnhancer.SHARED_FLAVOR);
TargetNode<?, ?> barLibNode = AppleLibraryBuilder.createBuilder(barLibTarget).setDeps(ImmutableSortedSet.of(fooFrameworkTarget)).setExportedDeps(ImmutableSortedSet.of(fooFrameworkTarget)).build();
BuildTarget barFrameworkTarget = BuildTargetFactory.newInstance("//bar:framework");
TargetNode<?, ?> barFrameworkNode = AppleBundleBuilder.createBuilder(barFrameworkTarget).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setBinary(barLibTarget).build();
BuildTarget bazLibTarget = BuildTargetFactory.newInstance("//baz:lib#" + CxxDescriptionEnhancer.SHARED_FLAVOR);
TargetNode<?, ?> bazLibNode = AppleLibraryBuilder.createBuilder(bazLibTarget).setDeps(ImmutableSortedSet.of(barFrameworkTarget)).build();
BuildTarget bazFrameworkTarget = BuildTargetFactory.newInstance("//baz:framework");
TargetNode<?, ?> bazFrameworkNode = AppleBundleBuilder.createBuilder(bazFrameworkTarget).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setBinary(bazLibTarget).build();
ImmutableSet<TargetNode<?, ?>> targetNodes = ImmutableSet.<TargetNode<?, ?>>builder().add(fooLibNode, fooFrameworkNode, barLibNode, barFrameworkNode, bazLibNode, bazFrameworkNode).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(targetNodes);
Optional<AppleDependenciesCache> cache = useCache ? Optional.of(new AppleDependenciesCache(targetGraph)) : Optional.empty();
for (int i = 0; i < (useCache ? 2 : 1); i++) {
Iterable<TargetNode<?, ?>> rules = AppleBuildRules.getRecursiveTargetNodeDependenciesOfTypes(targetGraph, cache, AppleBuildRules.RecursiveDependenciesMode.COPYING, bazFrameworkNode, Optional.empty());
assertEquals(ImmutableSortedSet.of(barFrameworkNode, fooFrameworkNode), ImmutableSortedSet.copyOf(rules));
}
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class RobolectricTestRuleTest method runtimeDepsIncludeTransitiveResources.
@Test
public void runtimeDepsIncludeTransitiveResources() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem(temporaryFolder.getRoot());
BuildTarget genRuleTarget = BuildTargetFactory.newInstance("//:gen");
TargetNode<?, ?> genRuleNode = GenruleBuilder.newGenruleBuilder(genRuleTarget).setOut("out").build();
BuildTarget res2RuleTarget = BuildTargetFactory.newInstance("//:res2");
TargetNode<?, ?> res2Node = AndroidResourceBuilder.createBuilder(res2RuleTarget).setRes(new DefaultBuildTargetSourcePath(genRuleTarget)).setRDotJavaPackage("foo.bar").build();
BuildTarget robolectricBuildTarget = BuildTargetFactory.newInstance("//java/src/com/facebook/base/robolectricTest:robolectricTest");
TargetNode<?, ?> robolectricTestNode = RobolectricTestBuilder.createBuilder(robolectricBuildTarget, filesystem).addDep(res2RuleTarget).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(genRuleNode, res2Node, robolectricTestNode);
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
BuildRule genRule = resolver.requireRule(genRuleTarget);
RobolectricTest robolectricTest = (RobolectricTest) resolver.requireRule(robolectricBuildTarget);
assertThat(robolectricTest.getRuntimeDeps().collect(MoreCollectors.toImmutableSet()), Matchers.hasItem(genRule.getBuildTarget()));
}
use of com.facebook.buck.rules.TargetGraph 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.TargetGraph 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")))));
}
Aggregations