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")));
}
}
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")));
}
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"))));
}
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")));
}
Aggregations