From f3a137c2dbcda5a0bcc58b370ca2d8f4f52b693c Mon Sep 17 00:00:00 2001 From: Murat Sari Date: Fri, 22 Feb 2019 10:20:04 +0100 Subject: [PATCH 1/4] * Prepare script update build properties for the main target only. With the old behavior it were not possible to add apple watch targets and build it because cordova bricked the bundleids for these targets. * Add new build parameter multipleProvisioningProfiles. Here the usage within the build.json: "multipleProvisioningProfiles": [ { "key": "de.demo.html5", "value": "DemoME-Enterprise" }, { "key": "de.demo.html5.watchkitapp", "value": "DemoWE-Enterprise" }, { "key": "de.demo.html5.watchkitapp.watchkitextension", "value": "DemoWE Extension-Enterprise" } ], This one is needed too otherwise the signing step fails because cordova generates a wrong bundleid to prov.profile mapping. With these settings the exportOptions.plist is written correctly for multiple targets. This patch is needed to make the apple watch targets work with the cordova-ios workflow (apple watch targets added within a post process scripts using npm xcode) --- bin/templates/scripts/cordova/build | 1 + bin/templates/scripts/cordova/lib/build.js | 13 +++-- bin/templates/scripts/cordova/lib/prepare.js | 55 ++++++++++++++++++-- bin/templates/scripts/cordova/run | 1 + 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/bin/templates/scripts/cordova/build b/bin/templates/scripts/cordova/build index bd5a61947..f9ca2122e 100755 --- a/bin/templates/scripts/cordova/build +++ b/bin/templates/scripts/cordova/build @@ -42,6 +42,7 @@ var buildOpts = nopt({ 'codeSignIdentity': String, 'codeSignResourceRules': String, 'provisioningProfile': String, + 'multipleProvisioningProfiles': Array, 'automaticProvisioning': Boolean, 'developmentTeam': String, 'packageType': String, diff --git a/bin/templates/scripts/cordova/lib/build.js b/bin/templates/scripts/cordova/lib/build.js index 4270c4769..9db9e0a37 100644 --- a/bin/templates/scripts/cordova/lib/build.js +++ b/bin/templates/scripts/cordova/lib/build.js @@ -129,7 +129,7 @@ module.exports.run = function (buildOpts) { var buildType = buildOpts.release ? 'release' : 'debug'; var config = buildConfig.ios[buildType]; if (config) { - ['codeSignIdentity', 'codeSignResourceRules', 'provisioningProfile', 'developmentTeam', 'packageType', 'buildFlag', 'iCloudContainerEnvironment', 'automaticProvisioning'].forEach( + ['codeSignIdentity', 'codeSignResourceRules', 'provisioningProfile', 'multipleProvisioningProfiles', 'developmentTeam', 'packageType', 'buildFlag', 'iCloudContainerEnvironment', 'automaticProvisioning'].forEach( function (key) { buildOpts[key] = buildOpts[key] || config[key]; }); @@ -247,8 +247,15 @@ module.exports.run = function (buildOpts) { exportOptions.teamID = buildOpts.developmentTeam; } - if (buildOpts.provisioningProfile && bundleIdentifier) { - exportOptions.provisioningProfiles = { [ bundleIdentifier ]: String(buildOpts.provisioningProfile) }; + if ((buildOpts.provisioningProfile || buildOpts.multipleProvisioningProfiles) && bundleIdentifier) { + if (buildOpts.multipleProvisioningProfiles) { + exportOptions.provisioningProfiles = {}; + for (var i = 0; i < buildOpts.multipleProvisioningProfiles.length; i++) { + exportOptions.provisioningProfiles[buildOpts.multipleProvisioningProfiles[i]["key"]] = String(buildOpts.multipleProvisioningProfiles[i]["value"]); + } + } else { + exportOptions.provisioningProfiles = { [bundleIdentifier]: String(buildOpts.provisioningProfile) }; + } exportOptions.signingStyle = 'manual'; } diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index 29f6cc2e7..f117a97b5 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -275,12 +275,59 @@ 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) { + 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(); + 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 (var configName in configs) { + if (!COMMENT_KEY.test(configName)) { + if (validConfigs.indexOf(configName) == -1) { + 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.shortName && platformConfig.shortName(); var proj = new xcode.project(locations.pbxproj); /* eslint new-cap : 0 */ @@ -300,22 +347,22 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { if (origPkg !== pkg) { events.emit('verbose', 'Set PRODUCT_BUNDLE_IDENTIFIER to ' + pkg + '.'); - proj.updateBuildProperty('PRODUCT_BUNDLE_IDENTIFIER', pkg); + updateBuildPropertyLocal(proj, displayName, 'PRODUCT_BUNDLE_IDENTIFIER', pkg); } if (targetDevice) { events.emit('verbose', 'Set TARGETED_DEVICE_FAMILY to ' + targetDevice + '.'); - proj.updateBuildProperty('TARGETED_DEVICE_FAMILY', targetDevice); + updateBuildPropertyLocal(proj, displayName, 'TARGETED_DEVICE_FAMILY', targetDevice); } if (deploymentTarget) { events.emit('verbose', 'Set IPHONEOS_DEPLOYMENT_TARGET to "' + deploymentTarget + '".'); - proj.updateBuildProperty('IPHONEOS_DEPLOYMENT_TARGET', deploymentTarget); + updateBuildPropertyLocal(proj, displayName, 'IPHONEOS_DEPLOYMENT_TARGET', deploymentTarget); } if (swiftVersion) { events.emit('verbose', 'Set SwiftVersion to "' + swiftVersion + '".'); - proj.updateBuildProperty('SWIFT_VERSION', swiftVersion); + updateBuildPropertyLocal(proj, displayName, 'SWIFT_VERSION', swiftVersion); } updateBuildSettingsForLaunchStoryboard(proj, platformConfig, infoPlist); diff --git a/bin/templates/scripts/cordova/run b/bin/templates/scripts/cordova/run index c4cfca30a..bf734b249 100755 --- a/bin/templates/scripts/cordova/run +++ b/bin/templates/scripts/cordova/run @@ -45,6 +45,7 @@ var opts = nopt({ 'codeSignIdentity': String, 'codeSignResourceRules': String, 'provisioningProfile': String, + 'multipleProvisioningProfiles': Array, 'automaticProvisioning': Boolean, 'buildConfig' : String, 'noSign' : Boolean From 160542d9dd387a99c886b7903a0bd78a95a9ac05 Mon Sep 17 00:00:00 2001 From: Murat Sari Date: Mon, 25 Feb 2019 22:30:35 +0100 Subject: [PATCH 2/4] * Do not use the short name to retrieve the pbx target --- bin/templates/scripts/cordova/lib/prepare.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index f117a97b5..6b2285cdd 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -327,8 +327,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { var deploymentTarget = platformConfig.getPreference('deployment-target', 'ios'); var needUpdatedBuildSettingsForLaunchStoryboard = checkIfBuildSettingsNeedUpdatedForLaunchStoryboard(platformConfig, infoPlist); var swiftVersion = platformConfig.getPreference('SwiftVersion', 'ios'); - var displayName = platformConfig.shortName && platformConfig.shortName(); - + var displayName = platformConfig.name().replace(/\"/g, ""); var proj = new xcode.project(locations.pbxproj); /* eslint new-cap : 0 */ try { From 0c24c4bb046f1f4930b6090770b81b9c4a45bcb6 Mon Sep 17 00:00:00 2001 From: Murat Sari Date: Mon, 25 Feb 2019 22:41:03 +0100 Subject: [PATCH 3/4] Adapt style --- bin/templates/scripts/cordova/lib/build.js | 2 +- bin/templates/scripts/cordova/lib/prepare.js | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/bin/templates/scripts/cordova/lib/build.js b/bin/templates/scripts/cordova/lib/build.js index 9db9e0a37..3ad97d134 100644 --- a/bin/templates/scripts/cordova/lib/build.js +++ b/bin/templates/scripts/cordova/lib/build.js @@ -251,7 +251,7 @@ module.exports.run = function (buildOpts) { if (buildOpts.multipleProvisioningProfiles) { exportOptions.provisioningProfiles = {}; for (var i = 0; i < buildOpts.multipleProvisioningProfiles.length; i++) { - exportOptions.provisioningProfiles[buildOpts.multipleProvisioningProfiles[i]["key"]] = String(buildOpts.multipleProvisioningProfiles[i]["value"]); + exportOptions.provisioningProfiles[buildOpts.multipleProvisioningProfiles[i]['key']] = String(buildOpts.multipleProvisioningProfiles[i]['value']); } } else { exportOptions.provisioningProfiles = { [bundleIdentifier]: String(buildOpts.provisioningProfile) }; diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index 6b2285cdd..44a7182aa 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -276,16 +276,14 @@ function handleOrientationSettings (platformConfig, infoPlist) { } // Make sure only update properties from our target project -function updateBuildPropertyLocal(proj, displayName, prop, value, build) { +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) { 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 = []; @@ -299,15 +297,13 @@ function updateBuildPropertyLocal(proj, displayName, prop, value, build) { break; } } - // Only update target props var configs = proj.pbxXCBuildConfigurationSection(); - for (var configName in configs) { + for (configName in configs) { if (!COMMENT_KEY.test(configName)) { - if (validConfigs.indexOf(configName) == -1) { + if (validConfigs.indexOf(configName) === -1) { continue; } - var config = configs[configName]; if ((build && config.name === build) || (!build)) { config.buildSettings[prop] = value; @@ -327,7 +323,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { var deploymentTarget = platformConfig.getPreference('deployment-target', 'ios'); var needUpdatedBuildSettingsForLaunchStoryboard = checkIfBuildSettingsNeedUpdatedForLaunchStoryboard(platformConfig, infoPlist); var swiftVersion = platformConfig.getPreference('SwiftVersion', 'ios'); - var displayName = platformConfig.name().replace(/\"/g, ""); + var displayName = platformConfig.name().replace(/\"/g, ''); var proj = new xcode.project(locations.pbxproj); /* eslint new-cap : 0 */ try { From 342396b1eced50805992cfcc9b7d6a7432ea0552 Mon Sep 17 00:00:00 2001 From: Murat Sari Date: Mon, 25 Feb 2019 22:48:43 +0100 Subject: [PATCH 4/4] More linter fixes --- bin/templates/scripts/cordova/lib/prepare.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index 44a7182aa..233959fa5 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -316,14 +316,13 @@ function updateBuildPropertyLocal (proj, displayName, 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, ''); + var displayName = platformConfig.name().replace(/"/g, ''); var proj = new xcode.project(locations.pbxproj); /* eslint new-cap : 0 */ try {