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