Search in sources :

Example 76 with TargetNode

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);
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) TargetNode(com.facebook.buck.rules.TargetNode) HeaderMap(com.facebook.buck.apple.clang.HeaderMap) CxxLibraryDescription(com.facebook.buck.cxx.CxxLibraryDescription) CacheBuilder(com.google.common.cache.CacheBuilder) AppleNativeTargetDescriptionArg(com.facebook.buck.apple.AppleNativeTargetDescriptionArg) StringWithMacrosArg(com.facebook.buck.rules.args.StringWithMacrosArg) AppleWrapperResourceArg(com.facebook.buck.apple.AppleWrapperResourceArg) HashSet(java.util.HashSet)

Example 77 with TargetNode

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));
    }
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) TargetGraph(com.facebook.buck.rules.TargetGraph) Test(org.junit.Test)

Example 78 with TargetNode

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));
    }
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) TargetGraph(com.facebook.buck.rules.TargetGraph) Test(org.junit.Test)

Example 79 with TargetNode

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));
    }
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) Test(org.junit.Test)

Example 80 with TargetNode

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);
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) TargetGraph(com.facebook.buck.rules.TargetGraph) Test(org.junit.Test)

Aggregations

TargetNode (com.facebook.buck.rules.TargetNode)88 BuildTarget (com.facebook.buck.model.BuildTarget)73 TargetGraph (com.facebook.buck.rules.TargetGraph)43 Test (org.junit.Test)40 Path (java.nio.file.Path)36 ImmutableSet (com.google.common.collect.ImmutableSet)33 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)23 PathSourcePath (com.facebook.buck.rules.PathSourcePath)22 SourcePath (com.facebook.buck.rules.SourcePath)22 ImmutableMap (com.google.common.collect.ImmutableMap)22 Optional (java.util.Optional)20 Map (java.util.Map)18 HumanReadableException (com.facebook.buck.util.HumanReadableException)17 ImmutableList (com.google.common.collect.ImmutableList)17 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)13 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)13 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)13 Cell (com.facebook.buck.rules.Cell)13 IOException (java.io.IOException)13 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)12