use of com.facebook.buck.io.AlwaysFoundExecutableFinder 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.io.AlwaysFoundExecutableFinder in project buck by facebook.
the class PythonBinaryDescriptionTest method pexExecutorRuleIsAddedToParseTimeDeps.
@Test
public void pexExecutorRuleIsAddedToParseTimeDeps() throws Exception {
ShBinaryBuilder pexExecutorBuilder = new ShBinaryBuilder(BuildTargetFactory.newInstance("//:pex_executor")).setMain(new FakeSourcePath("run.sh"));
PythonBinaryBuilder builder = new PythonBinaryBuilder(BuildTargetFactory.newInstance("//:bin"), new PythonBuckConfig(FakeBuckConfig.builder().setSections(ImmutableMap.of("python", ImmutableMap.of("path_to_pex_executer", pexExecutorBuilder.getTarget().toString()))).build(), new AlwaysFoundExecutableFinder()), PythonTestUtils.PYTHON_PLATFORMS, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS);
builder.setMainModule("main").setPackageStyle(PythonBuckConfig.PackageStyle.STANDALONE);
assertThat(builder.build().getExtraDeps(), Matchers.hasItem(pexExecutorBuilder.getTarget()));
}
use of com.facebook.buck.io.AlwaysFoundExecutableFinder in project buck by facebook.
the class PythonBinaryDescriptionTest method executableCommandWithPathToPexExecutor.
@Test
public void executableCommandWithPathToPexExecutor() throws Exception {
BuildTarget target = BuildTargetFactory.newInstance("//foo:bin");
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
final Path executor = Paths.get("executor");
PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().build(), new AlwaysFoundExecutableFinder()) {
@Override
public Optional<Tool> getPexExecutor(BuildRuleResolver resolver) {
return Optional.of(new HashedFileTool(executor));
}
};
PythonBinaryBuilder builder = new PythonBinaryBuilder(target, config, PythonTestUtils.PYTHON_PLATFORMS, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS);
PythonPackagedBinary binary = (PythonPackagedBinary) builder.setMainModule("main").build(resolver);
assertThat(binary.getExecutableCommand().getCommandPrefix(pathResolver), Matchers.contains(executor.toString(), pathResolver.getAbsolutePath(binary.getSourcePathToOutput()).toString()));
}
use of com.facebook.buck.io.AlwaysFoundExecutableFinder in project buck by facebook.
the class PythonBinaryDescriptionTest method linkerFlagsUsingMergedNativeLinkStrategy.
@Test
public void linkerFlagsUsingMergedNativeLinkStrategy() throws Exception {
CxxLibraryBuilder cxxDepBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("dep.c"))));
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.MERGED;
}
};
PythonBinaryBuilder binaryBuilder = new PythonBinaryBuilder(BuildTargetFactory.newInstance("//:bin"), config, PythonTestUtils.PYTHON_PLATFORMS, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS);
binaryBuilder.setLinkerFlags(ImmutableList.of("-flag"));
binaryBuilder.setMainModule("main");
binaryBuilder.setDeps(ImmutableSortedSet.of(cxxBuilder.getTarget()));
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(cxxDepBuilder.build(), cxxBuilder.build(), binaryBuilder.build()), new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
cxxDepBuilder.build(resolver);
cxxBuilder.build(resolver);
PythonBinary binary = binaryBuilder.build(resolver);
for (SourcePath path : binary.getComponents().getNativeLibraries().values()) {
CxxLink link = resolver.getRuleOptionalWithType(((BuildTargetSourcePath<?>) path).getTarget(), CxxLink.class).get();
assertThat(Arg.stringify(link.getArgs(), pathResolver), Matchers.hasItem("-flag"));
}
}
use of com.facebook.buck.io.AlwaysFoundExecutableFinder in project buck by facebook.
the class PythonBinaryDescriptionTest method transitiveDepsOfLibsWithPrebuiltNativeLibsAreNotIncludedInMergedLink.
@Test
public void transitiveDepsOfLibsWithPrebuiltNativeLibsAreNotIncludedInMergedLink() throws Exception {
CxxLibraryBuilder transitiveCxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:transitive_cxx")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("transitive_cxx.c"))));
CxxLibraryBuilder cxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:cxx")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("cxx.c")))).setDeps(ImmutableSortedSet.of(transitiveCxxLibraryBuilder.getTarget()));
PythonLibraryBuilder pythonLibraryBuilder = new PythonLibraryBuilder(BuildTargetFactory.newInstance("//:lib")).setSrcs(SourceList.ofUnnamedSources(ImmutableSortedSet.of(new FakeSourcePath("prebuilt.so")))).setDeps(ImmutableSortedSet.of(cxxLibraryBuilder.getTarget()));
PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().build(), new AlwaysFoundExecutableFinder()) {
@Override
public NativeLinkStrategy getNativeLinkStrategy() {
return NativeLinkStrategy.MERGED;
}
};
PythonBinaryBuilder pythonBinaryBuilder = new PythonBinaryBuilder(BuildTargetFactory.newInstance("//:bin"), config, PythonTestUtils.PYTHON_PLATFORMS, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS);
pythonBinaryBuilder.setMainModule("main");
pythonBinaryBuilder.setDeps(ImmutableSortedSet.of(pythonLibraryBuilder.getTarget()));
TargetGraph targetGraph = TargetGraphFactory.newInstance(transitiveCxxLibraryBuilder.build(), cxxLibraryBuilder.build(), pythonLibraryBuilder.build(), pythonBinaryBuilder.build());
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
transitiveCxxLibraryBuilder.build(resolver, filesystem, targetGraph);
cxxLibraryBuilder.build(resolver, filesystem, targetGraph);
pythonLibraryBuilder.build(resolver, filesystem, targetGraph);
PythonBinary binary = pythonBinaryBuilder.build(resolver, filesystem, targetGraph);
assertThat(Iterables.transform(binary.getComponents().getNativeLibraries().keySet(), Object::toString), Matchers.hasItem("libtransitive_cxx.so"));
}
Aggregations