Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 17 additions & 1 deletion lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ function handleBuildSettings (platformConfig, locations, infoPlist) {
const deploymentTarget = platformConfig.getPreference('deployment-target', 'ios');
const swiftVersion = platformConfig.getPreference('SwiftVersion', 'ios');

const supportMac = platformConfig.getPreference('SupportMac', 'ios');
const disableMacTarget = supportMac !== undefined && supportMac.toString().toLowerCase() === 'false';

let project;

try {
Expand All @@ -283,7 +286,7 @@ function handleBuildSettings (platformConfig, locations, infoPlist) {

// no build settings provided and we don't need to update build settings for launch storyboards,
// then we don't need to parse and update .pbxproj file
if (origPkg === pkg && !targetDevice && !deploymentTarget && !swiftVersion) {
if (origPkg === pkg && !targetDevice && !deploymentTarget && !swiftVersion && !disableMacTarget) {
return Promise.resolve();
}

Expand All @@ -307,6 +310,19 @@ function handleBuildSettings (platformConfig, locations, infoPlist) {
project.xcode.updateBuildProperty('SWIFT_VERSION', swiftVersion);
}

if (disableMacTarget) {
events.emit('verbose', 'Disable MacOS target.');
// This whole conundrum is required in order to only change the settings of the PBXNativeTarget and not the PBXProject
Object.values(project.xcode.pbxNativeTargetSection())
.filter((item) => item.isa === 'PBXNativeTarget' && item.name)
.forEach((item) => {
const target = item.name.replace(/^['"]*|['"]*$/g, ''); // Remove leading and trailing quotes
project.xcode.updateBuildProperty('SUPPORTED_PLATFORMS', '"iphoneos iphonesimulator"', undefined, target);
project.xcode.updateBuildProperty('SUPPORTS_MACCATALYST', 'NO', undefined, target);
project.xcode.updateBuildProperty('SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD', 'NO', undefined, target);
});
}

project.write();

return Promise.resolve();
Expand Down
1 change: 1 addition & 0 deletions tests/spec/unit/fixtures/test-config-3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<preference name="target-device" value="handset" />
<preference name="deployment-target" value="11.0" />
<preference name="SwiftVersion" value="4.1" />
<preference name="SupportMac" value="true" />
</platform>

<access origin="http://*.apache.org" />
Expand Down
54 changes: 54 additions & 0 deletions tests/spec/unit/prepare.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,60 @@ describe('prepare', () => {
});
});

it('should support Mac apps by default', () => {
cfg2.name = () => 'SampleApp'; // new config does *not* have a name change
writeFileSyncSpy.and.callThrough();
return updateProject(cfg2, p.locations).then(() => {
const xcode = require('xcode');
const proj = new xcode.project(p.locations.pbxproj); /* eslint new-cap : 0 */
proj.parseSync();
const supportedPlatforms = proj.getBuildProperty('SUPPORTED_PLATFORMS');
expect(supportedPlatforms).toBeUndefined();
const supportsMacCatalyst = proj.getBuildProperty('SUPPORTS_MACCATALYST');
expect(supportsMacCatalyst).toBeUndefined();
const supportsMacIPhoneIPad = proj.getBuildProperty('SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD');
expect(supportsMacIPhoneIPad).toBeUndefined();
});
});

it('should support Mac apps if SupportMac preference is set to true', () => {
cfg3.name = () => 'SampleApp'; // new config does *not* have a name change
const pref = cfg3.doc.findall('platform[@name=\'ios\']/preference')
.filter(elem => elem.attrib.name.toLowerCase() === 'supportmac')[0];
pref.attrib.value = 'true';
writeFileSyncSpy.and.callThrough();
return updateProject(cfg3, p.locations).then(() => {
const xcode = require('xcode');
const proj = new xcode.project(p.locations.pbxproj); /* eslint new-cap : 0 */
proj.parseSync();
const supportedPlatforms = proj.getBuildProperty('SUPPORTED_PLATFORMS');
expect(supportedPlatforms).toBeUndefined();
const supportsMacCatalyst = proj.getBuildProperty('SUPPORTS_MACCATALYST');
expect(supportsMacCatalyst).toBeUndefined();
const supportsMacIPhoneIPad = proj.getBuildProperty('SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD');
expect(supportsMacIPhoneIPad).toBeUndefined();
});
});

it('should not support Mac apps if SupportMac preference is set to false', () => {
cfg3.name = () => 'SampleApp'; // new config does *not* have a name change
const pref = cfg3.doc.findall('platform[@name=\'ios\']/preference')
.filter(elem => elem.attrib.name.toLowerCase() === 'supportmac')[0];
pref.attrib.value = 'false';
writeFileSyncSpy.and.callThrough();
return updateProject(cfg3, p.locations).then(() => {
const xcode = require('xcode');
const proj = new xcode.project(p.locations.pbxproj); /* eslint new-cap : 0 */
proj.parseSync();
const supportedPlatforms = proj.getBuildProperty('SUPPORTED_PLATFORMS');
expect(supportedPlatforms).toEqual('"iphoneos iphonesimulator"');
const supportsMacCatalyst = proj.getBuildProperty('SUPPORTS_MACCATALYST');
expect(supportsMacCatalyst).toEqual('NO');
const supportsMacIPhoneIPad = proj.getBuildProperty('SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD');
expect(supportsMacIPhoneIPad).toEqual('NO');
});
});

it('Test#002 : should write out the app id to info plist as CFBundleIdentifier', () => {
const orig = cfg.getAttribute;
cfg.getAttribute = function (name) {
Expand Down