Search in sources :

Example 21 with CxxBuckConfig

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)));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) Linker(com.facebook.buck.cxx.Linker) NativeLinkTargetMode(com.facebook.buck.cxx.NativeLinkTargetMode) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) PatternMatchedCollection(com.facebook.buck.rules.coercer.PatternMatchedCollection) InternalFlavor(com.facebook.buck.model.InternalFlavor) Assert.assertThat(org.junit.Assert.assertThat) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) BuildRule(com.facebook.buck.rules.BuildRule) FlavorDomain(com.facebook.buck.model.FlavorDomain) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) CxxPlatformUtils(com.facebook.buck.cxx.CxxPlatformUtils) ImmutableList(com.google.common.collect.ImmutableList) FluentIterable(com.google.common.collect.FluentIterable) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) NativeLinkable(com.facebook.buck.cxx.NativeLinkable) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) MoreCollectors(com.facebook.buck.util.MoreCollectors) CxxLink(com.facebook.buck.cxx.CxxLink) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) TestCellBuilder.createCellRoots(com.facebook.buck.rules.TestCellBuilder.createCellRoots) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) CxxTestBuilder(com.facebook.buck.cxx.CxxTestBuilder) TargetGraph(com.facebook.buck.rules.TargetGraph) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) NativeLinkTarget(com.facebook.buck.cxx.NativeLinkTarget) Arg(com.facebook.buck.rules.args.Arg) CxxLibrary(com.facebook.buck.cxx.CxxLibrary) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags) Paths(java.nio.file.Paths) TargetGraphFactory(com.facebook.buck.testutil.TargetGraphFactory) StringWithMacrosUtils(com.facebook.buck.rules.macros.StringWithMacrosUtils) Optional(java.util.Optional) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Pattern(java.util.regex.Pattern) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) CxxBinaryBuilder(com.facebook.buck.cxx.CxxBinaryBuilder) Assert.assertEquals(org.junit.Assert.assertEquals) CxxLibrary(com.facebook.buck.cxx.CxxLibrary) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) BuildTarget(com.facebook.buck.model.BuildTarget) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 22 with CxxBuckConfig

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());
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 23 with CxxBuckConfig

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"))));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) CxxLink(com.facebook.buck.cxx.CxxLink) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 24 with CxxBuckConfig

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);
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 25 with CxxBuckConfig

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)));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) NativeLinkable(com.facebook.buck.cxx.NativeLinkable) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) NativeLinkTarget(com.facebook.buck.cxx.NativeLinkTarget) 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