Search in sources :

Example 1 with XCBuildConfiguration

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

the class ProjectGenerator method generateBuildWithBuckTarget.

private void generateBuildWithBuckTarget(TargetNode<?, ?> targetNode) {
    final BuildTarget buildTarget = targetNode.getBuildTarget();
    String buckTargetProductName = getXcodeTargetName(buildTarget) + BUILD_WITH_BUCK_POSTFIX;
    PBXAggregateTarget buildWithBuckTarget = new PBXAggregateTarget(buckTargetProductName);
    buildWithBuckTarget.setProductName(buckTargetProductName);
    PBXShellScriptBuildPhase buildShellScriptBuildPhase = new PBXShellScriptBuildPhase();
    buildShellScriptBuildPhase.setShellScript(getBuildWithBuckShellScript(targetNode));
    buildWithBuckTarget.getBuildPhases().add(buildShellScriptBuildPhase);
    // Only add a shell script for fixing UUIDs if it is an AppleBundle
    if (targetNode.getDescription() instanceof AppleBundleDescription) {
        PBXShellScriptBuildPhase codesignPhase = new PBXShellScriptBuildPhase();
        codesignPhase.setShellScript(getCodesignShellScript(targetNode));
        buildWithBuckTarget.getBuildPhases().add(codesignPhase);
    }
    TargetNode<CxxLibraryDescription.Arg, ?> node = getAppleNativeNode(targetGraph, targetNode).get();
    ImmutableMap<String, ImmutableMap<String, String>> configs = getXcodeBuildConfigurationsForTargetNode(node, ImmutableMap.of()).get();
    XCConfigurationList configurationList = new XCConfigurationList();
    PBXGroup group = project.getMainGroup().getOrCreateDescendantGroupByPath(StreamSupport.stream(buildTarget.getBasePath().spliterator(), false).map(Object::toString).collect(MoreCollectors.toImmutableList())).getOrCreateChildGroupByName(getXcodeTargetName(buildTarget));
    for (String configurationName : configs.keySet()) {
        XCBuildConfiguration configuration = configurationList.getBuildConfigurationsByName().getUnchecked(configurationName);
        configuration.setBaseConfigurationReference(getConfigurationFileReference(group, getConfigurationNameToXcconfigPath(buildTarget).apply(configurationName)));
        NSDictionary inlineSettings = new NSDictionary();
        inlineSettings.put("HEADER_SEARCH_PATHS", "");
        inlineSettings.put("LIBRARY_SEARCH_PATHS", "");
        inlineSettings.put("FRAMEWORK_SEARCH_PATHS", "");
        configuration.setBuildSettings(inlineSettings);
    }
    buildWithBuckTarget.setBuildConfigurationList(configurationList);
    project.getTargets().add(buildWithBuckTarget);
    targetNodeToGeneratedProjectTargetBuilder.put(targetNode, buildWithBuckTarget);
}
Also used : XCBuildConfiguration(com.facebook.buck.apple.xcode.xcodeproj.XCBuildConfiguration) XCConfigurationList(com.facebook.buck.apple.xcode.xcodeproj.XCConfigurationList) NSDictionary(com.dd.plist.NSDictionary) NSString(com.dd.plist.NSString) PBXAggregateTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXAggregateTarget) ImmutableMap(com.google.common.collect.ImmutableMap) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) 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) PBXGroup(com.facebook.buck.apple.xcode.xcodeproj.PBXGroup) AppleBundleDescription(com.facebook.buck.apple.AppleBundleDescription)

Example 2 with XCBuildConfiguration

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

the class ProjectGenerator method createXcodeProjects.

public void createXcodeProjects() throws IOException {
    LOG.debug("Creating projects for targets %s", initialTargets);
    boolean hasAtLeastOneTarget = false;
    try (SimplePerfEvent.Scope scope = SimplePerfEvent.scope(buckEventBus, PerfEventId.of("xcode_project_generation"), ImmutableMap.of("Path", getProjectPath()))) {
        for (TargetNode<?, ?> targetNode : targetGraph.getNodes()) {
            if (isBuiltByCurrentProject(targetNode.getBuildTarget())) {
                LOG.debug("Including rule %s in project", targetNode);
                // Trigger the loading cache to call the generateProjectTarget function.
                Optional<PBXTarget> target = targetNodeToProjectTarget.getUnchecked(targetNode);
                if (target.isPresent()) {
                    targetNodeToGeneratedProjectTargetBuilder.put(targetNode, target.get());
                }
                if (targetNode.getBuildTarget().matchesUnflavoredTargets(focusModules)) {
                    // If the target is not included, we still need to do other operations to generate
                    // the required header maps.
                    hasAtLeastOneTarget = true;
                }
            } else {
                LOG.verbose("Excluding rule %s (not built by current project)", targetNode);
            }
        }
        if (!hasAtLeastOneTarget && focusModules.isPresent()) {
            return;
        }
        if (targetToBuildWithBuck.isPresent()) {
            generateBuildWithBuckTarget(targetGraph.get(targetToBuildWithBuck.get()));
        }
        for (String configName : targetConfigNamesBuilder.build()) {
            XCBuildConfiguration outputConfig = project.getBuildConfigurationList().getBuildConfigurationsByName().getUnchecked(configName);
            outputConfig.setBuildSettings(new NSDictionary());
        }
        if (!shouldGenerateHeaderSymlinkTreesOnly()) {
            writeProjectFile(project);
        }
        projectGenerated = true;
    } catch (UncheckedExecutionException e) {
        // if any code throws an exception, they tend to get wrapped in LoadingCache's
        // UncheckedExecutionException. Unwrap it if its cause is HumanReadable.
        UncheckedExecutionException originalException = e;
        while (e.getCause() instanceof UncheckedExecutionException) {
            e = (UncheckedExecutionException) e.getCause();
        }
        if (e.getCause() instanceof HumanReadableException) {
            throw (HumanReadableException) e.getCause();
        } else {
            throw originalException;
        }
    }
}
Also used : PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) XCBuildConfiguration(com.facebook.buck.apple.xcode.xcodeproj.XCBuildConfiguration) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) NSDictionary(com.dd.plist.NSDictionary) HumanReadableException(com.facebook.buck.util.HumanReadableException) NSString(com.dd.plist.NSString) SimplePerfEvent(com.facebook.buck.event.SimplePerfEvent)

Example 3 with XCBuildConfiguration

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

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

the class ProjectGeneratorTest method generatedProjectConfigurationListIsUnionOfAllTargetConfigurations.

/**
   * The project configurations should have named entries corresponding to every existing target
   * configuration for targets in the project.
   */
@Test
public void generatedProjectConfigurationListIsUnionOfAllTargetConfigurations() throws IOException {
    BuildTarget buildTarget1 = BuildTarget.builder(rootPath, "//foo", "rule1").build();
    TargetNode<?, ?> node1 = AppleLibraryBuilder.createBuilder(buildTarget1).setConfigs(ImmutableSortedMap.of("Conf1", ImmutableMap.of(), "Conf2", ImmutableMap.of())).build();
    BuildTarget buildTarget2 = BuildTarget.builder(rootPath, "//foo", "rule2").build();
    TargetNode<?, ?> node2 = AppleLibraryBuilder.createBuilder(buildTarget2).setConfigs(ImmutableSortedMap.of("Conf2", ImmutableMap.of(), "Conf3", ImmutableMap.of())).build();
    ProjectGenerator projectGenerator = createProjectGeneratorForCombinedProject(ImmutableSet.of(node1, node2));
    projectGenerator.createXcodeProjects();
    PBXProject generatedProject = projectGenerator.getGeneratedProject();
    Map<String, XCBuildConfiguration> configurations = generatedProject.getBuildConfigurationList().getBuildConfigurationsByName().asMap();
    assertThat(configurations, hasKey("Conf1"));
    assertThat(configurations, hasKey("Conf2"));
    assertThat(configurations, hasKey("Conf3"));
}
Also used : XCBuildConfiguration(com.facebook.buck.apple.xcode.xcodeproj.XCBuildConfiguration) 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 5 with XCBuildConfiguration

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

the class ProjectGeneratorTest method assertHasConfigurations.

private void assertHasConfigurations(PBXTarget target, String... names) {
    Map<String, XCBuildConfiguration> buildConfigurationMap = target.getBuildConfigurationList().getBuildConfigurationsByName().asMap();
    assertEquals("Configuration list has expected number of entries", names.length, buildConfigurationMap.size());
    for (String name : names) {
        XCBuildConfiguration configuration = buildConfigurationMap.get(name);
        assertNotNull("Configuration entry exists", configuration);
        assertEquals("Configuration name is same as key", name, configuration.getName());
        assertTrue("Configuration has xcconfig file", configuration.getBaseConfigurationReference().getPath().endsWith(".xcconfig"));
    }
}
Also used : XCBuildConfiguration(com.facebook.buck.apple.xcode.xcodeproj.XCBuildConfiguration) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString)

Aggregations

XCBuildConfiguration (com.facebook.buck.apple.xcode.xcodeproj.XCBuildConfiguration)8 NSString (com.dd.plist.NSString)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 PBXFileReference (com.facebook.buck.apple.xcode.xcodeproj.PBXFileReference)3 BuildTarget (com.facebook.buck.model.BuildTarget)3 NSDictionary (com.dd.plist.NSDictionary)2 PBXGroup (com.facebook.buck.apple.xcode.xcodeproj.PBXGroup)2 PBXTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXTarget)2 PathSourcePath (com.facebook.buck.rules.PathSourcePath)2 SourcePath (com.facebook.buck.rules.SourcePath)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 AppleBundleDescription (com.facebook.buck.apple.AppleBundleDescription)1 AppleNativeTargetDescriptionArg (com.facebook.buck.apple.AppleNativeTargetDescriptionArg)1 AppleWrapperResourceArg (com.facebook.buck.apple.AppleWrapperResourceArg)1 HeaderMap (com.facebook.buck.apple.clang.HeaderMap)1 PBXAggregateTarget (com.facebook.buck.apple.xcode.xcodeproj.PBXAggregateTarget)1 PBXProject (com.facebook.buck.apple.xcode.xcodeproj.PBXProject)1