Search in sources :

Example 81 with PBXTarget

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

the class ProjectGeneratorTest method testCxxLibraryPlatformFlags.

@Test
public void testCxxLibraryPlatformFlags() throws IOException {
    BuildTarget buildTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    TargetNode<?, ?> node = new CxxLibraryBuilder(buildTarget).setPlatformCompilerFlags(PatternMatchedCollection.<ImmutableList<String>>builder().add(Pattern.compile("android.*"), ImmutableList.of("-ffoo-android")).add(Pattern.compile("iphone.*"), ImmutableList.of("-ffoo-iphone")).add(Pattern.compile("macosx.*"), ImmutableList.of("-ffoo-macosx")).build()).setPlatformPreprocessorFlags(PatternMatchedCollection.<ImmutableList<String>>builder().add(Pattern.compile("android.*"), ImmutableList.of("-fbar-android")).add(Pattern.compile("iphone.*"), ImmutableList.of("-fbar-iphone")).add(Pattern.compile("macosx.*"), ImmutableList.of("-fbar-macosx")).build()).setPlatformLinkerFlags(PatternMatchedCollection.<ImmutableList<StringWithMacros>>builder().add(Pattern.compile("android.*"), ImmutableList.of(StringWithMacrosUtils.format("-lbaz-android"))).add(Pattern.compile("iphone.*"), ImmutableList.of(StringWithMacrosUtils.format("-lbaz-iphone"))).add(Pattern.compile("macosx.*"), ImmutableList.of(StringWithMacrosUtils.format("-lbaz-macosx"))).build()).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node), ImmutableSet.of());
    projectGenerator.createXcodeProjects();
    PBXTarget target = assertTargetExistsAndReturnTarget(projectGenerator.getGeneratedProject(), "//foo:lib");
    assertHasConfigurations(target, "Debug", "Release", "Profile");
    ImmutableMap<String, String> settings = ProjectGeneratorTestUtils.getBuildSettings(projectFilesystem, buildTarget, target, "Debug");
    assertEquals("-Wno-deprecated -Wno-conversion -Wno-deprecated -Wno-conversion", settings.get("OTHER_CFLAGS"));
    assertEquals("-Wundeclared-selector -Wno-objc-designated-initializers " + "-Wundeclared-selector -Wno-objc-designated-initializers", settings.get("OTHER_CPLUSPLUSFLAGS"));
    assertEquals("$(inherited) ", settings.get("OTHER_LDFLAGS"));
    assertEquals("-Wno-deprecated -Wno-conversion -ffoo-iphone -fbar-iphone " + "-Wno-deprecated -Wno-conversion -ffoo-iphone -fbar-iphone", settings.get("OTHER_CFLAGS[sdk=*iphone*]"));
    assertEquals("-Wundeclared-selector -Wno-objc-designated-initializers -ffoo-iphone -fbar-iphone " + "-Wundeclared-selector -Wno-objc-designated-initializers -ffoo-iphone -fbar-iphone", settings.get("OTHER_CPLUSPLUSFLAGS[sdk=*iphone*]"));
    assertEquals("-lbaz-iphone -lbaz-iphone", settings.get("OTHER_LDFLAGS[sdk=*iphone*]"));
}
Also used : PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) BuildTarget(com.facebook.buck.model.BuildTarget) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) ImmutableList(com.google.common.collect.ImmutableList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString) Test(org.junit.Test)

Example 82 with PBXTarget

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

the class ProjectGeneratorTest method testHeaderSymlinkTreesWithTestsAndLibraryBundles.

@Test
public void testHeaderSymlinkTreesWithTestsAndLibraryBundles() throws IOException {
    BuildTarget libraryTarget = BuildTarget.builder(rootPath, "//foo", "lib").build();
    BuildTarget bundleTarget = BuildTarget.builder(rootPath, "//foo", "bundle").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")))).build();
    TargetNode<?, ?> bundleNode = AppleBundleBuilder.createBuilder(bundleTarget).setBinary(libraryTarget).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setInfoPlist(new FakeSourcePath("Info.plist")).setTests(ImmutableSortedSet.of(testTarget)).build();
    TargetNode<?, ?> testNode = AppleTestBuilder.createBuilder(testTarget).setConfigs(ImmutableSortedMap.of("Default", ImmutableMap.of())).setInfoPlist(new FakeSourcePath("Info.plist")).setDeps(ImmutableSortedSet.of(bundleTarget)).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(libraryNode, bundleNode, 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 83 with PBXTarget

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

the class ProjectGeneratorTest method testAppleBundleRuleForSharedLibraryFramework.

@Test
public void testAppleBundleRuleForSharedLibraryFramework() 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", "bundle").build();
    TargetNode<?, ?> node = AppleBundleBuilder.createBuilder(buildTarget).setExtension(Either.ofLeft(AppleBundleExtension.FRAMEWORK)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(sharedLibraryTarget).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(sharedLibraryNode, node), ImmutableSet.of());
    projectGenerator.createXcodeProjects();
    PBXProject project = projectGenerator.getGeneratedProject();
    PBXTarget target = assertTargetExistsAndReturnTarget(project, "//foo:bundle");
    assertEquals(target.getProductType(), ProductType.FRAMEWORK);
    assertThat(target.isa(), equalTo("PBXNativeTarget"));
    PBXFileReference productReference = target.getProductReference();
    assertEquals("bundle.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 84 with PBXTarget

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

the class WorkspaceAndProjectGeneratorTest method buildWithBuckFocused.

@Test
public void buildWithBuckFocused() throws IOException, InterruptedException {
    final String fooLib = "//foo:lib";
    Optional<Path> buck = new ExecutableFinder().getOptionalExecutable(Paths.get("buck"), ImmutableMap.of());
    assumeThat(buck.isPresent(), is(true));
    WorkspaceAndProjectGenerator generator = new WorkspaceAndProjectGenerator(rootCell, targetGraph, workspaceNode.getConstructorArg(), workspaceNode.getBuildTarget(), ImmutableSet.of(ProjectGenerator.Option.INCLUDE_TESTS, ProjectGenerator.Option.INCLUDE_DEPENDENCIES_TESTS), false, /* combinedProject */
    true, /* buildWithBuck */
    ImmutableList.of(), Optional.of(ImmutableSet.of(BuildTargetFactory.newInstance(fooLib).getUnflavoredBuildTarget())), false, /* parallelizeBuild */
    new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, "BUCK", getBuildRuleResolverForNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
    Map<Path, ProjectGenerator> projectGenerators = new HashMap<>();
    generator.generateWorkspaceAndDependentProjects(projectGenerators, MoreExecutors.newDirectExecutorService());
    ProjectGenerator fooProjectGenerator = projectGenerators.get(Paths.get("foo"));
    assertThat(fooProjectGenerator, is(notNullValue()));
    for (PBXTarget target : fooProjectGenerator.getGeneratedProject().getTargets()) {
        if (target.getName() != null && !target.getName().equals(fooLib) && !target.getName().endsWith("-Buck")) {
            // all non-lib and non-Buck targets should have 0 steps as they are not in focus
            // (focus on .*lib.* only)
            assertThat(target.getBuildPhases().size(), Matchers.equalTo(0));
        }
    }
}
Also used : Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) HashMap(java.util.HashMap) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Example 85 with PBXTarget

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

the class ProjectGenerator method generateProjectTarget.

@SuppressWarnings("unchecked")
private Optional<PBXTarget> generateProjectTarget(TargetNode<?, ?> targetNode) throws IOException {
    Preconditions.checkState(isBuiltByCurrentProject(targetNode.getBuildTarget()), "should not generate rule if it shouldn't be built by current project");
    Optional<PBXTarget> result = Optional.empty();
    if (targetNode.getDescription() instanceof AppleLibraryDescription) {
        result = Optional.of(generateAppleLibraryTarget(project, (TargetNode<AppleNativeTargetDescriptionArg, ?>) targetNode, Optional.empty()));
    } else if (targetNode.getDescription() instanceof CxxLibraryDescription) {
        result = Optional.of(generateCxxLibraryTarget(project, (TargetNode<CxxLibraryDescription.Arg, ?>) targetNode, ImmutableSet.of(), ImmutableSet.of(), Optional.empty()));
    } else if (targetNode.getDescription() instanceof AppleBinaryDescription) {
        result = Optional.of(generateAppleBinaryTarget(project, (TargetNode<AppleNativeTargetDescriptionArg, ?>) targetNode));
    } else if (targetNode.getDescription() instanceof AppleBundleDescription) {
        TargetNode<AppleBundleDescription.Arg, ?> bundleTargetNode = (TargetNode<AppleBundleDescription.Arg, ?>) targetNode;
        result = Optional.of(generateAppleBundleTarget(project, bundleTargetNode, (TargetNode<AppleNativeTargetDescriptionArg, ?>) targetGraph.get(bundleTargetNode.getConstructorArg().binary), Optional.empty()));
    } else if (targetNode.getDescription() instanceof AppleTestDescription) {
        result = Optional.of(generateAppleTestTarget((TargetNode<AppleTestDescription.Arg, ?>) targetNode));
    } else if (targetNode.getDescription() instanceof AppleResourceDescription) {
        checkAppleResourceTargetNodeReferencingValidContents((TargetNode<AppleResourceDescription.Arg, ?>) targetNode);
    } else if (targetNode.getDescription() instanceof HalideLibraryDescription) {
        TargetNode<HalideLibraryDescription.Arg, ?> halideTargetNode = (TargetNode<HalideLibraryDescription.Arg, ?>) targetNode;
        BuildTarget buildTarget = targetNode.getBuildTarget();
        // The generated target just runs a shell script that invokes the "compiler" with the
        // correct target architecture.
        result = generateHalideLibraryTarget(project, halideTargetNode);
        // Make sure the compiler gets built at project time, since we'll need
        // it to generate the shader code during the Xcode build.
        requiredBuildTargetsBuilder.add(HalideLibraryDescription.createHalideCompilerBuildTarget(buildTarget));
        // headers from.
        if (HalideLibraryDescription.isPlatformSupported(halideTargetNode.getConstructorArg(), defaultCxxPlatform)) {
            // Run the compiler once at project time to generate the header
            // file needed for compilation if the Halide target is for the default
            // platform.
            requiredBuildTargetsBuilder.add(buildTarget.withFlavors(HalideLibraryDescription.HALIDE_COMPILE_FLAVOR, defaultCxxPlatform.getFlavor()));
        }
    }
    buckEventBus.post(ProjectGenerationEvent.processed());
    return result;
}
Also used : PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) AppleResourceDescription(com.facebook.buck.apple.AppleResourceDescription) TargetNode(com.facebook.buck.rules.TargetNode) CxxLibraryDescription(com.facebook.buck.cxx.CxxLibraryDescription) AppleNativeTargetDescriptionArg(com.facebook.buck.apple.AppleNativeTargetDescriptionArg) HalideLibraryDescription(com.facebook.buck.halide.HalideLibraryDescription) AppleTestDescription(com.facebook.buck.apple.AppleTestDescription) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) AppleNativeTargetDescriptionArg(com.facebook.buck.apple.AppleNativeTargetDescriptionArg) StringWithMacrosArg(com.facebook.buck.rules.args.StringWithMacrosArg) AppleWrapperResourceArg(com.facebook.buck.apple.AppleWrapperResourceArg) AppleBundleDescription(com.facebook.buck.apple.AppleBundleDescription) AppleBinaryDescription(com.facebook.buck.apple.AppleBinaryDescription) AppleLibraryDescription(com.facebook.buck.apple.AppleLibraryDescription)

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