Search in sources :

Example 11 with PBXTarget

use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.

the class ProjectGeneratorTest method testAppleLibraryHeaderGroupsWithMappedHeaders.

@Test
public void testAppleLibraryHeaderGroupsWithMappedHeaders() 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 = AppleLibraryBuilder.createBuilder(buildTarget).setSrcs(ImmutableSortedSet.of()).setHeaders(ImmutableSortedMap.of("any/name.h", new FakeSourcePath("HeaderGroup1/foo.h"), "different/name.h", new FakeSourcePath("HeaderGroup2/baz.h"), "one/more/name.h", new DefaultBuildTargetSourcePath(privateGeneratedTarget))).setExportedHeaders(ImmutableSortedMap.of("yet/another/name.h", new FakeSourcePath("HeaderGroup1/bar.h"), "and/one/more.h", new DefaultBuildTargetSourcePath(publicGeneratedTarget))).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node, privateGeneratedNode, publicGeneratedNode));
    projectGenerator.createXcodeProjects();
    PBXProject project = projectGenerator.getGeneratedProject();
    PBXGroup targetGroup = project.getMainGroup().getOrCreateChildGroupByName(buildTarget.getFullyQualifiedName());
    PBXGroup sourcesGroup = targetGroup.getOrCreateChildGroupByName("Sources");
    assertThat(sourcesGroup.getChildren(), hasSize(3));
    PBXGroup group1 = (PBXGroup) Iterables.get(sourcesGroup.getChildren(), 0);
    assertEquals("HeaderGroup1", group1.getName());
    assertThat(group1.getChildren(), hasSize(2));
    PBXFileReference fileRefFoo = (PBXFileReference) Iterables.get(group1.getChildren(), 0);
    assertEquals("bar.h", fileRefFoo.getName());
    PBXFileReference fileRefBar = (PBXFileReference) Iterables.get(group1.getChildren(), 1);
    assertEquals("foo.h", fileRefBar.getName());
    PBXGroup group2 = (PBXGroup) Iterables.get(sourcesGroup.getChildren(), 1);
    assertEquals("HeaderGroup2", group2.getName());
    assertThat(group2.getChildren(), hasSize(1));
    PBXFileReference fileRefBaz = (PBXFileReference) Iterables.get(group2.getChildren(), 0);
    assertEquals("baz.h", fileRefBaz.getName());
    PBXGroup group3 = (PBXGroup) Iterables.get(sourcesGroup.getChildren(), 2);
    assertEquals("foo", group3.getName());
    assertThat(group3.getChildren(), hasSize(2));
    PBXFileReference fileRefGenerated1 = (PBXFileReference) Iterables.get(group3.getChildren(), 0);
    assertEquals("generated1.h", fileRefGenerated1.getName());
    PBXFileReference fileRefGenerated2 = (PBXFileReference) Iterables.get(group3.getChildren(), 1);
    assertEquals("generated2.h", fileRefGenerated2.getName());
    // There should be no PBXHeadersBuildPhase in the 'Buck header map mode'.
    PBXTarget target = assertTargetExistsAndReturnTarget(project, "//foo:lib");
    assertEquals(0, target.getBuildPhases().stream().filter(input -> input instanceof PBXHeadersBuildPhase).count());
    List<Path> headerSymlinkTrees = projectGenerator.getGeneratedHeaderSymlinkTrees();
    assertThat(headerSymlinkTrees, hasSize(2));
    assertEquals("buck-out/gen/_p/CwkbTNOBmb-pub", headerSymlinkTrees.get(0).toString());
    assertThatHeaderSymlinkTreeContains(Paths.get("buck-out/gen/_p/CwkbTNOBmb-pub"), ImmutableMap.of("yet/another/name.h", "HeaderGroup1/bar.h", "and/one/more.h", "foo/generated2.h"));
    assertEquals("buck-out/gen/_p/CwkbTNOBmb-priv", headerSymlinkTrees.get(1).toString());
    assertThatHeaderSymlinkTreeContains(Paths.get("buck-out/gen/_p/CwkbTNOBmb-priv"), ImmutableMap.of("any/name.h", "HeaderGroup1/foo.h", "different/name.h", "HeaderGroup2/baz.h", "one/more/name.h", "foo/generated1.h"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) 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) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) PBXHeadersBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXHeadersBuildPhase) PBXProject(com.facebook.buck.apple.xcode.xcodeproj.PBXProject) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference) Test(org.junit.Test)

Example 12 with PBXTarget

use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.

the class ProjectGeneratorTest method testAppleLibraryWithoutSources.

@Test
public void testAppleLibraryWithoutSources() throws IOException {
    BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setFrameworks(ImmutableSortedSet.of(FrameworkPath.ofSourceTreePath(new SourceTreePath(PBXReference.SourceTree.SDKROOT, Paths.get("Library.framework"), Optional.empty())))).build();
    BuildTarget testTarget = BuildTarget.builder(rootPath, "//foo", "xctest").build();
    TargetNode<?, ?> testNode = AppleTestBuilder.createBuilder(testTarget).setInfoPlist(new FakeSourcePath("Info.plist")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("fooTest.m")))).setDeps(ImmutableSortedSet.of(libraryTarget)).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(libraryNode, testNode), ImmutableSet.of());
    projectGenerator.createXcodeProjects();
    PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:xctest");
    assertEquals("Should have exact number of build phases", 2, target.getBuildPhases().size());
    assertHasSingletonSourcesPhaseWithSourcesAndFlags(target, ImmutableMap.of("fooTest.m", Optional.empty()));
    ProjectGeneratorTestUtils.assertHasSingletonFrameworksPhaseWithFrameworkEntries(target, ImmutableList.of("$SDKROOT/Library.framework"));
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) BuildTarget(com.facebook.buck.model.BuildTarget) Test(org.junit.Test)

Example 13 with PBXTarget

use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.

the class ProjectGeneratorTest method testAppleLibraryExportedLinkerFlagsPropagate.

@Test
public void testAppleLibraryExportedLinkerFlagsPropagate() throws IOException {
    BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> node = AppleLibraryBuilder.createBuilder(buildTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setExportedLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("-Xlinker"), StringWithMacrosUtils.format("-lhello"))).build();
    BuildTarget dependentBuildTarget = BuildTarget.builder(rootPath, "//foo", "bin").build();
    TargetNode<?, ?> dependentNode = AppleBinaryBuilder.createBuilder(dependentBuildTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).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) -Xlinker -lhello", settings.get("OTHER_LDFLAGS"));
}
Also used : PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) BuildTarget(com.facebook.buck.model.BuildTarget) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString) Test(org.junit.Test)

Example 14 with PBXTarget

use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.

the class ProjectGeneratorTest method testAppleBundleRuleWithCustomXcodeProductType.

@Test
public void testAppleBundleRuleWithCustomXcodeProductType() throws IOException {
    BuildTarget sharedLibraryTarget = BuildTarget.builder(rootPath, "//dep", "shared").addFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR).build();
    TargetNode<?, ?> sharedLibraryNode = AppleLibraryBuilder.createBuilder(sharedLibraryTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).build();
    BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "custombundle").build();
    TargetNode<?, ?> node = AppleBundleBuilder.createBuilder(buildTarget).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(sharedLibraryTarget).setXcodeProductType(Optional.of("com.facebook.buck.niftyProductType")).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(sharedLibraryNode, node), ImmutableSet.of());
    projectGenerator.createXcodeProjects();
    PBXProject project = projectGenerator.getGeneratedProject();
    PBXTarget target = assertTargetExistsAndReturnTarget(project, "//foo:custombundle");
    assertEquals(target.getProductType(), ProductType.of("com.facebook.buck.niftyProductType"));
    assertThat(target.isa(), equalTo("PBXNativeTarget"));
    PBXFileReference productReference = target.getProductReference();
    assertEquals("custombundle.framework", productReference.getName());
    assertEquals(Optional.of("wrapper.framework"), productReference.getExplicitFileType());
    ImmutableMap<String, String> settings = getBuildSettings(buildTarget, target, "Debug");
    assertEquals("framework", settings.get("WRAPPER_EXTENSION"));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) BuildTarget(com.facebook.buck.model.BuildTarget) PBXProject(com.facebook.buck.apple.xcode.xcodeproj.PBXProject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference) Test(org.junit.Test)

Example 15 with PBXTarget

use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget in project buck by facebook.

the class ProjectGeneratorTest method testAppleLibraryHeaderGroupsWithHeaderSymlinkTrees.

@Test
public void testAppleLibraryHeaderGroupsWithHeaderSymlinkTrees() throws IOException {
    BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> node = AppleLibraryBuilder.createBuilder(buildTarget).setSrcs(ImmutableSortedSet.of()).setHeaders(ImmutableSortedSet.of(new FakeSourcePath("HeaderGroup1/foo.h"), new FakeSourcePath("HeaderGroup2/baz.h"))).setExportedHeaders(ImmutableSortedSet.of(new FakeSourcePath("HeaderGroup1/bar.h"))).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node));
    projectGenerator.createXcodeProjects();
    PBXProject project = projectGenerator.getGeneratedProject();
    PBXGroup targetGroup = project.getMainGroup().getOrCreateChildGroupByName(buildTarget.getFullyQualifiedName());
    PBXGroup sourcesGroup = targetGroup.getOrCreateChildGroupByName("Sources");
    assertThat(sourcesGroup.getChildren(), hasSize(2));
    PBXGroup group1 = (PBXGroup) Iterables.get(sourcesGroup.getChildren(), 0);
    assertEquals("HeaderGroup1", group1.getName());
    assertThat(group1.getChildren(), hasSize(2));
    PBXFileReference fileRefFoo = (PBXFileReference) Iterables.get(group1.getChildren(), 0);
    assertEquals("bar.h", fileRefFoo.getName());
    PBXFileReference fileRefBar = (PBXFileReference) Iterables.get(group1.getChildren(), 1);
    assertEquals("foo.h", fileRefBar.getName());
    PBXGroup group2 = (PBXGroup) Iterables.get(sourcesGroup.getChildren(), 1);
    assertEquals("HeaderGroup2", group2.getName());
    assertThat(group2.getChildren(), hasSize(1));
    PBXFileReference fileRefBaz = (PBXFileReference) Iterables.get(group2.getChildren(), 0);
    assertEquals("baz.h", fileRefBaz.getName());
    // There should be no PBXHeadersBuildPhase in the 'Buck header map mode'.
    PBXTarget target = assertTargetExistsAndReturnTarget(project, "//foo:lib");
    assertEquals(0, target.getBuildPhases().stream().filter(input -> input instanceof PBXHeadersBuildPhase).count());
    List<Path> headerSymlinkTrees = projectGenerator.getGeneratedHeaderSymlinkTrees();
    assertThat(headerSymlinkTrees, hasSize(2));
    assertEquals("buck-out/gen/_p/CwkbTNOBmb-pub", headerSymlinkTrees.get(0).toString());
    assertThatHeaderSymlinkTreeContains(Paths.get("buck-out/gen/_p/CwkbTNOBmb-pub"), ImmutableMap.of("lib/bar.h", "HeaderGroup1/bar.h"));
    assertEquals("buck-out/gen/_p/CwkbTNOBmb-priv", headerSymlinkTrees.get(1).toString());
    assertThatHeaderSymlinkTreeContains(Paths.get("buck-out/gen/_p/CwkbTNOBmb-priv"), ImmutableMap.<String, String>builder().put("lib/foo.h", "HeaderGroup1/foo.h").put("lib/baz.h", "HeaderGroup2/baz.h").put("foo.h", "HeaderGroup1/foo.h").put("bar.h", "HeaderGroup1/bar.h").put("baz.h", "HeaderGroup2/baz.h").build());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) 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) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) PBXHeadersBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXHeadersBuildPhase) PBXProject(com.facebook.buck.apple.xcode.xcodeproj.PBXProject) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference) Test(org.junit.Test)

Aggregations

PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)85 Test (org.junit.Test)79 BuildTarget (com.facebook.buck.model.BuildTarget)68 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)47 NSString (com.dd.plist.NSString)40 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)39 Path (java.nio.file.Path)21 PBXFileReference (com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)19 PBXProject (com.facebook.buck.apple.xcode.xcodeproj.PBXProject)19 ImmutableMap (com.google.common.collect.ImmutableMap)18 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)13 PBXNativeTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXNativeTarget)11 DocumentBuilder (javax.xml.parsers.DocumentBuilder)11 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)11 XPath (javax.xml.xpath.XPath)11 XPathExpression (javax.xml.xpath.XPathExpression)11 XPathFactory (javax.xml.xpath.XPathFactory)11 Document (org.w3c.dom.Document)11 NodeList (org.w3c.dom.NodeList)11 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)10