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"));
}
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());
}
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*]"));
}
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)));
}
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"));
}
Aggregations