Skip to content

Commit

Permalink
ignore swift version settings of cocoapods library on windows/linux e…
Browse files Browse the repository at this point in the history
…nvironment by using check_reqs.check_cocoapods function
  • Loading branch information
knaito-asial authored and dpogue committed Mar 2, 2019
1 parent bc774e6 commit ae4d1fd
Showing 1 changed file with 40 additions and 34 deletions.
74 changes: 40 additions & 34 deletions bin/templates/scripts/cordova/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ Api.prototype.addPodSpecs = function (plugin, podSpecs, frameworkPods) {

return podfileFile.install(check_reqs.check_cocoapods)
.then(function () {
self.setSwiftVersionForCocoaPodsLibraries(podsjsonFile);
return self.setSwiftVersionForCocoaPodsLibraries(podsjsonFile);
});
} else {
events.emit('verbose', 'Podfile unchanged, skipping `pod install`');
Expand Down Expand Up @@ -564,7 +564,7 @@ Api.prototype.removePodSpecs = function (plugin, podSpecs, frameworkPods) {

return podfileFile.install(check_reqs.check_cocoapods)
.then(function () {
self.setSwiftVersionForCocoaPodsLibraries(podsjsonFile);
return self.setSwiftVersionForCocoaPodsLibraries(podsjsonFile);
});
} else {
events.emit('verbose', 'Podfile unchanged, skipping `pod install`');
Expand All @@ -582,41 +582,47 @@ Api.prototype.removePodSpecs = function (plugin, podSpecs, frameworkPods) {
Api.prototype.setSwiftVersionForCocoaPodsLibraries = function (podsjsonFile) {
var self = this;
var __dirty = false;
var podPbxPath = path.join(self.root, 'Pods', 'Pods.xcodeproj', 'project.pbxproj');
var podXcodeproj = xcode.project(podPbxPath);
podXcodeproj.parseSync();
var podTargets = podXcodeproj.pbxNativeTargetSection();
var podConfigurationList = podXcodeproj.pbxXCConfigurationList();
var podConfigs = podXcodeproj.pbxXCBuildConfigurationSection();

var libraries = podsjsonFile.getLibraries();
Object.keys(libraries).forEach(function (key) {
var podJson = libraries[key];
var name = podJson.name;
var swiftVersion = podJson['swift-version'];
if (swiftVersion) {
__dirty = true;
Object.keys(podTargets).filter(function (targetKey) {
return podTargets[targetKey].productName === name;
}).map(function (targetKey) {
return podTargets[targetKey].buildConfigurationList;
}).map(function (buildConfigurationListId) {
return podConfigurationList[buildConfigurationListId];
}).map(function (buildConfigurationList) {
return buildConfigurationList.buildConfigurations;
}).reduce(function (acc, buildConfigurations) {
return acc.concat(buildConfigurations);
}, []).map(function (buildConfiguration) {
return buildConfiguration.value;
}).forEach(function (buildId) {
__dirty = true;
podConfigs[buildId].buildSettings['SWIFT_VERSION'] = swiftVersion;
return check_reqs.check_cocoapods().then(function (toolOptions) {
if (toolOptions.ignore) {
events.emit('verbose', '=== skip Swift Version Settings For Cocoapods Libraries');
} else {
var podPbxPath = path.join(self.root, 'Pods', 'Pods.xcodeproj', 'project.pbxproj');
var podXcodeproj = xcode.project(podPbxPath);
podXcodeproj.parseSync();
var podTargets = podXcodeproj.pbxNativeTargetSection();
var podConfigurationList = podXcodeproj.pbxXCConfigurationList();
var podConfigs = podXcodeproj.pbxXCBuildConfigurationSection();

var libraries = podsjsonFile.getLibraries();
Object.keys(libraries).forEach(function (key) {
var podJson = libraries[key];
var name = podJson.name;
var swiftVersion = podJson['swift-version'];
if (swiftVersion) {
__dirty = true;
Object.keys(podTargets).filter(function (targetKey) {
return podTargets[targetKey].productName === name;
}).map(function (targetKey) {
return podTargets[targetKey].buildConfigurationList;
}).map(function (buildConfigurationListId) {
return podConfigurationList[buildConfigurationListId];
}).map(function (buildConfigurationList) {
return buildConfigurationList.buildConfigurations;
}).reduce(function (acc, buildConfigurations) {
return acc.concat(buildConfigurations);
}, []).map(function (buildConfiguration) {
return buildConfiguration.value;
}).forEach(function (buildId) {
__dirty = true;
podConfigs[buildId].buildSettings['SWIFT_VERSION'] = swiftVersion;
});
}
});
if (__dirty) {
fs.writeFileSync(podPbxPath, podXcodeproj.writeSync(), 'utf-8');
}
}
});
if (__dirty) {
fs.writeFileSync(podPbxPath, podXcodeproj.writeSync(), 'utf-8');
}
};

/**
Expand Down

0 comments on commit ae4d1fd

Please sign in to comment.