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

chore: Add validation of Simulator binary architecture #2320

Merged
merged 8 commits into from
Feb 6, 2024
Merged
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
Prev Previous commit
Next Next commit
Tune
  • Loading branch information
mykola-mokhnach committed Feb 5, 2024
commit 2ed6b0c6f0155ad10dd479a6e6da609d8bdac373
23 changes: 15 additions & 8 deletions lib/app-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import log from './logger.js';
import {LRUCache} from 'lru-cache';
import os from 'node:os';
import {exec} from 'teen_process';
import B from 'bluebird';

const STRINGSDICT_RESOURCE = '.stringsdict';
const STRINGS_RESOURCE = '.strings';
Expand Down Expand Up @@ -129,18 +130,24 @@ export async function verifyApplicationPlatform(app, expectedPlatform) {
}
if (isSimulator) {
const executablePath = path.resolve(app, await extractExecutableName(app));
const {stdout} = await exec('file', [executablePath]);
log.debug(_.trim(stdout));
const {stdout: archRaw} = await exec('uname', ['-m']);
const arch = _.trim(archRaw);
const [resFile, resUname] = await B.all([
exec('file', [executablePath]),
exec('uname', ['-m']),
]);
log.debug(_.trim(resFile.stdout));
const arch = _.trim(resUname.stdout);
const isArm = os.cpus[0].model.includes('Apple');
// We cannot run Simulator builds compiled for arm64 on Intel machines
// Rosetta allows only to run Intel ones on arm64
if (!_.includes(stdout, `executable ${arch}`) && !(isArm && _.includes(stdout, 'executable x86_64'))) {
if (
!_.includes(resFile.stdout, `executable ${arch}`) &&
!(isArm && _.includes(resFile.stdout, 'executable x86_64'))
) {
const bundleId = await extractBundleId(app);
throw new Error(`The ${bundleId} application is built for non-${arch} Simulator ` +
`architecture:\n${_.trim(stdout)}\nand is not supported on the current platform. ` +
`Please rebuild your application to support the ${arch} platform.`
throw new Error(
`The ${bundleId} application does not support the ${arch} Simulator ` +
`architecture:\n${_.trim(resFile.stdout)}\n\n` +
`Please rebuild your application to support the ${arch} platform.`,
);
}
}
Expand Down
Loading