Search in sources :

Example 1 with PrebuiltCxxLibraryBuilder

use of com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder 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 2 with PrebuiltCxxLibraryBuilder

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

the class LuaBinaryDescriptionTest method pythonExtensionDepUsingMergedNativeLinkStrategy.

@Test
public void pythonExtensionDepUsingMergedNativeLinkStrategy() throws Exception {
    FlavorDomain<PythonPlatform> pythonPlatforms = FlavorDomain.of("Python Platform", PY2);
    PrebuiltCxxLibraryBuilder python2Builder = new PrebuiltCxxLibraryBuilder(PYTHON2_DEP_TARGET).setProvided(true).setExportedLinkerFlags(ImmutableList.of("-lpython2"));
    CxxPythonExtensionBuilder extensionBuilder = new CxxPythonExtensionBuilder(BuildTargetFactory.newInstance("//:extension"), pythonPlatforms, new CxxBuckConfig(FakeBuckConfig.builder().build()), CxxPlatformUtils.DEFAULT_PLATFORMS);
    extensionBuilder.setBaseModule("hello");
    LuaBinaryBuilder binaryBuilder = new LuaBinaryBuilder(BuildTargetFactory.newInstance("//:bin"), FakeLuaConfig.DEFAULT.withNativeLinkStrategy(NativeLinkStrategy.MERGED), CxxPlatformUtils.DEFAULT_CONFIG, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS, pythonPlatforms);
    binaryBuilder.setMainModule("main");
    binaryBuilder.setDeps(ImmutableSortedSet.of(extensionBuilder.getTarget()));
    TargetGraph targetGraph = TargetGraphFactory.newInstance(python2Builder.build(), extensionBuilder.build(), binaryBuilder.build());
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    python2Builder.build(resolver, filesystem, targetGraph);
    extensionBuilder.build(resolver, filesystem, targetGraph);
    LuaBinary binary = binaryBuilder.build(resolver, filesystem, targetGraph);
    assertThat(binary.getComponents().getNativeLibraries().entrySet(), Matchers.empty());
    assertThat(Iterables.transform(binary.getComponents().getPythonModules().keySet(), Object::toString), Matchers.hasItem(MorePaths.pathWithPlatformSeparators("hello/extension.so")));
}
Also used : PythonPlatform(com.facebook.buck.python.PythonPlatform) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) CxxPythonExtensionBuilder(com.facebook.buck.python.CxxPythonExtensionBuilder) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 3 with PrebuiltCxxLibraryBuilder

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

the class CxxPythonExtensionDescriptionTest method py2AndPy3PropagateToLinkRules.

@Test
public void py2AndPy3PropagateToLinkRules() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    PrebuiltCxxLibraryBuilder python2Builder = new PrebuiltCxxLibraryBuilder(PYTHON2_DEP_TARGET).setHeaderOnly(true).setExportedLinkerFlags(ImmutableList.of("-lpython2"));
    PrebuiltCxxLibraryBuilder python3Builder = new PrebuiltCxxLibraryBuilder(PYTHON3_DEP_TARGET).setHeaderOnly(true).setExportedLinkerFlags(ImmutableList.of("-lpython3"));
    PythonPlatform py2 = PY2.withCxxLibrary(PYTHON2_DEP_TARGET);
    PythonPlatform py3 = PY3.withCxxLibrary(PYTHON3_DEP_TARGET);
    BuildTarget target = BuildTargetFactory.newInstance("//:target");
    CxxPythonExtensionBuilder builder = new CxxPythonExtensionBuilder(target, FlavorDomain.of("Python Platform", py2, py3), new CxxBuckConfig(FakeBuckConfig.builder().build()), CxxTestBuilder.createDefaultPlatforms());
    TargetGraph targetGraph = TargetGraphFactory.newInstance(python2Builder.build(), python3Builder.build(), builder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    python2Builder.build(resolver, filesystem, targetGraph);
    python3Builder.build(resolver, filesystem, targetGraph);
    CxxPythonExtension extension = builder.build(resolver, filesystem, targetGraph);
    // Get the py2 extension, and verify it pulled in the py2 lib but not the py3 lib.
    CxxLink py2Ext = (CxxLink) extension.getExtension(py2, CxxPlatformUtils.DEFAULT_PLATFORM);
    assertThat(Arg.stringify(py2Ext.getArgs(), pathResolver), Matchers.allOf(Matchers.hasItem("-lpython2"), Matchers.not(Matchers.hasItem("-lpython3"))));
    // Get the py3 extension, and verify it pulled in the py3 lib but not the py2 lib.
    CxxLink py3Ext = (CxxLink) extension.getExtension(py3, CxxPlatformUtils.DEFAULT_PLATFORM);
    assertThat(Arg.stringify(py3Ext.getArgs(), pathResolver), Matchers.allOf(Matchers.hasItem("-lpython3"), Matchers.not(Matchers.hasItem("-lpython2"))));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) CxxLink(com.facebook.buck.cxx.CxxLink) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 4 with PrebuiltCxxLibraryBuilder

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

the class PythonBinaryDescriptionTest method extensionDepUsingMergedNativeLinkStrategy.

@Test
public void extensionDepUsingMergedNativeLinkStrategy() throws Exception {
    FlavorDomain<PythonPlatform> pythonPlatforms = FlavorDomain.of("Python Platform", PY2);
    PrebuiltCxxLibraryBuilder python2Builder = new PrebuiltCxxLibraryBuilder(PYTHON2_DEP_TARGET).setProvided(true).setExportedLinkerFlags(ImmutableList.of("-lpython2"));
    CxxPythonExtensionBuilder extensionBuilder = new CxxPythonExtensionBuilder(BuildTargetFactory.newInstance("//:extension"), pythonPlatforms, new CxxBuckConfig(FakeBuckConfig.builder().build()), CxxPlatformUtils.DEFAULT_PLATFORMS);
    extensionBuilder.setBaseModule("hello");
    PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().build(), new AlwaysFoundExecutableFinder()) {

        @Override
        public NativeLinkStrategy getNativeLinkStrategy() {
            return NativeLinkStrategy.MERGED;
        }
    };
    PythonBinaryBuilder binaryBuilder = new PythonBinaryBuilder(BuildTargetFactory.newInstance("//:bin"), config, pythonPlatforms, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS);
    binaryBuilder.setMainModule("main");
    binaryBuilder.setDeps(ImmutableSortedSet.of(extensionBuilder.getTarget()));
    TargetGraph targetGraph = TargetGraphFactory.newInstance(python2Builder.build(), extensionBuilder.build(), binaryBuilder.build());
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    python2Builder.build(resolver, filesystem, targetGraph);
    extensionBuilder.build(resolver, filesystem, targetGraph);
    PythonBinary binary = binaryBuilder.build(resolver, filesystem, targetGraph);
    assertThat(binary.getComponents().getNativeLibraries().entrySet(), Matchers.empty());
    assertThat(Iterables.transform(binary.getComponents().getModules().keySet(), Object::toString), Matchers.containsInAnyOrder(MorePaths.pathWithPlatformSeparators("hello/extension.so")));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) 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)

Aggregations

PrebuiltCxxLibraryBuilder (com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder)4 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)4 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)4 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)4 TargetGraph (com.facebook.buck.rules.TargetGraph)4 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)4 Test (org.junit.Test)4 CxxBuckConfig (com.facebook.buck.cxx.CxxBuckConfig)3 AlwaysFoundExecutableFinder (com.facebook.buck.io.AlwaysFoundExecutableFinder)2 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)2 CxxLibraryBuilder (com.facebook.buck.cxx.CxxLibraryBuilder)1 CxxLink (com.facebook.buck.cxx.CxxLink)1 NativeLinkStrategy (com.facebook.buck.cxx.NativeLinkStrategy)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 CxxPythonExtensionBuilder (com.facebook.buck.python.CxxPythonExtensionBuilder)1 PythonPlatform (com.facebook.buck.python.PythonPlatform)1 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)1 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)1 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)1