use of com.facebook.buck.cxx.CxxLibraryBuilder in project buck by facebook.
the class ProjectGeneratorTest method testCxxLibraryHeaderGroupsWithMapsOfHeadersAndCustomNamespace.
@Test
public void testCxxLibraryHeaderGroupsWithMapsOfHeadersAndCustomNamespace() throws IOException {
BuildTarget privateGeneratedTarget = BuildTarget.builder(rootPath, "//foo", "generated1.h").build();
BuildTarget publicGeneratedTarget = BuildTarget.builder(rootPath, "//foo", "generated2.h").build();
TargetNode<?, ?> privateGeneratedNode = ExportFileBuilder.newExportFileBuilder(privateGeneratedTarget).build();
TargetNode<?, ?> publicGeneratedNode = ExportFileBuilder.newExportFileBuilder(publicGeneratedTarget).build();
BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
TargetNode<?, ?> node = new CxxLibraryBuilder(buildTarget).setExportedHeaders(ImmutableSortedMap.of("yet/another/name.h", new FakeSourcePath("foo/dir1/bar.h"), "and/one/more.h", new DefaultBuildTargetSourcePath(publicGeneratedTarget))).setHeaders(ImmutableSortedMap.of("any/name.h", new FakeSourcePath("foo/dir1/foo.h"), "different/name.h", new FakeSourcePath("foo/dir2/baz.h"), "one/more/name.h", new DefaultBuildTargetSourcePath(privateGeneratedTarget))).setSrcs(ImmutableSortedSet.of()).setHeaderNamespace("name/space").build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node, privateGeneratedNode, publicGeneratedNode));
projectGenerator.createXcodeProjects();
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("name/space/yet/another/name.h", "foo/dir1/bar.h", "name/space/and/one/more.h", "foo/generated2.h"));
assertThat(headerSymlinkTrees.get(1).toString(), is(equalTo("buck-out/gen/_p/CwkbTNOBmb-priv")));
assertThatHeaderSymlinkTreeContains(Paths.get("buck-out/gen/_p/CwkbTNOBmb-priv"), ImmutableMap.of("name/space/any/name.h", "foo/dir1/foo.h", "name/space/different/name.h", "foo/dir2/baz.h", "name/space/one/more/name.h", "foo/generated1.h"));
}
use of com.facebook.buck.cxx.CxxLibraryBuilder in project buck by facebook.
the class ProjectGeneratorTest method testCxxLibraryCompilerAndPreprocessorFlags.
@Test
public void testCxxLibraryCompilerAndPreprocessorFlags() throws IOException {
BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
TargetNode<?, ?> node = new CxxLibraryBuilder(buildTarget).setCompilerFlags(ImmutableList.of("-ffoo")).setPreprocessorFlags(ImmutableList.of("-fbar")).setLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("-lbaz"))).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 -ffoo -fbar " + "-Wno-deprecated -Wno-conversion -ffoo -fbar", settings.get("OTHER_CFLAGS"));
assertEquals("-Wundeclared-selector -Wno-objc-designated-initializers -ffoo -fbar " + "-Wundeclared-selector -Wno-objc-designated-initializers -ffoo -fbar", settings.get("OTHER_CPLUSPLUSFLAGS"));
assertEquals("-lbaz -lbaz", settings.get("OTHER_LDFLAGS"));
}
use of com.facebook.buck.cxx.CxxLibraryBuilder in project buck by facebook.
the class ProjectGeneratorTest method testCxxLibraryExportedPreprocessorFlagsPropagate.
@Test
public void testCxxLibraryExportedPreprocessorFlagsPropagate() throws IOException {
BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
TargetNode<?, ?> node = new CxxLibraryBuilder(buildTarget).setExportedPreprocessorFlags(ImmutableList.of("-DHELLO")).build();
BuildTarget dependentBuildTarget = BuildTarget.builder(rootPath, "//foo", "bin").build();
TargetNode<?, ?> dependentNode = AppleBinaryBuilder.createBuilder(dependentBuildTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setPreprocessorFlags(ImmutableList.of("-D__APPLE__")).setDeps(ImmutableSortedSet.of(buildTarget)).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node, dependentNode), ImmutableSet.of());
projectGenerator.createXcodeProjects();
PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:bin");
ImmutableMap<String, String> settings = getBuildSettings(buildTarget, target, "Debug");
assertEquals("$(inherited) -Wno-deprecated -Wno-conversion -DHELLO -D__APPLE__", settings.get("OTHER_CFLAGS"));
}
use of com.facebook.buck.cxx.CxxLibraryBuilder in project buck by facebook.
the class ProjectGeneratorTest method testCxxLibraryWithListsOfHeadersAndCustomNamespace.
@Test
public void testCxxLibraryWithListsOfHeadersAndCustomNamespace() 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()).setHeaderNamespace("name/space").build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node));
projectGenerator.createXcodeProjects();
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("name/space/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("name/space/dir1/foo.h", "foo/dir1/foo.h").put("name/space/dir2/baz.h", "foo/dir2/baz.h").build());
}
use of com.facebook.buck.cxx.CxxLibraryBuilder in project buck by facebook.
the class ProjectGeneratorTest method testCxxLibraryRule.
@Test
public void testCxxLibraryRule() throws IOException {
BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
TargetNode<?, ?> cxxNode = new CxxLibraryBuilder(buildTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.cpp"), ImmutableList.of("-foo")), SourceWithFlags.of(new FakeSourcePath("bar.cpp")))).setHeaders(ImmutableSortedSet.of(new FakeSourcePath("foo.h"))).build();
ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(cxxNode));
projectGenerator.createXcodeProjects();
PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:lib");
assertThat(target.isa(), equalTo("PBXNativeTarget"));
assertThat(target.getProductType(), equalTo(ProductType.STATIC_LIBRARY));
assertHasConfigurations(target, "Debug", "Release", "Profile");
assertEquals("Should have exact number of build phases", 1, target.getBuildPhases().size());
assertHasSingletonSourcesPhaseWithSourcesAndFlags(target, ImmutableMap.of("foo.cpp", Optional.of("-foo"), "bar.cpp", Optional.empty()));
}
Aggregations