Search in sources :

Example 1 with CxxLibraryBuilder

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"));
}
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) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) Test(org.junit.Test)

Example 2 with CxxLibraryBuilder

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"));
}
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 3 with CxxLibraryBuilder

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"));
}
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 4 with CxxLibraryBuilder

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());
}
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 5 with CxxLibraryBuilder

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()));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) BuildTarget(com.facebook.buck.model.BuildTarget) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) 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