use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class ProjectGenerator method createMergedHeaderMap.
/**
* Generates the merged header maps and write it to the public header symlink tree location.
*/
private void createMergedHeaderMap() throws IOException {
HeaderMap.Builder headerMapBuilder = new HeaderMap.Builder();
Set<TargetNode<? extends CxxLibraryDescription.Arg, ?>> processedNodes = new HashSet<TargetNode<? extends CxxLibraryDescription.Arg, ?>>();
for (TargetNode<?, ?> targetNode : targetGraph.getAll(targetsInRequiredProjects)) {
Optional<TargetNode<CxxLibraryDescription.Arg, ?>> nativeNode = getAppleNativeNode(targetGraph, targetNode);
if (nativeNode.isPresent()) {
// Includes the public headers of the dependencies in the merged header map.
visitRecursiveHeaderSymlinkTrees(nativeNode.get(), (depNativeNode, headerVisibility) -> {
if (processedNodes.contains(depNativeNode)) {
return;
}
if (headerVisibility == HeaderVisibility.PUBLIC) {
addToMergedHeaderMap(depNativeNode, headerMapBuilder, HeaderVisibility.PUBLIC);
processedNodes.add(depNativeNode);
}
});
}
}
// Writes the resulting header map.
Path mergedHeaderMapRoot = getPathToMergedHeaderMap();
Path headerMapLocation = getHeaderMapLocationFromSymlinkTreeRoot(mergedHeaderMapRoot);
projectFilesystem.mkdirs(mergedHeaderMapRoot);
projectFilesystem.writeBytesToPath(headerMapBuilder.build().getBytes(), headerMapLocation);
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class AppleBuildRulesTest method resourceDepsOfDylibsAreNotIncludedInMainBundle.
@Test
public void resourceDepsOfDylibsAreNotIncludedInMainBundle() throws Exception {
BuildTarget sharedResourceTarget = BuildTargetFactory.newInstance("//shared:resource");
TargetNode<?, ?> sharedResourceNode = AppleResourceBuilder.createBuilder(sharedResourceTarget).build();
// no preferredLinkage, shared flavor
BuildTarget fooLibTarget = BuildTargetFactory.newInstance("//foo:lib#" + CxxDescriptionEnhancer.SHARED_FLAVOR);
TargetNode<?, ?> fooLibNode = AppleLibraryBuilder.createBuilder(fooLibTarget).setDeps(ImmutableSortedSet.of(sharedResourceTarget)).build();
// shared preferredLinkage, no flavor
BuildTarget foo2LibTarget = BuildTargetFactory.newInstance("//foo2:lib");
TargetNode<?, ?> foo2LibNode = AppleLibraryBuilder.createBuilder(foo2LibTarget).setDeps(ImmutableSortedSet.of(sharedResourceTarget)).setPreferredLinkage(NativeLinkable.Linkage.SHARED).build();
BuildTarget fooFrameworkTarget = BuildTargetFactory.newInstance("//foo:framework#default");
TargetNode<?, ?> fooFrameworkNode = AppleBundleBuilder.createBuilder(fooFrameworkTarget).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setBinary(fooLibTarget).build();
// shared preferredLinkage overriden by static flavor should still propagate dependencies.
BuildTarget staticResourceTarget = BuildTargetFactory.newInstance("//static:resource");
TargetNode<?, ?> staticResourceNode = AppleResourceBuilder.createBuilder(staticResourceTarget).build();
BuildTarget bazLibTarget = BuildTargetFactory.newInstance("//baz:lib#" + CxxDescriptionEnhancer.STATIC_FLAVOR);
TargetNode<?, ?> bazLibNode = AppleLibraryBuilder.createBuilder(bazLibTarget).setDeps(ImmutableSortedSet.of(staticResourceTarget)).setPreferredLinkage(NativeLinkable.Linkage.SHARED).build();
BuildTarget barBinaryTarget = BuildTargetFactory.newInstance("//bar:binary");
TargetNode<?, ?> barBinaryNode = AppleBinaryBuilder.createBuilder(barBinaryTarget).setDeps(ImmutableSortedSet.of(fooLibTarget, foo2LibTarget, bazLibTarget)).build();
BuildTarget barAppTarget = BuildTargetFactory.newInstance("//bar:app");
TargetNode<?, ?> barAppNode = AppleBundleBuilder.createBuilder(barAppTarget).setExtension(Either.ofLeft(AppleBundleExtension.APP)).setBinary(barBinaryTarget).setDeps(ImmutableSortedSet.of(fooFrameworkTarget)).build();
ImmutableSet<TargetNode<?, ?>> targetNodes = ImmutableSet.<TargetNode<?, ?>>builder().add(sharedResourceNode, staticResourceNode, fooLibNode, foo2LibNode, bazLibNode, fooFrameworkNode, barBinaryNode, barAppNode).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, fooFrameworkNode, Optional.of(APPLE_RESOURCE_DESCRIPTION_CLASSES));
assertEquals(ImmutableSortedSet.of(sharedResourceNode), ImmutableSortedSet.copyOf(rules));
rules = AppleBuildRules.getRecursiveTargetNodeDependenciesOfTypes(targetGraph, cache, AppleBuildRules.RecursiveDependenciesMode.COPYING, barAppNode, Optional.of(APPLE_RESOURCE_DESCRIPTION_CLASSES));
assertEquals(ImmutableSortedSet.of(staticResourceNode), ImmutableSortedSet.copyOf(rules));
}
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class AppleBuildRulesTest method exportedDepsOfDylibsAreCollectedForLinking.
@Test
public void exportedDepsOfDylibsAreCollectedForLinking() 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 rootTarget = BuildTargetFactory.newInstance("//foo:root");
TargetNode<?, ?> rootNode = AppleLibraryBuilder.createBuilder(rootTarget).setDeps(ImmutableSortedSet.of(barFrameworkTarget)).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(ImmutableSet.of(rootNode, fooLibNode, fooFrameworkNode, barLibNode, barFrameworkNode));
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.LINKING, rootNode, Optional.empty());
assertEquals(ImmutableSortedSet.of(barFrameworkNode, fooFrameworkNode), ImmutableSortedSet.copyOf(rules));
}
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class AppleBuildRulesTest method buildingStopsAtGenruleDepButNotAtBundleDep.
@Test
public void buildingStopsAtGenruleDepButNotAtBundleDep() throws Exception {
// Pass a random static lib in a genrule and make sure a framework
// depending on the genrule doesn't build the dependencies of that genrule.
BuildTarget fooLibTarget = BuildTargetFactory.newInstance("//foo:lib");
TargetNode<?, ?> fooLibNode = AppleLibraryBuilder.createBuilder(fooLibTarget).build();
BuildTarget fooGenruleTarget = BuildTargetFactory.newInstance("//foo:genrule");
TargetNode<?, ?> fooGenruleNode = GenruleBuilder.newGenruleBuilder(fooGenruleTarget).setOut("foo").setCmd("echo hi > $OUT").setSrcs(ImmutableList.of(new DefaultBuildTargetSourcePath(fooLibTarget))).build();
BuildTarget barLibTarget = BuildTargetFactory.newInstance("//bar:lib#" + CxxDescriptionEnhancer.SHARED_FLAVOR);
TargetNode<?, ?> barLibNode = AppleLibraryBuilder.createBuilder(barLibTarget).setDeps(ImmutableSortedSet.of(fooGenruleTarget)).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, fooGenruleNode, 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.BUILDING, bazFrameworkNode, Optional.empty());
assertEquals(ImmutableSortedSet.of(barFrameworkNode, fooGenruleNode), ImmutableSortedSet.copyOf(rules));
}
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class AppleBuildRulesTest method testDependenciesCache.
@Test
public void testDependenciesCache() 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));
AppleDependenciesCache cache = new AppleDependenciesCache(targetGraph);
ImmutableSortedSet<TargetNode<?, ?>> cachedDefaultDeps = cache.getDefaultDeps(rootNode);
ImmutableSortedSet<TargetNode<?, ?>> cachedExportedDeps = cache.getExportedDeps(rootNode);
assertEquals(cachedDefaultDeps, ImmutableSortedSet.of(bundleNode, libraryNode));
assertEquals(cachedExportedDeps, ImmutableSortedSet.of());
ImmutableSortedSet<TargetNode<?, ?>> defaultDeps = cache.getDefaultDeps(rootNode);
ImmutableSortedSet<TargetNode<?, ?>> exportedDeps = cache.getExportedDeps(rootNode);
assertSame(cachedDefaultDeps, defaultDeps);
assertSame(cachedExportedDeps, exportedDeps);
}
Aggregations