Search in sources :

Example 1 with NativeLinkStrategy

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")));
    }
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) NativeLinkStrategy(com.facebook.buck.cxx.NativeLinkStrategy) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Example 2 with NativeLinkStrategy

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")));
    }
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) NativeLinkStrategy(com.facebook.buck.cxx.NativeLinkStrategy) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Aggregations

CxxLibraryBuilder (com.facebook.buck.cxx.CxxLibraryBuilder)2 NativeLinkStrategy (com.facebook.buck.cxx.NativeLinkStrategy)2 PrebuiltCxxLibraryBuilder (com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder)2 AlwaysFoundExecutableFinder (com.facebook.buck.io.AlwaysFoundExecutableFinder)2 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)2 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)2 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)2 Test (org.junit.Test)2 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 TargetGraph (com.facebook.buck.rules.TargetGraph)1 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)1 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)1