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