Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add support for 'pod install' in VM based environments #5144

Merged
merged 13 commits into from
Oct 27, 2021
Merged
22 changes: 16 additions & 6 deletions cli/src/ios/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { readFile, writeFile } from '@ionic/utils-fs';
import { which } from '@ionic/utils-subprocess';
import { resolve } from 'path';

import c from '../colors';
Expand Down Expand Up @@ -86,13 +87,22 @@ export async function editProjectSettingsIOS(config: Config): Promise<void> {
await writeFile(pbxPath, pbxContent, { encoding: 'utf-8' });
}

export function shouldPodInstall(
config: Config,
platformName: string,
): boolean {
// Don't run pod install or xcodebuild if not on macOS
if (config.cli.os !== OS.Mac && platformName === 'ios') {
export async function canRunPodInstall(): Promise<boolean> {
try {
await which('pod');
} catch (e) {
return false;
}

return true;
}

export async function canRunXcodebuild(): Promise<boolean> {
try {
await which('xcodebuild');
} catch (e) {
return false;
}

return true;
}
33 changes: 23 additions & 10 deletions cli/src/ios/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
needsStaticPod,
} from '../cordova';
import type { Config } from '../definitions';
import { OS } from '../definitions';
import { fatal } from '../errors';
import { logger } from '../log';
import {
Expand All @@ -35,7 +36,7 @@ import { resolveNode } from '../util/node';
import { runCommand } from '../util/subprocess';
import { extractTemplate } from '../util/template';

import { getIOSPlugins, shouldPodInstall } from './common';
import { getIOSPlugins, canRunPodInstall, canRunXcodebuild } from './common';

const platform = 'ios';

Expand Down Expand Up @@ -79,7 +80,14 @@ export async function installCocoaPodsPlugins(
plugins: Plugin[],
deployment: boolean,
): Promise<void> {
if (shouldPodInstall(config, platform)) {
const podCommandExists = await canRunPodInstall();
if (platform === 'ios' && podCommandExists) {
if (config.cli.os !== OS.Mac) {
logger.warn(
'Running "pod install" on a non-Mac OS may lead to unexpected results',
);
}

thomasvidas marked this conversation as resolved.
Show resolved Hide resolved
await runTask(
`Updating iOS native dependencies with ${c.input(
`${config.ios.podPath} install`,
Expand All @@ -89,7 +97,7 @@ export async function installCocoaPodsPlugins(
},
);
} else {
logger.warn('Skipping pod install on unsupported OS');
logger.warn('Skipping pod install because "pod" is not installed');
thomasvidas marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -118,13 +126,18 @@ async function updatePodfile(
{ cwd: config.ios.nativeProjectDirAbs },
);

await runCommand(
'xcodebuild',
['-project', basename(`${config.ios.nativeXcodeProjDirAbs}`), 'clean'],
{
cwd: config.ios.nativeProjectDirAbs,
},
);
const isXcodebuildAvailable = await canRunXcodebuild();
if (isXcodebuildAvailable) {
await runCommand(
'xcodebuild',
['-project', basename(`${config.ios.nativeXcodeProjDirAbs}`), 'clean'],
{
cwd: config.ios.nativeProjectDirAbs,
},
);
} else {
logger.warn('Unable to find "xcodebuild". Skipping xcodebuild step...');
thomasvidas marked this conversation as resolved.
Show resolved Hide resolved
}
}

async function generatePodFile(
Expand Down