Skip to content

Commit

Permalink
Deployment target patch
Browse files Browse the repository at this point in the history
Combined patch from apache#708 from @msari-ipe-ext-1 with refactorings

Co-authored-by: Murat Sari <[email protected]>
  • Loading branch information
msari-ipe-ext-1 authored and NiklasMerz committed Jan 14, 2020
1 parent 266d339 commit b362e70
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions bin/templates/scripts/cordova/lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,56 @@ function handleOrientationSettings (platformConfig, infoPlist) {
}
}

// Make sure only update properties from our target project
function updateBuildPropertyLocal (project, displayName, prop, value, build) {
const proj = project.xcode;
try {
// Check if we have a valid target - during prepare we do not have it
const target = proj.pbxTargetByName(displayName);
if (target == null || target.buildConfigurationList == null) {
proj.updateBuildProperty(prop, value, build);
} else {
const targetProjectBuildReference = target.buildConfigurationList;
// Collect the uuid's from the configuration of our target
const COMMENT_KEY = /_comment$/;
const validConfigs = [];
const configList = proj.pbxXCConfigurationList();
for (let configName in configList) {
if (!COMMENT_KEY.test(configName) && targetProjectBuildReference === configName) {
const buildVariants = configList[configName].buildConfigurations;
for (let i = 0; i < buildVariants.length; i++) {
validConfigs.push(buildVariants[i].value);
}
break;
}
}
// Only update target props
const configs = proj.pbxXCBuildConfigurationSection();
for (configName in configs) {
if (!COMMENT_KEY.test(configName)) {
if (validConfigs.indexOf(configName) === -1) {
continue;
}
const 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) {
const pkg = platformConfig.getAttribute('ios-CFBundleIdentifier') || platformConfig.packageName();
const targetDevice = parseTargetDevicePreference(platformConfig.getPreference('target-device', 'ios'));
const deploymentTarget = platformConfig.getPreference('deployment-target', 'ios');
const needUpdatedBuildSettingsForLaunchStoryboard = checkIfBuildSettingsNeedUpdatedForLaunchStoryboard(platformConfig, infoPlist);
const swiftVersion = platformConfig.getPreference('SwiftVersion', 'ios');
const wkWebViewOnly = platformConfig.getPreference('WKWebViewOnly');
const displayName = platformConfig.shortName && platformConfig.shortName();

let project;

Expand Down Expand Up @@ -303,12 +346,12 @@ function handleBuildSettings (platformConfig, locations, infoPlist) {

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

if (swiftVersion) {
events.emit('verbose', `Set SwiftVersion to "${swiftVersion}".`);
project.xcode.updateBuildProperty('SWIFT_VERSION', swiftVersion);
updateBuildPropertyLocal(project, displayName, 'SWIFT_VERSION', swiftVersion);
}
if (wkWebViewOnly) {
let wkwebviewValue = '1';
Expand All @@ -325,6 +368,8 @@ function handleBuildSettings (platformConfig, locations, infoPlist) {
xcodeproj.parseSync();
xcodeproj.updateBuildProperty('WK_WEB_VIEW_ONLY', wkwebviewValue);
fs.writeFileSync(pbxPath, xcodeproj.writeSync());
events.emit('verbose', `Set PRODUCT_BUNDLE_IDENTIFIER to ${pkg}.`);
updateBuildPropertyLocal(project, displayName, 'PRODUCT_BUNDLE_IDENTIFIER', pkg);
}

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

0 comments on commit b362e70

Please sign in to comment.