Search in sources :

Example 31 with CxxLibraryBuilder

use of com.facebook.buck.cxx.CxxLibraryBuilder 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"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Example 32 with CxxLibraryBuilder

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

the class TargetNodeTranslatorTest method noTranslate.

@Test
public void noTranslate() {
    BuildTarget a = BuildTargetFactory.newInstance("//:a");
    BuildTarget b = BuildTargetFactory.newInstance("//:b");
    BuildTarget c = BuildTargetFactory.newInstance("//:c");
    TargetNode<CxxLibraryDescription.Arg, ?> node = new CxxLibraryBuilder(a).setDeps(ImmutableSortedSet.of(b)).setExportedDeps(ImmutableSortedSet.of(c)).build();
    TargetNodeTranslator translator = new TargetNodeTranslator(ImmutableList.of()) {

        @Override
        public Optional<BuildTarget> translateBuildTarget(BuildTarget target) {
            return Optional.empty();
        }

        @Override
        public Optional<ImmutableMap<BuildTarget, Version>> getSelectedVersions(BuildTarget target) {
            return Optional.empty();
        }
    };
    Optional<TargetNode<CxxLibraryDescription.Arg, ?>> translated = translator.translateNode(node);
    assertFalse(translated.isPresent());
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) CxxLibraryDescription(com.facebook.buck.cxx.CxxLibraryDescription) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 33 with CxxLibraryBuilder

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

the class TargetNodeTranslatorTest method translate.

@Test
public void translate() {
    BuildTarget a = BuildTargetFactory.newInstance("//:a");
    BuildTarget b = BuildTargetFactory.newInstance("//:b");
    BuildTarget c = BuildTargetFactory.newInstance("//:c");
    final BuildTarget d = BuildTargetFactory.newInstance("//:d");
    TargetNode<CxxLibraryDescription.Arg, ?> node = new CxxLibraryBuilder(a).setDeps(ImmutableSortedSet.of(b)).setExportedDeps(ImmutableSortedSet.of(c)).build();
    TargetNodeTranslator translator = new TargetNodeTranslator(ImmutableList.of()) {

        @Override
        public Optional<BuildTarget> translateBuildTarget(BuildTarget target) {
            return Optional.of(d);
        }

        @Override
        public Optional<ImmutableMap<BuildTarget, Version>> getSelectedVersions(BuildTarget target) {
            return Optional.empty();
        }
    };
    Optional<TargetNode<CxxLibraryDescription.Arg, ?>> translated = translator.translateNode(node);
    assertThat(translated.get().getBuildTarget(), Matchers.equalTo(d));
    assertThat(translated.get().getDeclaredDeps(), Matchers.equalTo(ImmutableSet.of(d)));
    assertThat(translated.get().getExtraDeps(), Matchers.equalTo(ImmutableSet.of(d)));
    assertThat(translated.get().getConstructorArg().deps, Matchers.equalTo(ImmutableSortedSet.of(d)));
    assertThat(translated.get().getConstructorArg().exportedDeps, Matchers.equalTo(ImmutableSortedSet.of(d)));
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) CxxLibraryDescription(com.facebook.buck.cxx.CxxLibraryDescription) ImmutableMap(com.google.common.collect.ImmutableMap) 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