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);
}
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;
}
}
}
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);
}
}
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"));
}
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"));
}
}
Aggregations