use of com.facebook.buck.cxx.CxxBuckConfig in project buck by facebook.
the class CxxPythonExtensionDescriptionTest method createBuildRuleNativeLinkableDep.
@Test
public void createBuildRuleNativeLinkableDep() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildTarget target = BuildTargetFactory.newInstance("//:target");
// Setup a C/C++ library that we'll depend on form the C/C++ binary description.
BuildTarget cxxLibraryTarget = BuildTargetFactory.newInstance("//:dep");
CxxLibraryBuilder cxxLibraryBuilder = new CxxLibraryBuilder(cxxLibraryTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("something.cpp"), ImmutableList.of())));
CxxPythonExtensionBuilder builder = new CxxPythonExtensionBuilder(target, FlavorDomain.of("Python Platform", PY2, PY3), new CxxBuckConfig(FakeBuckConfig.builder().build()), CxxTestBuilder.createDefaultPlatforms()).setDeps(ImmutableSortedSet.of(cxxLibraryTarget));
TargetGraph targetGraph = TargetGraphFactory.newInstance(cxxLibraryBuilder.build(), builder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
CxxLibrary dep = (CxxLibrary) cxxLibraryBuilder.build(resolver, filesystem, targetGraph);
CxxPythonExtension extension = builder.build(resolver, filesystem, targetGraph);
NativeLinkableInput depInput = dep.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.SHARED);
// Verify that the shared library dep propagated to the link rule.
extension.getPythonPackageComponents(PY2, CxxPlatformUtils.DEFAULT_PLATFORM);
BuildRule rule = resolver.getRule(CxxPythonExtensionDescription.getExtensionTarget(target, PY2.getFlavor(), CxxPlatformUtils.DEFAULT_PLATFORM.getFlavor()));
assertThat(rule.getDeps(), Matchers.hasItems(FluentIterable.from(depInput.getArgs()).transformAndConcat(arg -> arg.getDeps(ruleFinder)).toArray(BuildRule.class)));
}
use of com.facebook.buck.cxx.CxxBuckConfig in project buck by facebook.
the class CxxPythonExtensionDescriptionTest method createBuildRuleBaseModule.
@Test
public void createBuildRuleBaseModule() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildTarget target = BuildTargetFactory.newInstance("//:target");
CxxPythonExtensionBuilder builder = new CxxPythonExtensionBuilder(target, FlavorDomain.of("Python Platform", PY2, PY3), new CxxBuckConfig(FakeBuckConfig.builder().build()), CxxTestBuilder.createDefaultPlatforms());
TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
CxxPythonExtension normal = builder.build(resolver, filesystem, targetGraph);
PythonPackageComponents normalComps = normal.getPythonPackageComponents(PY2, CxxPlatformUtils.DEFAULT_PLATFORM);
assertEquals(ImmutableSet.of(target.getBasePath().resolve(CxxPythonExtensionDescription.getExtensionName(target.getShortName()))), normalComps.getModules().keySet());
// Verify that explicitly setting works.
BuildTarget target2 = BuildTargetFactory.newInstance("//:target2#py2");
String name = "blah";
CxxPythonExtensionBuilder baseModuleBuilder = new CxxPythonExtensionBuilder(target2, FlavorDomain.of("Python Platform", PY2, PY3), new CxxBuckConfig(FakeBuckConfig.builder().build()), CxxTestBuilder.createDefaultPlatforms()).setBaseModule(name);
targetGraph = TargetGraphFactory.newInstance(baseModuleBuilder.build());
resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
CxxPythonExtension baseModule = baseModuleBuilder.build(resolver, filesystem, targetGraph);
PythonPackageComponents baseModuleComps = baseModule.getPythonPackageComponents(PY2, CxxPlatformUtils.DEFAULT_PLATFORM);
assertEquals(ImmutableSet.of(Paths.get(name).resolve(CxxPythonExtensionDescription.getExtensionName(target2.getShortName()))), baseModuleComps.getModules().keySet());
}
use of com.facebook.buck.cxx.CxxBuckConfig in project buck by facebook.
the class CxxPythonExtensionDescriptionTest method py2AndPy3PropagateToLinkRules.
@Test
public void py2AndPy3PropagateToLinkRules() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
PrebuiltCxxLibraryBuilder python2Builder = new PrebuiltCxxLibraryBuilder(PYTHON2_DEP_TARGET).setHeaderOnly(true).setExportedLinkerFlags(ImmutableList.of("-lpython2"));
PrebuiltCxxLibraryBuilder python3Builder = new PrebuiltCxxLibraryBuilder(PYTHON3_DEP_TARGET).setHeaderOnly(true).setExportedLinkerFlags(ImmutableList.of("-lpython3"));
PythonPlatform py2 = PY2.withCxxLibrary(PYTHON2_DEP_TARGET);
PythonPlatform py3 = PY3.withCxxLibrary(PYTHON3_DEP_TARGET);
BuildTarget target = BuildTargetFactory.newInstance("//:target");
CxxPythonExtensionBuilder builder = new CxxPythonExtensionBuilder(target, FlavorDomain.of("Python Platform", py2, py3), new CxxBuckConfig(FakeBuckConfig.builder().build()), CxxTestBuilder.createDefaultPlatforms());
TargetGraph targetGraph = TargetGraphFactory.newInstance(python2Builder.build(), python3Builder.build(), builder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
python2Builder.build(resolver, filesystem, targetGraph);
python3Builder.build(resolver, filesystem, targetGraph);
CxxPythonExtension extension = builder.build(resolver, filesystem, targetGraph);
// Get the py2 extension, and verify it pulled in the py2 lib but not the py3 lib.
CxxLink py2Ext = (CxxLink) extension.getExtension(py2, CxxPlatformUtils.DEFAULT_PLATFORM);
assertThat(Arg.stringify(py2Ext.getArgs(), pathResolver), Matchers.allOf(Matchers.hasItem("-lpython2"), Matchers.not(Matchers.hasItem("-lpython3"))));
// Get the py3 extension, and verify it pulled in the py3 lib but not the py2 lib.
CxxLink py3Ext = (CxxLink) extension.getExtension(py3, CxxPlatformUtils.DEFAULT_PLATFORM);
assertThat(Arg.stringify(py3Ext.getArgs(), pathResolver), Matchers.allOf(Matchers.hasItem("-lpython3"), Matchers.not(Matchers.hasItem("-lpython2"))));
}
use of com.facebook.buck.cxx.CxxBuckConfig in project buck by facebook.
the class CxxPythonExtensionDescriptionTest method createBuildRulePythonPackageable.
@Test
public void createBuildRulePythonPackageable() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildTarget target = BuildTargetFactory.newInstance("//:target");
CxxPythonExtensionBuilder builder = new CxxPythonExtensionBuilder(target, FlavorDomain.of("Python Platform", PY2, PY3), new CxxBuckConfig(FakeBuckConfig.builder().build()), CxxTestBuilder.createDefaultPlatforms());
TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
CxxPythonExtension extension = builder.build(resolver, filesystem, targetGraph);
// Verify that we get the expected view from the python packageable interface.
PythonPackageComponents actualComponent = extension.getPythonPackageComponents(PY2, CxxPlatformUtils.DEFAULT_PLATFORM);
BuildRule rule = resolver.getRule(CxxPythonExtensionDescription.getExtensionTarget(target, PY2.getFlavor(), CxxPlatformUtils.DEFAULT_PLATFORM.getFlavor()));
PythonPackageComponents expectedComponents = PythonPackageComponents.of(ImmutableMap.of(target.getBasePath().resolve(CxxPythonExtensionDescription.getExtensionName(target.getShortName())), rule.getSourcePathToOutput()), ImmutableMap.of(), ImmutableMap.of(), ImmutableSet.of(), Optional.of(false));
assertEquals(expectedComponents, actualComponent);
}
use of com.facebook.buck.cxx.CxxBuckConfig in project buck by facebook.
the class CxxPythonExtensionDescriptionTest method nativeLinkTargetDepsIncludePlatformCxxLibrary.
@Test
public void nativeLinkTargetDepsIncludePlatformCxxLibrary() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
CxxLibraryBuilder python2Builder = new CxxLibraryBuilder(PYTHON2_DEP_TARGET);
PythonPlatform platform = PY2.withCxxLibrary(PYTHON2_DEP_TARGET);
CxxPythonExtensionBuilder builder = new CxxPythonExtensionBuilder(BuildTargetFactory.newInstance("//:rule"), FlavorDomain.of("Python Platform", platform), new CxxBuckConfig(FakeBuckConfig.builder().build()), CxxTestBuilder.createDefaultPlatforms());
TargetGraph targetGraph = TargetGraphFactory.newInstance(python2Builder.build(), builder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
python2Builder.build(resolver, filesystem, targetGraph);
CxxPythonExtension rule = builder.build(resolver, filesystem, targetGraph);
NativeLinkTarget nativeLinkTarget = rule.getNativeLinkTarget(platform);
assertThat(ImmutableList.copyOf(nativeLinkTarget.getNativeLinkTargetDeps(CxxPlatformUtils.DEFAULT_PLATFORM)), Matchers.hasItem((NativeLinkable) resolver.getRule(PYTHON2_DEP_TARGET)));
}
Aggregations