Search in sources :

Example 16 with CxxLibraryBuilder

use of com.facebook.buck.cxx.CxxLibraryBuilder in project buck by facebook.

the class PythonBinaryDescriptionTest method explicitDepOnlinkWholeLibPullsInSharedLibrary.

@Test
public void explicitDepOnlinkWholeLibPullsInSharedLibrary() throws Exception {
    for (final NativeLinkStrategy strategy : NativeLinkStrategy.values()) {
        ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
        CxxLibraryBuilder cxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep1")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("test.c")))).setForceStatic(true);
        PrebuiltCxxLibraryBuilder prebuiltCxxLibraryBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep2")).setForceStatic(true);
        PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().build(), new AlwaysFoundExecutableFinder()) {

            @Override
            public NativeLinkStrategy getNativeLinkStrategy() {
                return strategy;
            }
        };
        PythonBinaryBuilder binaryBuilder = new PythonBinaryBuilder(BuildTargetFactory.newInstance("//:bin"), config, PythonTestUtils.PYTHON_PLATFORMS, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS);
        binaryBuilder.setMainModule("main");
        binaryBuilder.setDeps(ImmutableSortedSet.of(cxxLibraryBuilder.getTarget(), prebuiltCxxLibraryBuilder.getTarget()));
        TargetGraph targetGraph = TargetGraphFactory.newInstance(cxxLibraryBuilder.build(), prebuiltCxxLibraryBuilder.build(), binaryBuilder.build());
        BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
        cxxLibraryBuilder.build(resolver, filesystem, targetGraph);
        prebuiltCxxLibraryBuilder.build(resolver, filesystem, targetGraph);
        PythonBinary binary = binaryBuilder.build(resolver, filesystem, targetGraph);
        assertThat("Using " + strategy, binary.getComponents().getNativeLibraries().keySet(), Matchers.hasItems(Paths.get("libdep1.so"), Paths.get("libdep2.so")));
    }
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) NativeLinkStrategy(com.facebook.buck.cxx.NativeLinkStrategy) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 17 with CxxLibraryBuilder

use of com.facebook.buck.cxx.CxxLibraryBuilder in project buck by facebook.

the class PythonBinaryDescriptionTest method transitiveNativeDepsUsingSeparateNativeLinkStrategy.

@Test
public void transitiveNativeDepsUsingSeparateNativeLinkStrategy() throws Exception {
    CxxLibraryBuilder transitiveCxxDepBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:transitive_dep")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("transitive_dep.c"))));
    CxxLibraryBuilder cxxDepBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("dep.c")))).setDeps(ImmutableSortedSet.of(transitiveCxxDepBuilder.getTarget()));
    CxxLibraryBuilder cxxBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:cxx")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("cxx.c")))).setDeps(ImmutableSortedSet.of(cxxDepBuilder.getTarget()));
    PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().build(), new AlwaysFoundExecutableFinder()) {

        @Override
        public NativeLinkStrategy getNativeLinkStrategy() {
            return NativeLinkStrategy.SEPARATE;
        }
    };
    PythonBinaryBuilder binaryBuilder = new PythonBinaryBuilder(BuildTargetFactory.newInstance("//:bin"), config, PythonTestUtils.PYTHON_PLATFORMS, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS);
    binaryBuilder.setMainModule("main");
    binaryBuilder.setDeps(ImmutableSortedSet.of(cxxBuilder.getTarget()));
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(transitiveCxxDepBuilder.build(), cxxDepBuilder.build(), cxxBuilder.build(), binaryBuilder.build()), new DefaultTargetNodeToBuildRuleTransformer());
    transitiveCxxDepBuilder.build(resolver);
    cxxDepBuilder.build(resolver);
    cxxBuilder.build(resolver);
    PythonBinary binary = binaryBuilder.build(resolver);
    assertThat(Iterables.transform(binary.getComponents().getNativeLibraries().keySet(), Object::toString), Matchers.containsInAnyOrder("libtransitive_dep.so", "libdep.so", "libcxx.so"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Example 18 with CxxLibraryBuilder

use of com.facebook.buck.cxx.CxxLibraryBuilder in project buck by facebook.

the class PythonBinaryDescriptionTest method transitiveDepsOfPreloadDepsAreExcludedFromMergedNativeLinkStrategy.

@Test
public void transitiveDepsOfPreloadDepsAreExcludedFromMergedNativeLinkStrategy() throws Exception {
    CxxLibraryBuilder transitiveCxxDepBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:transitive_dep")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("transitive_dep.c"))));
    CxxLibraryBuilder cxxDepBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("dep.c")))).setDeps(ImmutableSortedSet.of(transitiveCxxDepBuilder.getTarget()));
    CxxLibraryBuilder cxxBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:cxx")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("cxx.c")))).setDeps(ImmutableSortedSet.of(cxxDepBuilder.getTarget()));
    CxxLibraryBuilder preloadCxxBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:preload_cxx")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("preload_cxx.c")))).setDeps(ImmutableSortedSet.of(transitiveCxxDepBuilder.getTarget()));
    PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().build(), new AlwaysFoundExecutableFinder()) {

        @Override
        public NativeLinkStrategy getNativeLinkStrategy() {
            return NativeLinkStrategy.MERGED;
        }
    };
    PythonBinaryBuilder binaryBuilder = new PythonBinaryBuilder(BuildTargetFactory.newInstance("//:bin"), config, PythonTestUtils.PYTHON_PLATFORMS, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS);
    binaryBuilder.setMainModule("main");
    binaryBuilder.setDeps(ImmutableSortedSet.of(cxxBuilder.getTarget()));
    binaryBuilder.setPreloadDeps(ImmutableSet.of(preloadCxxBuilder.getTarget()));
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(transitiveCxxDepBuilder.build(), cxxDepBuilder.build(), cxxBuilder.build(), preloadCxxBuilder.build(), binaryBuilder.build()), new DefaultTargetNodeToBuildRuleTransformer());
    transitiveCxxDepBuilder.build(resolver);
    cxxDepBuilder.build(resolver);
    cxxBuilder.build(resolver);
    preloadCxxBuilder.build(resolver);
    PythonBinary binary = binaryBuilder.build(resolver);
    assertThat(Iterables.transform(binary.getComponents().getNativeLibraries().keySet(), Object::toString), Matchers.containsInAnyOrder("libomnibus.so", "libcxx.so", "libpreload_cxx.so", "libtransitive_dep.so"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Example 19 with CxxLibraryBuilder

use of com.facebook.buck.cxx.CxxLibraryBuilder in project buck by facebook.

the class CxxPythonExtensionDescriptionTest method platformDepsSeparateLinkage.

@Test
public void platformDepsSeparateLinkage() throws Exception {
    PythonBuckConfig pythonBuckConfig = new PythonBuckConfig(FakeBuckConfig.builder().build(), new ExecutableFinder());
    FlavorDomain<PythonPlatform> pythonPlatforms = FlavorDomain.of("Python Platform", PY2, PY3);
    CxxLibraryBuilder depBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("test.c"))));
    CxxPythonExtensionBuilder extensionBuilder = new CxxPythonExtensionBuilder(BuildTargetFactory.newInstance("//:rule"), pythonPlatforms, new CxxBuckConfig(FakeBuckConfig.builder().build()), CxxTestBuilder.createDefaultPlatforms()).setPlatformDeps(PatternMatchedCollection.<ImmutableSortedSet<BuildTarget>>builder().add(Pattern.compile(PY2.getFlavor().toString()), ImmutableSortedSet.of(depBuilder.getTarget())).build());
    PythonBinaryBuilder binary2Builder = new PythonBinaryBuilder(BuildTargetFactory.newInstance("//:bin2"), pythonBuckConfig, pythonPlatforms, CxxTestBuilder.createDefaultPlatform(), CxxTestBuilder.createDefaultPlatforms()).setMainModule("test").setPlatform(PY2.getFlavor().toString()).setDeps(ImmutableSortedSet.of(extensionBuilder.getTarget()));
    PythonBinaryBuilder binary3Builder = new PythonBinaryBuilder(BuildTargetFactory.newInstance("//:bin3"), pythonBuckConfig, pythonPlatforms, CxxTestBuilder.createDefaultPlatform(), CxxTestBuilder.createDefaultPlatforms()).setMainModule("test").setPlatform(PY3.getFlavor().toString()).setDeps(ImmutableSortedSet.of(extensionBuilder.getTarget()));
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(depBuilder.build(), extensionBuilder.build(), binary2Builder.build()), new DefaultTargetNodeToBuildRuleTransformer());
    depBuilder.build(resolver);
    extensionBuilder.build(resolver);
    PythonBinary binary2 = binary2Builder.build(resolver);
    PythonBinary binary3 = binary3Builder.build(resolver);
    assertThat(binary2.getComponents().getNativeLibraries().keySet(), Matchers.contains(Paths.get("libdep.so")));
    assertThat(binary3.getComponents().getNativeLibraries().keySet(), Matchers.not(Matchers.contains(Paths.get("libdep.so"))));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 20 with CxxLibraryBuilder

use of com.facebook.buck.cxx.CxxLibraryBuilder in project buck by facebook.

the class ProjectGeneratorTest method testCxxLibraryHeaderGroupsWithMapsOfHeaders.

@Test
public void testCxxLibraryHeaderGroupsWithMapsOfHeaders() throws IOException {
    BuildTarget privateGeneratedTarget = BuildTarget.builder(rootPath, "//foo", "generated1.h").build();
    BuildTarget publicGeneratedTarget = BuildTarget.builder(rootPath, "//foo", "generated2.h").build();
    TargetNode<?, ?> privateGeneratedNode = ExportFileBuilder.newExportFileBuilder(privateGeneratedTarget).build();
    TargetNode<?, ?> publicGeneratedNode = ExportFileBuilder.newExportFileBuilder(publicGeneratedTarget).build();
    BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> node = new CxxLibraryBuilder(buildTarget).setExportedHeaders(ImmutableSortedMap.of("yet/another/name.h", new FakeSourcePath("foo/dir1/bar.h"), "and/one/more.h", new DefaultBuildTargetSourcePath(publicGeneratedTarget))).setHeaders(ImmutableSortedMap.of("any/name.h", new FakeSourcePath("foo/dir1/foo.h"), "different/name.h", new FakeSourcePath("foo/dir2/baz.h"), "one/more/name.h", new DefaultBuildTargetSourcePath(privateGeneratedTarget))).setSrcs(ImmutableSortedSet.of()).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node, privateGeneratedNode, publicGeneratedNode));
    projectGenerator.createXcodeProjects();
    List<Path> headerSymlinkTrees = projectGenerator.getGeneratedHeaderSymlinkTrees();
    assertThat(headerSymlinkTrees, hasSize(2));
    assertThat(headerSymlinkTrees.get(0).toString(), is(equalTo("buck-out/gen/_p/CwkbTNOBmb-pub")));
    assertThatHeaderSymlinkTreeContains(Paths.get("buck-out/gen/_p/CwkbTNOBmb-pub"), ImmutableMap.of("foo/yet/another/name.h", "foo/dir1/bar.h", "foo/and/one/more.h", "foo/generated2.h"));
    assertThat(headerSymlinkTrees.get(1).toString(), is(equalTo("buck-out/gen/_p/CwkbTNOBmb-priv")));
    assertThatHeaderSymlinkTreeContains(Paths.get("buck-out/gen/_p/CwkbTNOBmb-priv"), ImmutableMap.of("foo/any/name.h", "foo/dir1/foo.h", "foo/different/name.h", "foo/dir2/baz.h", "foo/one/more/name.h", "foo/generated1.h"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) Test(org.junit.Test)

Aggregations

CxxLibraryBuilder (com.facebook.buck.cxx.CxxLibraryBuilder)33 Test (org.junit.Test)33 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)23 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)18 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)18 PrebuiltCxxLibraryBuilder (com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder)17 BuildTarget (com.facebook.buck.model.BuildTarget)17 NSString (com.dd.plist.NSString)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 SourcePath (com.facebook.buck.rules.SourcePath)8 AlwaysFoundExecutableFinder (com.facebook.buck.io.AlwaysFoundExecutableFinder)7 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)7 Path (java.nio.file.Path)7 PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)6 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)6 CxxBuckConfig (com.facebook.buck.cxx.CxxBuckConfig)6 PathSourcePath (com.facebook.buck.rules.PathSourcePath)6 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)6 TargetGraph (com.facebook.buck.rules.TargetGraph)5 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)5