use of com.facebook.buck.cxx.NativeLinkStrategy 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.NativeLinkStrategy 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")));
}
}
Aggregations