Search in sources :

Example 21 with CxxLibraryBuilder

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

the class ProjectGeneratorTest method testCxxLibraryExportedPreprocessorFlags.

@Test
public void testCxxLibraryExportedPreprocessorFlags() throws IOException {
    BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> node = new CxxLibraryBuilder(buildTarget).setExportedPreprocessorFlags(ImmutableList.of("-DHELLO")).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node), ImmutableSet.of());
    projectGenerator.createXcodeProjects();
    PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:lib");
    assertHasConfigurations(target, "Debug", "Release", "Profile");
    ImmutableMap<String, String> settings = ProjectGeneratorTestUtils.getBuildSettings(projectFilesystem, buildTarget, target, "Debug");
    assertEquals("-Wno-deprecated -Wno-conversion -DHELLO -Wno-deprecated -Wno-conversion -DHELLO", settings.get("OTHER_CFLAGS"));
}
Also used : PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) BuildTarget(com.facebook.buck.model.BuildTarget) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString) Test(org.junit.Test)

Example 22 with CxxLibraryBuilder

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

the class ProjectGeneratorTest method testGenerateOnlyHeaderSymlinkTrees.

@Test
public void testGenerateOnlyHeaderSymlinkTrees() throws IOException {
    BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> node = new CxxLibraryBuilder(buildTarget).setExportedHeaders(ImmutableSortedSet.of(new FakeSourcePath("foo/dir1/bar.h"))).setHeaders(ImmutableSortedSet.of(new FakeSourcePath("foo/dir1/foo.h"), new FakeSourcePath("foo/dir2/baz.h"))).setSrcs(ImmutableSortedSet.of()).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node), ImmutableSet.of(ProjectGenerator.Option.GENERATE_HEADERS_SYMLINK_TREES_ONLY));
    projectGenerator.createXcodeProjects();
    // The project should not generated since we're generating only header symlink trees.
    assertFalse(projectGenerator.getProjectPath() + " should not be generated.", projectFilesystem.isDirectory(projectGenerator.getProjectPath()));
    List<Path> headerSymlinkTrees = projectGenerator.getGeneratedHeaderSymlinkTrees();
    assertThat(headerSymlinkTrees, hasSize(2));
    assertThat(headerSymlinkTrees.get(0).toString(), is(equalTo("buck-out/gen/_p/CwkbTNOBmb-pub")));
    assertThatHeaderSymlinkTreeContains(Paths.get("buck-out/gen/_p/CwkbTNOBmb-pub"), ImmutableMap.of("foo/dir1/bar.h", "foo/dir1/bar.h"));
    assertThat(headerSymlinkTrees.get(1).toString(), is(equalTo("buck-out/gen/_p/CwkbTNOBmb-priv")));
    assertThatHeaderSymlinkTreeContains(Paths.get("buck-out/gen/_p/CwkbTNOBmb-priv"), ImmutableMap.<String, String>builder().put("foo/dir1/foo.h", "foo/dir1/foo.h").put("foo/dir2/baz.h", "foo/dir2/baz.h").build());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString) Test(org.junit.Test)

Example 23 with CxxLibraryBuilder

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

the class ProjectGeneratorTest method testCxxLibraryPlatformFlags.

@Test
public void testCxxLibraryPlatformFlags() throws IOException {
    BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> node = new CxxLibraryBuilder(buildTarget).setPlatformCompilerFlags(PatternMatchedCollection.<ImmutableList<String>>builder().add(Pattern.compile("android.*"), ImmutableList.of("-ffoo-android")).add(Pattern.compile("iphone.*"), ImmutableList.of("-ffoo-iphone")).add(Pattern.compile("macosx.*"), ImmutableList.of("-ffoo-macosx")).build()).setPlatformPreprocessorFlags(PatternMatchedCollection.<ImmutableList<String>>builder().add(Pattern.compile("android.*"), ImmutableList.of("-fbar-android")).add(Pattern.compile("iphone.*"), ImmutableList.of("-fbar-iphone")).add(Pattern.compile("macosx.*"), ImmutableList.of("-fbar-macosx")).build()).setPlatformLinkerFlags(PatternMatchedCollection.<ImmutableList<StringWithMacros>>builder().add(Pattern.compile("android.*"), ImmutableList.of(StringWithMacrosUtils.format("-lbaz-android"))).add(Pattern.compile("iphone.*"), ImmutableList.of(StringWithMacrosUtils.format("-lbaz-iphone"))).add(Pattern.compile("macosx.*"), ImmutableList.of(StringWithMacrosUtils.format("-lbaz-macosx"))).build()).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node), ImmutableSet.of());
    projectGenerator.createXcodeProjects();
    PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:lib");
    assertHasConfigurations(target, "Debug", "Release", "Profile");
    ImmutableMap<String, String> settings = ProjectGeneratorTestUtils.getBuildSettings(projectFilesystem, buildTarget, target, "Debug");
    assertEquals("-Wno-deprecated -Wno-conversion -Wno-deprecated -Wno-conversion", settings.get("OTHER_CFLAGS"));
    assertEquals("-Wundeclared-selector -Wno-objc-designated-initializers " + "-Wundeclared-selector -Wno-objc-designated-initializers", settings.get("OTHER_CPLUSPLUSFLAGS"));
    assertEquals("$(inherited) ", settings.get("OTHER_LDFLAGS"));
    assertEquals("-Wno-deprecated -Wno-conversion -ffoo-iphone -fbar-iphone " + "-Wno-deprecated -Wno-conversion -ffoo-iphone -fbar-iphone", settings.get("OTHER_CFLAGS[sdk=*iphone*]"));
    assertEquals("-Wundeclared-selector -Wno-objc-designated-initializers -ffoo-iphone -fbar-iphone " + "-Wundeclared-selector -Wno-objc-designated-initializers -ffoo-iphone -fbar-iphone", settings.get("OTHER_CPLUSPLUSFLAGS[sdk=*iphone*]"));
    assertEquals("-lbaz-iphone -lbaz-iphone", settings.get("OTHER_LDFLAGS[sdk=*iphone*]"));
}
Also used : PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) BuildTarget(com.facebook.buck.model.BuildTarget) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) ImmutableList(com.google.common.collect.ImmutableList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString) Test(org.junit.Test)

Example 24 with CxxLibraryBuilder

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

the class AndroidNativeLibsPackageableGraphEnhancerTest method testCxxLibrary.

@Test
@SuppressWarnings("unchecked")
public void testCxxLibrary() throws Exception {
    NdkCxxPlatform ndkCxxPlatform = NdkCxxPlatform.builder().setCxxPlatform(CxxPlatformUtils.DEFAULT_PLATFORM).setCxxRuntime(NdkCxxPlatforms.CxxRuntime.GNUSTL).setCxxSharedRuntimePath(Paths.get("runtime")).setObjdump(new CommandTool.Builder().addArg("objdump").build()).build();
    ImmutableMap<NdkCxxPlatforms.TargetCpuType, NdkCxxPlatform> nativePlatforms = ImmutableMap.<NdkCxxPlatforms.TargetCpuType, NdkCxxPlatform>builder().put(NdkCxxPlatforms.TargetCpuType.ARMV7, ndkCxxPlatform).put(NdkCxxPlatforms.TargetCpuType.X86, ndkCxxPlatform).build();
    CxxLibraryBuilder cxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:cxxlib")).setSoname("somelib.so").setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("test/bar.cpp"))));
    TargetNode<CxxLibraryDescription.Arg, ?> cxxLibraryDescription = cxxLibraryBuilder.build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(cxxLibraryDescription);
    BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    CxxLibrary cxxLibrary = (CxxLibrary) cxxLibraryBuilder.build(ruleResolver, new FakeProjectFilesystem(), targetGraph);
    ruleResolver.addToIndex(cxxLibrary);
    BuildTarget target = BuildTargetFactory.newInstance("//:target");
    BuildRuleParams originalParams = new FakeBuildRuleParamsBuilder(target).setDeclaredDeps(ImmutableSortedSet.of(cxxLibrary)).build();
    APKModuleGraph apkModuleGraph = new APKModuleGraph(TargetGraph.EMPTY, target, Optional.empty());
    AndroidNativeLibsPackageableGraphEnhancer enhancer = new AndroidNativeLibsPackageableGraphEnhancer(ruleResolver, originalParams, nativePlatforms, ImmutableSet.of(NdkCxxPlatforms.TargetCpuType.ARMV7), CxxPlatformUtils.DEFAULT_CONFIG, /* nativeLibraryMergeMap */
    Optional.empty(), /* nativeLibraryMergeGlue */
    Optional.empty(), AndroidBinary.RelinkerMode.DISABLED, apkModuleGraph);
    AndroidPackageableCollector collector = new AndroidPackageableCollector(target, ImmutableSet.of(), ImmutableSet.of(), apkModuleGraph);
    collector.addPackageables(AndroidPackageableCollector.getPackageableRules(ImmutableSet.of(cxxLibrary)));
    AndroidPackageableCollection packageableCollection = collector.build();
    Optional<ImmutableMap<APKModule, CopyNativeLibraries>> copyNativeLibrariesOptional = enhancer.enhance(packageableCollection).getCopyNativeLibraries();
    CopyNativeLibraries copyNativeLibraries = copyNativeLibrariesOptional.get().get(apkModuleGraph.getRootAPKModule());
    assertThat(copyNativeLibraries.getStrippedObjectDescriptions(), Matchers.containsInAnyOrder(Matchers.allOf(Matchers.hasProperty("targetCpuType", Matchers.equalTo(NdkCxxPlatforms.TargetCpuType.ARMV7)), Matchers.hasProperty("strippedObjectName", Matchers.equalTo("somelib.so"))), Matchers.allOf(Matchers.hasProperty("targetCpuType", Matchers.equalTo(NdkCxxPlatforms.TargetCpuType.ARMV7)), Matchers.hasProperty("strippedObjectName", Matchers.equalTo("libgnustl_shared.so")))));
    assertThat(copyNativeLibraries.getNativeLibDirectories(), Matchers.empty());
    ImmutableCollection<BuildRule> stripRules = ruleFinder.filterBuildRuleInputs(copyNativeLibraries.getStrippedObjectDescriptions().stream().map(StrippedObjectDescription::getSourcePath).collect(MoreCollectors.toImmutableSet()));
    assertThat(stripRules, Matchers.contains(Matchers.instanceOf(StripLinkable.class), Matchers.instanceOf(StripLinkable.class)));
}
Also used : CxxLibrary(com.facebook.buck.cxx.CxxLibrary) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) BuildTarget(com.facebook.buck.model.BuildTarget) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) ImmutableMap(com.google.common.collect.ImmutableMap) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Test(org.junit.Test)

Example 25 with CxxLibraryBuilder

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

the class LuaBinaryDescriptionTest method transitiveDepsOfNativeStarterDepsAreIncludedInMergedNativeLinkStrategy.

@Test
public void transitiveDepsOfNativeStarterDepsAreIncludedInMergedNativeLinkStrategy() 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()));
    CxxLibraryBuilder nativeStarterCxxBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:native_starter")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("native_starter.c")))).setDeps(ImmutableSortedSet.of(transitiveCxxDepBuilder.getTarget()));
    LuaBinaryBuilder binaryBuilder = new LuaBinaryBuilder(BuildTargetFactory.newInstance("//:bin"), FakeLuaConfig.DEFAULT.withNativeLinkStrategy(NativeLinkStrategy.MERGED));
    binaryBuilder.setMainModule("main");
    binaryBuilder.setDeps(ImmutableSortedSet.of(cxxBuilder.getTarget()));
    binaryBuilder.setNativeStarterLibrary(nativeStarterCxxBuilder.getTarget());
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(transitiveCxxDepBuilder.build(), cxxDepBuilder.build(), cxxBuilder.build(), nativeStarterCxxBuilder.build(), binaryBuilder.build()), new DefaultTargetNodeToBuildRuleTransformer());
    transitiveCxxDepBuilder.build(resolver);
    cxxDepBuilder.build(resolver);
    cxxBuilder.build(resolver);
    nativeStarterCxxBuilder.build(resolver);
    LuaBinary 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) 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