Search in sources :

Example 16 with PBXProject

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

the class ProjectGeneratorTest method shouldEmitFilesForBuildSettingPrefixedFrameworks.

@Test
public void shouldEmitFilesForBuildSettingPrefixedFrameworks() throws IOException {
    BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "rule").addFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR).build();
    TargetNode<?, ?> node = AppleLibraryBuilder.createBuilder(buildTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setLibraries(ImmutableSortedSet.of(FrameworkPath.ofSourceTreePath(new SourceTreePath(PBXReference.SourceTree.BUILT_PRODUCTS_DIR, Paths.get("libfoo.a"), Optional.empty())), FrameworkPath.ofSourceTreePath(new SourceTreePath(PBXReference.SourceTree.SDKROOT, Paths.get("libfoo.a"), Optional.empty())), FrameworkPath.ofSourceTreePath(new SourceTreePath(PBXReference.SourceTree.SOURCE_ROOT, Paths.get("libfoo.a"), Optional.empty())))).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node));
    projectGenerator.createXcodeProjects();
    PBXProject generatedProject = projectGenerator.getGeneratedProject();
    PBXTarget target = assertTargetExistsAndReturnTarget(generatedProject, "//foo:rule#shared");
    ProjectGeneratorTestUtils.assertHasSingletonFrameworksPhaseWithFrameworkEntries(target, ImmutableList.of("$BUILT_PRODUCTS_DIR/libfoo.a", "$SDKROOT/libfoo.a", "$SOURCE_ROOT/libfoo.a"));
}
Also used : SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) BuildTarget(com.facebook.buck.model.BuildTarget) PBXProject(com.facebook.buck.apple.xcode.xcodeproj.PBXProject) Test(org.junit.Test)

Example 17 with PBXProject

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

the class ProjectGeneratorTest method assetCatalogsInDependenciesPropogatesToBundles.

@Test
public void assetCatalogsInDependenciesPropogatesToBundles() throws IOException {
    BuildTarget assetCatalogTarget = BuildTarget.builder(rootPath, "//foo", "asset_catalog").build();
    TargetNode<?, ?> assetCatalogNode = AppleAssetCatalogBuilder.createBuilder(assetCatalogTarget).setDirs(ImmutableSortedSet.of(new FakeSourcePath("AssetCatalog.xcassets"))).build();
    BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setDeps(ImmutableSortedSet.of(assetCatalogTarget)).build();
    BuildTarget bundleLibraryTarget = BuildTarget.builder(rootPath, "//foo", "bundlelib").build();
    TargetNode<?, ?> bundleLibraryNode = AppleLibraryBuilder.createBuilder(bundleLibraryTarget).setDeps(ImmutableSortedSet.of(libraryTarget)).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(bundleLibraryTarget).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(assetCatalogNode, libraryNode, bundleLibraryNode, bundleNode));
    projectGenerator.createXcodeProjects();
    PBXProject generatedProject = projectGenerator.getGeneratedProject();
    PBXTarget target = assertTargetExistsAndReturnTarget(generatedProject, "//foo:bundle");
    assertHasSingletonResourcesPhaseWithEntries(target, "AssetCatalog.xcassets");
}
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) Test(org.junit.Test)

Example 18 with PBXProject

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

the class ProjectGeneratorTest method testHeaderSymlinkTreesWithHeadersVisibleForTesting.

@Test
public void testHeaderSymlinkTreesWithHeadersVisibleForTesting() throws IOException {
    BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    BuildTarget testTarget = BuildTarget.builder(rootPath, "//foo", "test").build();
    TargetNode<?, ?> libraryNode = AppleLibraryBuilder.createBuilder(libraryTarget).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.h"), ImmutableList.of("public")), SourceWithFlags.of(new FakeSourcePath("bar.h")))).setTests(ImmutableSortedSet.of(testTarget)).build();
    TargetNode<?, ?> testNode = AppleTestBuilder.createBuilder(testTarget).setConfigs(ImmutableSortedMap.of("Default", ImmutableMap.of())).setInfoPlist(new FakeSourcePath("Info.plist")).setDeps(ImmutableSortedSet.of(libraryTarget)).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(libraryNode, testNode));
    projectGenerator.createXcodeProjects();
    PBXProject project = projectGenerator.getGeneratedProject();
    PBXTarget testPBXTarget = assertTargetExistsAndReturnTarget(project, "//foo:test");
    ImmutableMap<String, String> buildSettings = getBuildSettings(testTarget, testPBXTarget, "Default");
    assertEquals("test binary should use header symlink trees for both public and non-public headers " + "of the tested library in HEADER_SEARCH_PATHS", "$(inherited) " + "../buck-out/gen/_p/LpygK8zq5F-priv/.hmap " + "../buck-out/gen/_p/LpygK8zq5F-pub/.hmap " + "../buck-out/gen/_p/CwkbTNOBmb-pub/.hmap " + "../buck-out/gen/_p/CwkbTNOBmb-priv/.hmap " + "../buck-out", buildSettings.get("HEADER_SEARCH_PATHS"));
    assertEquals("USER_HEADER_SEARCH_PATHS should not be set", null, buildSettings.get("USER_HEADER_SEARCH_PATHS"));
}
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) Test(org.junit.Test)

Example 19 with PBXProject

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

the class ProjectGeneratorTest method testAppleBundleRuleWithPreBuildScriptDependency.

@Test
public void testAppleBundleRuleWithPreBuildScriptDependency() throws IOException {
    BuildTarget scriptTarget = BuildTarget.builder(rootPath, "//foo", "pre_build_script").addFlavors(DEFAULT_FLAVOR).build();
    TargetNode<?, ?> scriptNode = XcodePrebuildScriptBuilder.createBuilder(scriptTarget).setCmd("script.sh").build();
    BuildTarget resourceTarget = BuildTarget.builder(rootPath, "//foo", "resource").build();
    TargetNode<?, ?> resourceNode = AppleResourceBuilder.createBuilder(resourceTarget).setFiles(ImmutableSet.of(new FakeSourcePath("bar.png"))).setDirs(ImmutableSet.of()).build();
    BuildTarget sharedLibraryTarget = BuildTarget.builder(rootPath, "//dep", "shared").addFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR).build();
    TargetNode<?, ?> sharedLibraryNode = AppleLibraryBuilder.createBuilder(sharedLibraryTarget).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(sharedLibraryTarget).setDeps(ImmutableSortedSet.of(scriptTarget)).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(scriptNode, resourceNode, sharedLibraryNode, bundleNode));
    projectGenerator.createXcodeProjects();
    PBXProject project = projectGenerator.getGeneratedProject();
    PBXTarget target = assertTargetExistsAndReturnTarget(project, "//foo:bundle");
    assertThat(target.getName(), equalTo("//foo:bundle"));
    assertThat(target.isa(), equalTo("PBXNativeTarget"));
    PBXShellScriptBuildPhase shellScriptBuildPhase = ProjectGeneratorTestUtils.getSingletonPhaseByType(target, PBXShellScriptBuildPhase.class);
    assertThat(shellScriptBuildPhase.getShellScript(), equalTo("script.sh"));
    // Assert that the pre-build script phase comes before resources are copied.
    assertThat(target.getBuildPhases().get(0), instanceOf(PBXShellScriptBuildPhase.class));
    assertThat(target.getBuildPhases().get(1), instanceOf(PBXResourcesBuildPhase.class));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) BuildTarget(com.facebook.buck.model.BuildTarget) PBXProject(com.facebook.buck.apple.xcode.xcodeproj.PBXProject) PBXResourcesBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXResourcesBuildPhase) Test(org.junit.Test)

Example 20 with PBXProject

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

the class ProjectGeneratorTest method resourceDirectoriesDontHaveFolderTypeIfTheyCanHaveAMoreSpecificType.

@Test
public void resourceDirectoriesDontHaveFolderTypeIfTheyCanHaveAMoreSpecificType() throws IOException {
    BuildTarget directoryTarget = BuildTarget.builder(rootPath, "//foo", "dir.iconset").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.iconset"));
    assertThat(resource.getExplicitFileType(), not(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)

Aggregations

PBXProject (com.facebook.buck.apple.xcode.xcodeproj.PBXProject)31 BuildTarget (com.facebook.buck.model.BuildTarget)27 Test (org.junit.Test)27 PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)18 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)18 NSString (com.dd.plist.NSString)14 PBXFileReference (com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)12 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)12 PBXGroup (com.facebook.buck.apple.xcode.xcodeproj.PBXGroup)11 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)6 Path (java.nio.file.Path)5 PBXReference (com.facebook.buck.apple.xcode.xcodeproj.PBXReference)4 PBXResourcesBuildPhase (com.facebook.buck.apple.xcode.xcodeproj.PBXResourcesBuildPhase)4 PBXShellScriptBuildPhase (com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase)4 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)4 PathSourcePath (com.facebook.buck.rules.PathSourcePath)4 SourcePath (com.facebook.buck.rules.SourcePath)3 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)3 NSDictionary (com.dd.plist.NSDictionary)2 PBXHeadersBuildPhase (com.facebook.buck.apple.xcode.xcodeproj.PBXHeadersBuildPhase)2