use of com.facebook.buck.cxx.CxxLibraryBuilder 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")));
}
use of com.facebook.buck.cxx.CxxLibraryBuilder in project buck by facebook.
the class LuaBinaryDescriptionTest method versionLessNativeLibraryExtension.
@Test
public void versionLessNativeLibraryExtension() throws Exception {
CxxLibraryBuilder cxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:lib")).setSoname("libfoo.so.1.0").setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("hello.c"))));
LuaBinaryBuilder binaryBuilder = new LuaBinaryBuilder(BuildTargetFactory.newInstance("//:rule"), FakeLuaConfig.DEFAULT.withPackageStyle(LuaConfig.PackageStyle.INPLACE)).setMainModule("main").setDeps(ImmutableSortedSet.of(cxxLibraryBuilder.getTarget()));
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(cxxLibraryBuilder.build(), binaryBuilder.build()), new DefaultTargetNodeToBuildRuleTransformer());
cxxLibraryBuilder.build(resolver);
binaryBuilder.build(resolver);
SymlinkTree tree = resolver.getRuleWithType(LuaBinaryDescription.getNativeLibsSymlinkTreeTarget(binaryBuilder.getTarget()), SymlinkTree.class);
assertThat(tree.getLinks().keySet(), Matchers.hasItem(tree.getProjectFilesystem().getPath("libfoo.so")));
}
use of com.facebook.buck.cxx.CxxLibraryBuilder in project buck by facebook.
the class LuaBinaryDescriptionTest method transitiveNativeDepsUsingMergedNativeLinkStrategy.
@Test
public void transitiveNativeDepsUsingMergedNativeLinkStrategy() 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()));
LuaBinaryBuilder binaryBuilder = new LuaBinaryBuilder(BuildTargetFactory.newInstance("//:bin"), FakeLuaConfig.DEFAULT.withNativeLinkStrategy(NativeLinkStrategy.MERGED));
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);
LuaBinary binary = binaryBuilder.build(resolver);
assertThat(Iterables.transform(binary.getComponents().getNativeLibraries().keySet(), Object::toString), Matchers.containsInAnyOrder("libomnibus.so", "libcxx.so"));
}
use of com.facebook.buck.cxx.CxxLibraryBuilder in project buck by facebook.
the class PythonBinaryDescriptionTest method preloadLibraries.
@Test
public void preloadLibraries() throws Exception {
for (final NativeLinkStrategy strategy : NativeLinkStrategy.values()) {
CxxLibraryBuilder cxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("test.c"))));
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.setPreloadDeps(ImmutableSortedSet.of(cxxLibraryBuilder.getTarget()));
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(cxxLibraryBuilder.build(), binaryBuilder.build()), new DefaultTargetNodeToBuildRuleTransformer());
cxxLibraryBuilder.build(resolver);
PythonBinary binary = binaryBuilder.build(resolver);
assertThat("Using " + strategy, binary.getPreloadLibraries(), Matchers.hasItems("libdep.so"));
assertThat("Using " + strategy, binary.getComponents().getNativeLibraries().keySet(), Matchers.hasItems(Paths.get("libdep.so")));
}
}
use of com.facebook.buck.cxx.CxxLibraryBuilder in project buck by facebook.
the class CxxPythonExtensionDescriptionTest method nativeLinkTargetDeps.
@Test
public void nativeLinkTargetDeps() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
CxxLibrary dep = (CxxLibrary) new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep")).build(resolver);
CxxPythonExtensionBuilder builder = new CxxPythonExtensionBuilder(BuildTargetFactory.newInstance("//:rule"), FlavorDomain.of("Python Platform", PY2, PY3), new CxxBuckConfig(FakeBuckConfig.builder().build()), CxxTestBuilder.createDefaultPlatforms());
CxxPythonExtension rule = builder.setDeps(ImmutableSortedSet.of(dep.getBuildTarget())).build(resolver);
NativeLinkTarget nativeLinkTarget = rule.getNativeLinkTarget(PY2);
assertThat(ImmutableList.copyOf(nativeLinkTarget.getNativeLinkTargetDeps(CxxPlatformUtils.DEFAULT_PLATFORM)), Matchers.<NativeLinkable>hasItem(dep));
}
Aggregations