This is an automated email from the ASF dual-hosted git repository. erisu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cordova-ios.git
The following commit(s) were added to refs/heads/master by this push: new ad57677f fix: Try updating Podfile deployment target on prepare (#1341) ad57677f is described below commit ad57677fa4a66e245e30b471983ff783b63f8110 Author: Darryl Pogue <dar...@dpogue.ca> AuthorDate: Thu Jun 29 11:07:10 2023 -0700 fix: Try updating Podfile deployment target on prepare (#1341) --- lib/Api.js | 43 +++---------------------------------------- lib/PodsJson.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ lib/prepare.js | 18 ++++++++++++++++++ 3 files changed, 67 insertions(+), 40 deletions(-) diff --git a/lib/Api.js b/lib/Api.js index 95f8dec3..0437a1ad 100644 --- a/lib/Api.js +++ b/lib/Api.js @@ -34,7 +34,6 @@ const { PluginManager } = require('cordova-common'); const util = require('util'); -const xcode = require('xcode'); function setupEvents (externalEventEmitter) { if (externalEventEmitter) { @@ -417,7 +416,7 @@ class Api { projectFile.purgeProjectFileCache(this.locations.root); return podfileFile.install(check_reqs.check_cocoapods) - .then(() => this.setSwiftVersionForCocoaPodsLibraries(podsjsonFile)); + .then(() => podsjsonFile.setSwiftVersionForCocoaPodsLibraries(this.root)); } else { events.emit('verbose', 'Podfile unchanged, skipping `pod install`'); } @@ -506,7 +505,7 @@ class Api { events.emit('verbose', 'Running `pod install` (to uninstall pods)'); return podfileFile.install(check_reqs.check_cocoapods) - .then(() => this.setSwiftVersionForCocoaPodsLibraries(podsjsonFile)); + .then(() => podsjsonFile.setSwiftVersionForCocoaPodsLibraries(this.root)); } else { events.emit('verbose', 'Podfile unchanged, skipping `pod install`'); } @@ -520,43 +519,7 @@ class Api { * @param {PodsJson} podsjsonFile A PodsJson instance that represents pods.json */ setSwiftVersionForCocoaPodsLibraries (podsjsonFile) { - let __dirty = false; - return check_reqs.check_cocoapods().then(toolOptions => { - if (toolOptions.ignore) { - events.emit('verbose', '=== skip Swift Version Settings For Cocoapods Libraries'); - } else { - const podPbxPath = path.join(this.root, 'Pods', 'Pods.xcodeproj', 'project.pbxproj'); - const podXcodeproj = xcode.project(podPbxPath); - podXcodeproj.parseSync(); - const podTargets = podXcodeproj.pbxNativeTargetSection(); - const podConfigurationList = podXcodeproj.pbxXCConfigurationList(); - const podConfigs = podXcodeproj.pbxXCBuildConfigurationSection(); - - const libraries = podsjsonFile.getLibraries(); - Object.keys(libraries).forEach(key => { - const podJson = libraries[key]; - const name = podJson.name; - const swiftVersion = podJson['swift-version']; - if (swiftVersion) { - __dirty = true; - Object.keys(podTargets) - .filter(targetKey => podTargets[targetKey].productName === name) - .map(targetKey => podTargets[targetKey].buildConfigurationList) - .map(buildConfigurationListId => podConfigurationList[buildConfigurationListId]) - .map(buildConfigurationList => buildConfigurationList.buildConfigurations) - .reduce((acc, buildConfigurations) => acc.concat(buildConfigurations), []) - .map(buildConfiguration => buildConfiguration.value) - .forEach(buildId => { - __dirty = true; - podConfigs[buildId].buildSettings.SWIFT_VERSION = swiftVersion; - }); - } - }); - if (__dirty) { - fs.writeFileSync(podPbxPath, podXcodeproj.writeSync(), 'utf-8'); - } - } - }); + return podsjsonFile.setSwiftVersionForCocoaPodsLibraries(this.root); } /** diff --git a/lib/PodsJson.js b/lib/PodsJson.js index 598d9607..efea7d8d 100644 --- a/lib/PodsJson.js +++ b/lib/PodsJson.js @@ -20,6 +20,8 @@ const fs = require('fs-extra'); const path = require('path'); const util = require('util'); +const xcode = require('xcode'); +const check_reqs = require('./check_reqs'); const events = require('cordova-common').events; const CordovaError = require('cordova-common').CordovaError; @@ -206,4 +208,48 @@ PodsJson.prototype.isDirty = function () { return this.__dirty; }; +/** + * set Swift Version for all CocoaPods libraries + */ +PodsJson.prototype.setSwiftVersionForCocoaPodsLibraries = function (projectRoot) { + let __dirty = false; + return check_reqs.check_cocoapods().then(toolOptions => { + if (toolOptions.ignore) { + events.emit('verbose', '=== skip Swift Version Settings For Cocoapods Libraries'); + } else { + const podPbxPath = path.join(projectRoot, 'Pods', 'Pods.xcodeproj', 'project.pbxproj'); + const podXcodeproj = xcode.project(podPbxPath); + podXcodeproj.parseSync(); + + const podTargets = podXcodeproj.pbxNativeTargetSection(); + const podConfigurationList = podXcodeproj.pbxXCConfigurationList(); + const podConfigs = podXcodeproj.pbxXCBuildConfigurationSection(); + + const libraries = this.getLibraries(); + Object.keys(libraries).forEach(key => { + const podJson = libraries[key]; + const name = podJson.name; + const swiftVersion = podJson['swift-version']; + if (swiftVersion) { + __dirty = true; + Object.keys(podTargets) + .filter(targetKey => podTargets[targetKey].productName === name) + .map(targetKey => podTargets[targetKey].buildConfigurationList) + .map(buildConfigurationListId => podConfigurationList[buildConfigurationListId]) + .map(buildConfigurationList => buildConfigurationList.buildConfigurations) + .reduce((acc, buildConfigurations) => acc.concat(buildConfigurations), []) + .map(buildConfiguration => buildConfiguration.value) + .forEach(buildId => { + __dirty = true; + podConfigs[buildId].buildSettings.SWIFT_VERSION = swiftVersion; + }); + } + }); + if (__dirty) { + fs.writeFileSync(podPbxPath, podXcodeproj.writeSync(), 'utf-8'); + } + } + }); +}; + module.exports.PodsJson = PodsJson; diff --git a/lib/prepare.js b/lib/prepare.js index ab9746b5..38239e4c 100644 --- a/lib/prepare.js +++ b/lib/prepare.js @@ -33,6 +33,8 @@ const PlatformMunger = require('cordova-common').ConfigChanges.PlatformMunger; const PluginInfoProvider = require('cordova-common').PluginInfoProvider; const FileUpdater = require('cordova-common').FileUpdater; const projectFile = require('./projectFile'); +const Podfile = require('./Podfile').Podfile; +const check_reqs = require('./check_reqs'); // launch storyboard and related constants const IMAGESET_COMPACT_SIZE_CLASS = 'compact'; @@ -309,6 +311,22 @@ function handleBuildSettings (platformConfig, locations, infoPlist) { project.write(); + // If we have a Podfile, we want to update the deployment target there too + const podPath = path.join(locations.root, Podfile.FILENAME); + if (deploymentTarget && fs.existsSync(podPath)) { + const project_name = locations.xcodeCordovaProj.split(path.sep).pop(); + + const PodsJson = require('./PodsJson').PodsJson; + const podsjsonFile = new PodsJson(path.join(locations.root, PodsJson.FILENAME)); + const podfileFile = new Podfile(podPath, project_name, deploymentTarget); + podfileFile.write(); + + events.emit('verbose', 'Running `pod install` (to install plugins)'); + projectFile.purgeProjectFileCache(locations.root); + return podfileFile.install(check_reqs.check_cocoapods) + .then(() => podsjsonFile.setSwiftVersionForCocoaPodsLibraries(locations.root)); + } + return Promise.resolve(); } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org