Search in sources :

Example 6 with PBXGroup

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

the class ProjectGeneratorTest method assertKeepsConfigurationsInMainGroup.

private void assertKeepsConfigurationsInMainGroup(PBXProject project, PBXTarget target) {
    Map<String, XCBuildConfiguration> buildConfigurationMap = target.getBuildConfigurationList().getBuildConfigurationsByName().asMap();
    PBXGroup configsGroup = project.getMainGroup().getOrCreateChildGroupByName("Configurations").getOrCreateChildGroupByName("Buck (Do Not Modify)");
    assertNotNull("Configuration group exists", configsGroup);
    List<PBXReference> configReferences = configsGroup.getChildren();
    assertFalse("Configuration file references exist", configReferences.isEmpty());
    for (XCBuildConfiguration configuration : buildConfigurationMap.values()) {
        String path = configuration.getBaseConfigurationReference().getPath();
        PBXReference foundReference = null;
        for (PBXReference reference : configReferences) {
            assertTrue("References in the configuration group should point to xcconfigs", reference.getPath().endsWith(".xcconfig"));
            if (reference.getPath().equals(path)) {
                foundReference = reference;
                break;
            }
        }
        assertNotNull("File reference for configuration " + path + " should be in main group", foundReference);
    }
}
Also used : XCBuildConfiguration(com.facebook.buck.apple.xcode.xcodeproj.XCBuildConfiguration) PBXReference(com.facebook.buck.apple.xcode.xcodeproj.PBXReference) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString)

Example 7 with PBXGroup

use of com.facebook.buck.apple.xcode.xcodeproj.PBXGroup 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)

Example 8 with PBXGroup

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

the class ProjectGeneratorTest method testCreateDirectoryStructure.

@Test
public void testCreateDirectoryStructure() throws IOException {
    BuildTarget buildTarget1 = BuildTarget.builder(rootPath, "//foo/bar", "target1").build();
    TargetNode<?, ?> node1 = AppleLibraryBuilder.createBuilder(buildTarget1).build();
    BuildTarget buildTarget2 = BuildTarget.builder(rootPath, "//foo/foo", "target2").build();
    TargetNode<?, ?> node2 = AppleLibraryBuilder.createBuilder(buildTarget2).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node1, node2), ImmutableSet.of(ProjectGenerator.Option.CREATE_DIRECTORY_STRUCTURE, ProjectGenerator.Option.USE_SHORT_NAMES_FOR_TARGETS));
    projectGenerator.createXcodeProjects();
    PBXProject project = projectGenerator.getGeneratedProject();
    PBXGroup mainGroup = project.getMainGroup();
    PBXGroup groupFoo = null;
    for (PBXReference reference : mainGroup.getChildren()) {
        if (reference instanceof PBXGroup && "foo".equals(reference.getName())) {
            groupFoo = (PBXGroup) reference;
        }
    }
    assertNotNull("Project should have a group called foo", groupFoo);
    assertEquals("foo", groupFoo.getName());
    assertThat(groupFoo.getChildren(), hasSize(2));
    PBXGroup groupFooBar = (PBXGroup) Iterables.get(groupFoo.getChildren(), 0);
    assertEquals("bar", groupFooBar.getName());
    assertThat(groupFooBar.getChildren(), hasSize(1));
    PBXGroup groupFooFoo = (PBXGroup) Iterables.get(groupFoo.getChildren(), 1);
    assertEquals("foo", groupFooFoo.getName());
    assertThat(groupFooFoo.getChildren(), hasSize(1));
    PBXGroup groupFooBarTarget1 = (PBXGroup) Iterables.get(groupFooBar.getChildren(), 0);
    assertEquals("target1", groupFooBarTarget1.getName());
    PBXGroup groupFooFooTarget2 = (PBXGroup) Iterables.get(groupFooFoo.getChildren(), 0);
    assertEquals("target2", groupFooFooTarget2.getName());
}
Also used : PBXReference(com.facebook.buck.apple.xcode.xcodeproj.PBXReference) BuildTarget(com.facebook.buck.model.BuildTarget) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) PBXProject(com.facebook.buck.apple.xcode.xcodeproj.PBXProject) Test(org.junit.Test)

Example 9 with PBXGroup

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

the class ProjectGeneratorTest method testRuleAddsReference.

private void testRuleAddsReference(BuildTarget ruleTarget, TargetNode<?, ?> ruleNode, String path) throws IOException {
    BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setDeps(ImmutableSortedSet.of(ruleTarget)).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(ruleNode, libraryNode));
    projectGenerator.createXcodeProjects();
    PBXProject project = projectGenerator.getGeneratedProject();
    PBXGroup targetGroup = project.getMainGroup().getOrCreateChildGroupByName(libraryTarget.getFullyQualifiedName());
    PBXGroup resourcesGroup = targetGroup.getOrCreateChildGroupByName("Resources");
    assertThat(resourcesGroup.getChildren(), hasSize(1));
    PBXFileReference ruleReference = (PBXFileReference) Iterables.get(resourcesGroup.getChildren(), 0);
    assertEquals(path, ruleReference.getName());
}
Also used : 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)

Example 10 with PBXGroup

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

the class ProjectGeneratorTest method testAssetCatalogsUnderLibraryNotTest.

@Test
public void testAssetCatalogsUnderLibraryNotTest() throws IOException {
    BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    BuildTarget testTarget = BuildTarget.builder(rootPath, "//foo", "test").build();
    BuildTarget assetCatalogTarget = BuildTarget.builder(rootPath, "//foo", "asset_catalog").build();
    TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setTests(ImmutableSortedSet.of(testTarget)).setDeps(ImmutableSortedSet.of(assetCatalogTarget)).build();
    TargetNode<?, ?> testNode = AppleTestBuilder.createBuilder(testTarget).setConfigs(ImmutableSortedMap.of("Default", ImmutableMap.of())).setInfoPlist(new FakeSourcePath("Info.plist")).setDeps(ImmutableSortedSet.of(libraryTarget)).build();
    TargetNode<?, ?> assetCatalogNode = AppleAssetCatalogBuilder.createBuilder(assetCatalogTarget).setDirs(ImmutableSortedSet.of(new FakeSourcePath("AssetCatalog.xcassets"))).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(libraryNode, testNode, assetCatalogNode), ImmutableSet.of(ProjectGenerator.Option.USE_SHORT_NAMES_FOR_TARGETS));
    projectGenerator.createXcodeProjects();
    PBXProject project = projectGenerator.getGeneratedProject();
    PBXGroup mainGroup = project.getMainGroup();
    PBXTarget fooLibTarget = assertTargetExistsAndReturnTarget(project, "lib");
    assertTrue(FluentIterable.from(fooLibTarget.getBuildPhases()).filter(PBXResourcesBuildPhase.class).isEmpty());
    PBXGroup libResourcesGroup = mainGroup.getOrCreateChildGroupByName("lib").getOrCreateChildGroupByName("Resources");
    PBXFileReference assetCatalogFile = (PBXFileReference) libResourcesGroup.getChildren().get(0);
    assertEquals("AssetCatalog.xcassets", assetCatalogFile.getName());
    PBXTarget fooTestTarget = assertTargetExistsAndReturnTarget(project, "test");
    PBXResourcesBuildPhase resourcesBuildPhase = ProjectGeneratorTestUtils.getSingletonPhaseByType(fooTestTarget, PBXResourcesBuildPhase.class);
    assertThat(resourcesBuildPhase.getFiles(), hasSize(1));
    assertThat(assertFileRefIsRelativeAndResolvePath(resourcesBuildPhase.getFiles().get(0).getFileRef()), equalTo(projectFilesystem.resolve("AssetCatalog.xcassets").toString()));
    PBXGroup testResourcesGroup = mainGroup.getOrCreateChildGroupByName("test").getOrCreateChildGroupByName("Resources");
    assetCatalogFile = (PBXFileReference) testResourcesGroup.getChildren().get(0);
    assertEquals("AssetCatalog.xcassets", assetCatalogFile.getName());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) 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) PBXResourcesBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXResourcesBuildPhase) 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