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

fix: Tune simulator app architecture validation #2492

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Changes from all commits
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
55 changes: 45 additions & 10 deletions lib/app-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const MAX_ARCHIVE_SCAN_DEPTH = 1;
export const SUPPORTED_EXTENSIONS = [IPA_EXT, APP_EXT];
const MACOS_RESOURCE_FOLDER = '__MACOSX';
const SANITIZE_REPLACEMENT = '-';
const INTEL_ARCH = 'x86_64';

/**
* Verify whether the given application is compatible to the
Expand Down Expand Up @@ -56,27 +57,47 @@ export async function verifyApplicationPlatform() {
return;
}

const executablePath = path.resolve(this.opts.app, await this.appInfosCache.extractExecutableName(this.opts.app));
const executablePath = path.resolve(
this.opts.app,
await this.appInfosCache.extractExecutableName(this.opts.app)
);
const [resFile, resUname] = await B.all([
exec('lipo', ['-info', executablePath]),
exec('uname', ['-m']),
]);
const bundleExecutableInfo = _.trim(resFile.stdout);
this.log.debug(bundleExecutableInfo);
const arch = _.trim(resUname.stdout);
const isAppleSilicon = os.cpus()[0].model.includes('Apple');
const processArch = _.trim(resUname.stdout);
this.log.debug(`Current process architecture: ${processArch}`);
const isAppleSiliconCpu = isAppleSilicon();
this.log.debug(`Is Apple Silicon CPU: ${isAppleSiliconCpu}`);
if (isAppleSiliconCpu && processArch === INTEL_ARCH) {
this.log.warn(
`It looks like the Appium server process is running under Rosetta emulation. ` +
`This might lead to various performance/compatibility issues while running tests on Simulator. ` +
`Consider using binaries compiled natively for the ARM64 architecture to run Appium server ` +
`with this driver.`
);
}
if (_.includes(bundleExecutableInfo, processArch)) {
return;
}
const hasRosetta = isAppleSiliconCpu && await isRosettaInstalled();
const isIntelApp = _.includes(bundleExecutableInfo, INTEL_ARCH);
// We cannot run Simulator builds compiled for arm64 on Intel machines
// Rosetta allows only to run Intel ones on arm64
if (
!_.includes(bundleExecutableInfo, arch) &&
!(isAppleSilicon && _.includes(bundleExecutableInfo, 'x86_64'))
(isIntelApp && (!isAppleSiliconCpu || hasRosetta)) || (!isIntelApp && isAppleSiliconCpu)
) {
throw new Error(
`The ${this.opts.bundleId} application does not support the ${arch} Simulator ` +
`architecture:\n${bundleExecutableInfo}\n\n` +
`Please rebuild your application to support the ${arch} platform.`,
);
return;
}
const advice = isIntelApp && isAppleSiliconCpu && !hasRosetta
? `Please install Rosetta and try again.`
: `Please rebuild your application to support the ${processArch} platform.`;
throw new Error(
`The ${this.opts.bundleId} application does not support the ${processArch} Simulator ` +
`architecture:\n${bundleExecutableInfo}\n\n${advice}`
);
}

/**
Expand Down Expand Up @@ -666,6 +687,20 @@ export async function onPostConfigureApp({cachedAppInfo, isUrl, appPath}) {
};
}

/**
* @returns {Promise<boolean>}
*/
async function isRosettaInstalled() {
return await fs.exists('/Library/Apple/usr/share/rosetta/rosetta');
}

/**
* @returns {boolean}
*/
function isAppleSilicon() {
return os.cpus()[0].model.includes('Apple');
}

/**
* @typedef {import('./driver').XCUITestDriver} XCUITestDriver
*/
Loading