Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MAJOR] Do not overwrite all targets with same id (minimal) #708

Closed
wants to merge 19 commits into from
Closed
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions bin/templates/scripts/cordova/lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,54 @@ function handleOrientationSettings (platformConfig, infoPlist) {
}
}

// Make sure only update properties from our target project
function updateBuildPropertyLocal (proj, displayName, prop, value, build) {
try {
// Check if we have a valid target - during prepare we do not have it
var target = proj.pbxTargetByName(displayName);
if (target == null || target.buildConfigurationList == null) {
NiklasMerz marked this conversation as resolved.
Show resolved Hide resolved
proj.updateBuildProperty(prop, value, build);
} else {
var targetProjectBuildReference = target.buildConfigurationList;
// Collect the uuid's from the configuration of our target
var COMMENT_KEY = /_comment$/;
var validConfigs = [];
var configList = proj.pbxXCConfigurationList();
NiklasMerz marked this conversation as resolved.
Show resolved Hide resolved
for (var configName in configList) {
if (!COMMENT_KEY.test(configName) && targetProjectBuildReference === configName) {
var buildVariants = configList[configName].buildConfigurations;
for (var i = 0; i < buildVariants.length; i++) {
validConfigs.push(buildVariants[i].value);
}
break;
}
}
// Only update target props
var configs = proj.pbxXCBuildConfigurationSection();
for (configName in configs) {
if (!COMMENT_KEY.test(configName)) {
if (validConfigs.indexOf(configName) === -1) {
NiklasMerz marked this conversation as resolved.
Show resolved Hide resolved
continue;
}
var config = configs[configName];
if ((build && config.name === build) || (!build)) {
config.buildSettings[prop] = value;
}
}
}
}
} catch (e) { // fallback to default behavior on error
proj.updateBuildProperty(prop, value, build);
}
}

function handleBuildSettings (platformConfig, locations, infoPlist) {
var pkg = platformConfig.getAttribute('ios-CFBundleIdentifier') || platformConfig.packageName();
var targetDevice = parseTargetDevicePreference(platformConfig.getPreference('target-device', 'ios'));
var deploymentTarget = platformConfig.getPreference('deployment-target', 'ios');
var needUpdatedBuildSettingsForLaunchStoryboard = checkIfBuildSettingsNeedUpdatedForLaunchStoryboard(platformConfig, infoPlist);
var swiftVersion = platformConfig.getPreference('SwiftVersion', 'ios');
var displayName = platformConfig.name().replace(/"/g, '');
brodycj marked this conversation as resolved.
Show resolved Hide resolved

var project;

Expand All @@ -299,22 +341,22 @@ function handleBuildSettings (platformConfig, locations, infoPlist) {

if (origPkg !== pkg) {
events.emit('verbose', 'Set PRODUCT_BUNDLE_IDENTIFIER to ' + pkg + '.');
project.xcode.updateBuildProperty('PRODUCT_BUNDLE_IDENTIFIER', pkg);
updateBuildPropertyLocal(project.xcode, displayName, 'PRODUCT_BUNDLE_IDENTIFIER', pkg);
}

if (targetDevice) {
events.emit('verbose', 'Set TARGETED_DEVICE_FAMILY to ' + targetDevice + '.');
project.xcode.updateBuildProperty('TARGETED_DEVICE_FAMILY', targetDevice);
updateBuildPropertyLocal(project.xcode, displayName, 'TARGETED_DEVICE_FAMILY', targetDevice);
}

if (deploymentTarget) {
events.emit('verbose', 'Set IPHONEOS_DEPLOYMENT_TARGET to "' + deploymentTarget + '".');
project.xcode.updateBuildProperty('IPHONEOS_DEPLOYMENT_TARGET', deploymentTarget);
updateBuildPropertyLocal(project.xcode, displayName, 'IPHONEOS_DEPLOYMENT_TARGET', deploymentTarget);
}

if (swiftVersion) {
events.emit('verbose', 'Set SwiftVersion to "' + swiftVersion + '".');
project.xcode.updateBuildProperty('SWIFT_VERSION', swiftVersion);
updateBuildPropertyLocal(project.xcode, displayName, 'SWIFT_VERSION', swiftVersion);
}

updateBuildSettingsForLaunchStoryboard(project.xcode, platformConfig, infoPlist);
Expand Down