Search in sources :

Example 26 with CxxBuckConfig

use of com.facebook.buck.cxx.CxxBuckConfig 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")));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) 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)

Example 27 with CxxBuckConfig

use of com.facebook.buck.cxx.CxxBuckConfig in project buck by facebook.

the class PythonBinaryIntegrationTest method nativeLibsEnvVarIsPreserved.

@Test
public void nativeLibsEnvVarIsPreserved() throws IOException {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    assumeThat("TODO(8667197): Native libs currently don't work on El Capitan", Platform.detect(), not(equalTo(Platform.MACOS)));
    String nativeLibsEnvVarName = CxxPlatformUtils.build(new CxxBuckConfig(FakeBuckConfig.builder().build())).getLd().resolve(resolver).searchPathEnvVar();
    String originalNativeLibsEnvVar = "something";
    workspace.writeContentsToPath(String.format("import os; print(os.environ.get('%s'))", nativeLibsEnvVarName), "main_with_native_libs.py");
    // Pre-set library path.
    String nativeLibsEnvVar = workspace.runBuckCommandWithEnvironmentOverridesAndContext(workspace.getPath(""), Optional.empty(), ImmutableMap.of(nativeLibsEnvVarName, originalNativeLibsEnvVar), "run", ":bin-with-native-libs").assertSuccess().getStdout().trim();
    assertThat(nativeLibsEnvVar, equalTo(originalNativeLibsEnvVar));
    // Empty library path.
    nativeLibsEnvVar = workspace.runBuckCommandWithEnvironmentOverridesAndContext(workspace.getPath(""), Optional.empty(), ImmutableMap.of(), "run", ":bin-with-native-libs").assertSuccess().getStdout().trim();
    assertThat(nativeLibsEnvVar, equalTo("None"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Aggregations

CxxBuckConfig (com.facebook.buck.cxx.CxxBuckConfig)27 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)19 Test (org.junit.Test)19 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)18 BuildTarget (com.facebook.buck.model.BuildTarget)11 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)10 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)10 PrebuiltCxxLibraryBuilder (com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder)9 TargetGraph (com.facebook.buck.rules.TargetGraph)8 CxxLibraryBuilder (com.facebook.buck.cxx.CxxLibraryBuilder)6 NativeLinkTarget (com.facebook.buck.cxx.NativeLinkTarget)6 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)6 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)5 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)5 ExecutableFinder (com.facebook.buck.io.ExecutableFinder)5 BuildRule (com.facebook.buck.rules.BuildRule)5 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)5 AppleConfig (com.facebook.buck.apple.AppleConfig)4