Search in sources :

Example 26 with CxxLibraryBuilder

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

the class CxxPythonExtensionDescriptionTest method platformDeps.

@Test
public void platformDeps() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    CxxLibrary dep = (CxxLibrary) new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep")).build(resolver);
    CxxPythonExtensionBuilder builder = new CxxPythonExtensionBuilder(BuildTargetFactory.newInstance("//:rule"), FlavorDomain.of("Python Platform", PY2, PY3), new CxxBuckConfig(FakeBuckConfig.builder().build()), CxxTestBuilder.createDefaultPlatforms());
    CxxPythonExtension rule = builder.setPlatformDeps(PatternMatchedCollection.<ImmutableSortedSet<BuildTarget>>builder().add(Pattern.compile(PY2.getFlavor().toString()), ImmutableSortedSet.of(dep.getBuildTarget())).build()).build(resolver);
    NativeLinkTarget py2NativeLinkTarget = rule.getNativeLinkTarget(PY2);
    assertThat(ImmutableList.copyOf(py2NativeLinkTarget.getNativeLinkTargetDeps(CxxPlatformUtils.DEFAULT_PLATFORM)), Matchers.<NativeLinkable>hasItem(dep));
    NativeLinkTarget py3NativeLinkTarget = rule.getNativeLinkTarget(PY3);
    assertThat(ImmutableList.copyOf(py3NativeLinkTarget.getNativeLinkTargetDeps(CxxPlatformUtils.DEFAULT_PLATFORM)), Matchers.not(Matchers.<NativeLinkable>hasItem(dep)));
}
Also used : CxxLibrary(com.facebook.buck.cxx.CxxLibrary) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) NativeLinkable(com.facebook.buck.cxx.NativeLinkable) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) 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)

Example 27 with CxxLibraryBuilder

use of com.facebook.buck.cxx.CxxLibraryBuilder 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 28 with CxxLibraryBuilder

use of com.facebook.buck.cxx.CxxLibraryBuilder 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)

Example 29 with CxxLibraryBuilder

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

the class PythonBinaryDescriptionTest method transitiveNativeDepsUsingMergedNativeLinkStrategy.

@Test
public void transitiveNativeDepsUsingMergedNativeLinkStrategy() throws Exception {
    CxxLibraryBuilder transitiveCxxDepBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:transitive_dep")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("transitive_dep.c"))));
    CxxLibraryBuilder cxxDepBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("dep.c")))).setDeps(ImmutableSortedSet.of(transitiveCxxDepBuilder.getTarget()));
    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.setMainModule("main");
    binaryBuilder.setDeps(ImmutableSortedSet.of(cxxBuilder.getTarget()));
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(transitiveCxxDepBuilder.build(), cxxDepBuilder.build(), cxxBuilder.build(), binaryBuilder.build()), new DefaultTargetNodeToBuildRuleTransformer());
    transitiveCxxDepBuilder.build(resolver);
    cxxDepBuilder.build(resolver);
    cxxBuilder.build(resolver);
    PythonBinary binary = binaryBuilder.build(resolver);
    assertThat(Iterables.transform(binary.getComponents().getNativeLibraries().keySet(), Object::toString), Matchers.containsInAnyOrder("libomnibus.so", "libcxx.so"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Example 30 with CxxLibraryBuilder

use of com.facebook.buck.cxx.CxxLibraryBuilder 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"));
    }
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) CxxLink(com.facebook.buck.cxx.CxxLink) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Aggregations

CxxLibraryBuilder (com.facebook.buck.cxx.CxxLibraryBuilder)33 Test (org.junit.Test)33 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)23 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)18 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)18 PrebuiltCxxLibraryBuilder (com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder)17 BuildTarget (com.facebook.buck.model.BuildTarget)17 NSString (com.dd.plist.NSString)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 SourcePath (com.facebook.buck.rules.SourcePath)8 AlwaysFoundExecutableFinder (com.facebook.buck.io.AlwaysFoundExecutableFinder)7 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)7 Path (java.nio.file.Path)7 PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)6 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)6 CxxBuckConfig (com.facebook.buck.cxx.CxxBuckConfig)6 PathSourcePath (com.facebook.buck.rules.PathSourcePath)6 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)6 TargetGraph (com.facebook.buck.rules.TargetGraph)5 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)5