Search in sources :

Example 56 with PBXTarget

use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget 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 57 with PBXTarget

use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget 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 58 with PBXTarget

use of com.facebook.buck.apple.xcode.xcodeproj.PBXTarget 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 59 with PBXTarget

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

the class ProjectGeneratorTest method testAggregateTargetForBinaryForBuildWithBuck.

@Test
public void testAggregateTargetForBinaryForBuildWithBuck() throws IOException {
    BuildTarget binaryTarget = BuildTarget.builder(rootPath, "//foo", "binary").build();
    TargetNode<?, ?> binaryNode = AppleBinaryBuilder.createBuilder(binaryTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("foo.m"), ImmutableList.of("-foo")))).build();
    ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(binaryNode);
    final TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes);
    final AppleDependenciesCache cache = new AppleDependenciesCache(targetGraph);
    ProjectGenerator projectGenerator = new ProjectGenerator(targetGraph, cache, nodes.stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet()), projectCell, OUTPUT_DIRECTORY, PROJECT_NAME, "BUCK", ImmutableSet.of(), Optional.of(binaryTarget), ImmutableList.of("--flag", "value with spaces"), false, Optional.empty(), ImmutableSet.of(), Optional.empty(), new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, getBuildRuleResolverNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
    projectGenerator.createXcodeProjects();
    PBXTarget buildWithBuckTarget = null;
    for (PBXTarget target : projectGenerator.getGeneratedProject().getTargets()) {
        if (target.getProductName() != null && target.getProductName().endsWith("-Buck")) {
            buildWithBuckTarget = target;
        }
    }
    assertThat(buildWithBuckTarget, is(notNullValue()));
    assertHasConfigurations(buildWithBuckTarget, "Debug");
    assertKeepsConfigurationsInMainGroup(projectGenerator.getGeneratedProject(), buildWithBuckTarget);
    assertEquals("Should have exact number of build phases", 1, buildWithBuckTarget.getBuildPhases().size());
    PBXBuildPhase buildPhase = Iterables.getOnlyElement(buildWithBuckTarget.getBuildPhases());
    assertThat(buildPhase, instanceOf(PBXShellScriptBuildPhase.class));
    PBXShellScriptBuildPhase shellScriptBuildPhase = (PBXShellScriptBuildPhase) buildPhase;
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("buck -- \"--show-output --report-absolute-paths --flag 'value with spaces'\" " + binaryTarget.getFullyQualifiedName() + " dwarf dwarf-and-dsym"));
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    Path fixUUIDScriptPath = ProjectGenerator.getFixUUIDScriptPath(filesystem);
    assertThat(shellScriptBuildPhase.getShellScript(), containsString("python " + fixUUIDScriptPath + " --verbose " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/binary-unsanitised/binary.app") + " " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/binary-unsanitised/binary.dSYM") + " " + binaryTarget.getShortName()));
}
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) TargetNode(com.facebook.buck.rules.TargetNode) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) BuildTarget(com.facebook.buck.model.BuildTarget) PBXBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase) AppleDependenciesCache(com.facebook.buck.apple.AppleDependenciesCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 60 with PBXTarget

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

the class ProjectGeneratorTest method testAppleLibraryDoesntOverrideHeaderOutputPath.

@Test
public void testAppleLibraryDoesntOverrideHeaderOutputPath() throws IOException {
    BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> node = AppleLibraryBuilder.createBuilder(buildTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of("PUBLIC_HEADERS_FOLDER_PATH", "FooHeaders"))).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node), ImmutableSet.of());
    projectGenerator.createXcodeProjects();
    PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:lib");
    assertThat(target.isa(), equalTo("PBXNativeTarget"));
    assertThat(target.getProductType(), equalTo(ProductType.STATIC_LIBRARY));
    ImmutableMap<String, String> settings = getBuildSettings(buildTarget, target, "Debug");
    assertEquals("$SYMROOT/$CONFIGURATION$EFFECTIVE_PLATFORM_NAME", settings.get("BUILT_PRODUCTS_DIR"));
    assertEquals("$BUILT_PRODUCTS_DIR", settings.get("CONFIGURATION_BUILD_DIR"));
    assertEquals("FooHeaders", settings.get("PUBLIC_HEADERS_FOLDER_PATH"));
}
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)

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