Search in sources :

Example 11 with PBXGroup

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

the class ProjectGeneratorTest method resourceDirectoriesHaveFolderType.

@Test
public void resourceDirectoriesHaveFolderType() throws IOException {
    BuildTarget directoryTarget = BuildTarget.builder(rootPath, "//foo", "dir").build();
    BuildTarget resourceTarget = BuildTarget.builder(rootPath, "//foo", "res").build();
    BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> directoryNode = ExportFileBuilder.newExportFileBuilder(directoryTarget).build();
    TargetNode<?, ?> resourceNode = AppleResourceBuilder.createBuilder(resourceTarget).setDirs(ImmutableSet.of(new DefaultBuildTargetSourcePath(directoryTarget))).setFiles(ImmutableSet.of()).build();
    TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setDeps(ImmutableSortedSet.of(resourceTarget)).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(directoryNode, resourceNode, libraryNode));
    projectGenerator.createXcodeProjects();
    PBXProject project = projectGenerator.getGeneratedProject();
    PBXGroup mainGroup = project.getMainGroup();
    PBXGroup resourcesGroup = mainGroup.getOrCreateDescendantGroupByPath(ImmutableList.of("//foo:lib", "Resources"));
    PBXFileReference resource = (PBXFileReference) Iterables.get(resourcesGroup.getChildren(), 0);
    assertThat(resource.getName(), equalTo("dir"));
    assertThat(resource.getExplicitFileType(), equalTo(Optional.of("folder")));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) 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 PBXGroup

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

the class NewNativeTargetProjectMutatorTest method testLibraryHeaderGroups.

@Test
public void testLibraryHeaderGroups() throws NoSuchBuildTargetException {
    NewNativeTargetProjectMutator mutator = mutatorWithCommonDefaults();
    SourcePath foo = new FakeSourcePath("HeaderGroup1/foo.h");
    SourcePath bar = new FakeSourcePath("HeaderGroup1/bar.h");
    SourcePath baz = new FakeSourcePath("HeaderGroup2/baz.h");
    mutator.setPublicHeaders(ImmutableSet.of(bar, baz));
    mutator.setPrivateHeaders(ImmutableSet.of(foo));
    NewNativeTargetProjectMutator.Result result = mutator.buildTargetAndAddToProject(generatedProject, true);
    PBXGroup sourcesGroup = result.targetGroup.get().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 fileRefBar = (PBXFileReference) Iterables.get(group1.getChildren(), 0);
    assertEquals("bar.h", fileRefBar.getName());
    PBXFileReference fileRefFoo = (PBXFileReference) Iterables.get(group1.getChildren(), 1);
    assertEquals("foo.h", fileRefFoo.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());
}
Also used : PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference) Test(org.junit.Test)

Example 13 with PBXGroup

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

the class ProjectGeneratorTest method testAppleResourceWithVariantGroupSetsFileTypeBasedOnPath.

@Test
public void testAppleResourceWithVariantGroupSetsFileTypeBasedOnPath() throws IOException {
    BuildTarget resourceTarget = BuildTarget.builder(rootPath, "//foo", "resource").addFlavors(DEFAULT_FLAVOR).build();
    TargetNode<?, ?> resourceNode = AppleResourceBuilder.createBuilder(resourceTarget).setFiles(ImmutableSet.of()).setDirs(ImmutableSet.of()).setVariants(ImmutableSet.of(new FakeSourcePath("Base.lproj/Bar.storyboard"))).build();
    BuildTarget fooLibraryTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> fooLibraryNode = AppleLibraryBuilder.createBuilder(fooLibraryTarget).setDeps(ImmutableSortedSet.of(resourceTarget)).build();
    BuildTarget bundleTarget = BuildTarget.builder(rootPath, "//foo", "bundle").build();
    TargetNode<?, ?> bundleNode = AppleBundleBuilder.createBuilder(bundleTarget).setExtension(Either.ofLeft(AppleBundleExtension.BUNDLE)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(fooLibraryTarget).setDeps(ImmutableSortedSet.of(resourceTarget)).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(fooLibraryNode, bundleNode, resourceNode), ImmutableSet.of());
    projectGenerator.createXcodeProjects();
    PBXProject project = projectGenerator.getGeneratedProject();
    PBXGroup targetGroup = project.getMainGroup().getOrCreateChildGroupByName(bundleTarget.getFullyQualifiedName());
    PBXGroup resourcesGroup = targetGroup.getOrCreateChildGroupByName("Resources");
    PBXVariantGroup storyboardGroup = (PBXVariantGroup) Iterables.get(resourcesGroup.getChildren(), 0);
    List<PBXReference> storyboardGroupChildren = storyboardGroup.getChildren();
    assertEquals(1, storyboardGroupChildren.size());
    assertTrue(storyboardGroupChildren.get(0) instanceof PBXFileReference);
    PBXFileReference baseStoryboardReference = (PBXFileReference) storyboardGroupChildren.get(0);
    assertEquals("Base", baseStoryboardReference.getName());
    // Make sure the file type is set from the path.
    assertEquals(Optional.of("file.storyboard"), baseStoryboardReference.getLastKnownFileType());
    assertEquals(Optional.empty(), baseStoryboardReference.getExplicitFileType());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXReference(com.facebook.buck.apple.xcode.xcodeproj.PBXReference) PBXVariantGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXVariantGroup) BuildTarget(com.facebook.buck.model.BuildTarget) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) PBXProject(com.facebook.buck.apple.xcode.xcodeproj.PBXProject) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference) Test(org.junit.Test)

Example 14 with PBXGroup

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

the class NewNativeTargetProjectMutatorTest method shouldCreateTargetAndCustomTargetGroup.

@Test
public void shouldCreateTargetAndCustomTargetGroup() throws NoSuchBuildTargetException {
    NewNativeTargetProjectMutator mutator = new NewNativeTargetProjectMutator(pathRelativizer, sourcePathResolver::getRelativePath);
    mutator.setTargetName("TestTarget").setTargetGroupPath(ImmutableList.of("Grandparent", "Parent")).setProduct(ProductType.BUNDLE, "TestTargetProduct", Paths.get("TestTargetProduct.bundle")).buildTargetAndAddToProject(generatedProject, true);
    assertTargetExistsAndReturnTarget(generatedProject, "TestTarget");
    PBXGroup grandparentGroup = assertHasSubgroupAndReturnIt(generatedProject.getMainGroup(), "Grandparent");
    assertHasSubgroupAndReturnIt(grandparentGroup, "Parent");
}
Also used : PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) Test(org.junit.Test)

Example 15 with PBXGroup

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

the class NewNativeTargetProjectMutatorTest method testSourceGroups.

@Test
public void testSourceGroups() throws NoSuchBuildTargetException {
    NewNativeTargetProjectMutator mutator = mutatorWithCommonDefaults();
    SourcePath foo = new FakeSourcePath("Group1/foo.m");
    SourcePath bar = new FakeSourcePath("Group1/bar.m");
    SourcePath baz = new FakeSourcePath("Group2/baz.m");
    mutator.setSourcesWithFlags(ImmutableSet.of(SourceWithFlags.of(foo), SourceWithFlags.of(bar, ImmutableList.of("-Wall")), SourceWithFlags.of(baz)));
    NewNativeTargetProjectMutator.Result result = mutator.buildTargetAndAddToProject(generatedProject, true);
    PBXGroup sourcesGroup = result.targetGroup.get().getOrCreateChildGroupByName("Sources");
    PBXGroup group1 = (PBXGroup) Iterables.get(sourcesGroup.getChildren(), 0);
    assertEquals("Group1", group1.getName());
    assertThat(group1.getChildren(), hasSize(2));
    PBXFileReference fileRefBar = (PBXFileReference) Iterables.get(group1.getChildren(), 0);
    assertEquals("bar.m", fileRefBar.getName());
    PBXFileReference fileRefFoo = (PBXFileReference) Iterables.get(group1.getChildren(), 1);
    assertEquals("foo.m", fileRefFoo.getName());
    PBXGroup group2 = (PBXGroup) Iterables.get(sourcesGroup.getChildren(), 1);
    assertEquals("Group2", group2.getName());
    assertThat(group2.getChildren(), hasSize(1));
    PBXFileReference fileRefBaz = (PBXFileReference) Iterables.get(group2.getChildren(), 0);
    assertEquals("baz.m", fileRefBaz.getName());
}
Also used : PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) PBXFileReference(com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference) Test(org.junit.Test)

Aggregations

PBXGroup (com.facebook.buck.apple.xcode.xcodeproj.PBXGroup)25 PBXFileReference (com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)17 Test (org.junit.Test)14 BuildTarget (com.facebook.buck.model.BuildTarget)13 PBXProject (com.facebook.buck.apple.xcode.xcodeproj.PBXProject)11 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)10 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)9 SourcePath (com.facebook.buck.rules.SourcePath)9 NSString (com.dd.plist.NSString)8 PathSourcePath (com.facebook.buck.rules.PathSourcePath)7 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)7 Path (java.nio.file.Path)6 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)5 PBXReference (com.facebook.buck.apple.xcode.xcodeproj.PBXReference)4 PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)4 AppleWrapperResourceArg (com.facebook.buck.apple.AppleWrapperResourceArg)3 PBXHeadersBuildPhase (com.facebook.buck.apple.xcode.xcodeproj.PBXHeadersBuildPhase)3 HumanReadableException (com.facebook.buck.util.HumanReadableException)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 NSDictionary (com.dd.plist.NSDictionary)2