Search in sources :

Example 1 with CxxPythonExtensionBuilder

use of com.facebook.buck.python.CxxPythonExtensionBuilder in project buck by facebook.

the class LuaBinaryDescriptionTest method platformDeps.

@Test
public void platformDeps() throws Exception {
    FlavorDomain<PythonPlatform> pythonPlatforms = FlavorDomain.of("Python Platform", PY2, PY3);
    CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(FakeBuckConfig.builder().build());
    CxxLibraryBuilder py2LibBuilder = new CxxLibraryBuilder(PYTHON2_DEP_TARGET);
    CxxLibraryBuilder py3LibBuilder = new CxxLibraryBuilder(PYTHON3_DEP_TARGET);
    CxxLibraryBuilder py2CxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:py2_library")).setSoname("libpy2.so").setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("hello.c"))));
    CxxLibraryBuilder py3CxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:py3_library")).setSoname("libpy3.so").setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("hello.c"))));
    CxxPythonExtensionBuilder cxxPythonExtensionBuilder = new CxxPythonExtensionBuilder(BuildTargetFactory.newInstance("//:extension"), pythonPlatforms, cxxBuckConfig, CxxTestBuilder.createDefaultPlatforms()).setPlatformDeps(PatternMatchedCollection.<ImmutableSortedSet<BuildTarget>>builder().add(Pattern.compile(PY2.getFlavor().toString()), ImmutableSortedSet.of(py2CxxLibraryBuilder.getTarget())).add(Pattern.compile(PY3.getFlavor().toString()), ImmutableSortedSet.of(py3CxxLibraryBuilder.getTarget())).build());
    LuaBinaryBuilder luaBinaryBuilder = new LuaBinaryBuilder(new LuaBinaryDescription(FakeLuaConfig.DEFAULT, cxxBuckConfig, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS, pythonPlatforms), BuildTargetFactory.newInstance("//:binary")).setMainModule("main").setDeps(ImmutableSortedSet.of(cxxPythonExtensionBuilder.getTarget()));
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(py2LibBuilder.build(), py3LibBuilder.build(), py2CxxLibraryBuilder.build(), py3CxxLibraryBuilder.build(), cxxPythonExtensionBuilder.build(), luaBinaryBuilder.build()), new DefaultTargetNodeToBuildRuleTransformer());
    py2LibBuilder.build(resolver);
    py3LibBuilder.build(resolver);
    py2CxxLibraryBuilder.build(resolver);
    py3CxxLibraryBuilder.build(resolver);
    cxxPythonExtensionBuilder.build(resolver);
    LuaBinary luaBinary = luaBinaryBuilder.build(resolver);
    LuaPackageComponents components = luaBinary.getComponents();
    assertThat(components.getNativeLibraries().keySet(), Matchers.hasItem("libpy2.so"));
    assertThat(components.getNativeLibraries().keySet(), Matchers.not(Matchers.hasItem("libpy3.so")));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) CxxPythonExtensionBuilder(com.facebook.buck.python.CxxPythonExtensionBuilder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) PythonPlatform(com.facebook.buck.python.PythonPlatform) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 2 with CxxPythonExtensionBuilder

use of com.facebook.buck.python.CxxPythonExtensionBuilder 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)

Aggregations

CxxBuckConfig (com.facebook.buck.cxx.CxxBuckConfig)2 PrebuiltCxxLibraryBuilder (com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder)2 CxxPythonExtensionBuilder (com.facebook.buck.python.CxxPythonExtensionBuilder)2 PythonPlatform (com.facebook.buck.python.PythonPlatform)2 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)2 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)2 Test (org.junit.Test)2 CxxLibraryBuilder (com.facebook.buck.cxx.CxxLibraryBuilder)1 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)1 TargetGraph (com.facebook.buck.rules.TargetGraph)1 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1