iOS CLI version mismatch detection

Summary:
Trying to detect version mismatches between the running Simulator and the version of Xcode's CLI tools.

What is done in this check:
- The running path of the running simulator is queries from `ps`
- The path of Xcode CLI tools is queried using `xcode-select -p`.
- The two paths are compared if they differ

Reviewed By: jknoxville, passy

Differential Revision: D15803238

fbshipit-source-id: 6638312505fc950ff7869fd55494984bfffb677b
This commit is contained in:
Daniel Büchele
2019-06-13 06:38:53 -07:00
committed by Facebook Github Bot
parent fd89d73be5
commit eb36e667d4

View File

@@ -53,6 +53,7 @@ if (typeof window !== 'undefined') {
}
function queryDevices(store: Store, logger: Logger): Promise<void> {
checkXcodeVersionMismatch();
const {connections} = store.getState();
const currentDeviceIDs: Set<string> = new Set(
connections.devices
@@ -143,6 +144,34 @@ function getActiveDevices(): Promise<Array<IOSDeviceParams>> {
});
}
let xcodeVersionMismatchFound = false;
async function checkXcodeVersionMismatch() {
if (xcodeVersionMismatchFound) {
return;
}
const exec = promisify(child_process.exec);
try {
let {stdout: xcodeCLIVersion} = await exec('xcode-select -p');
xcodeCLIVersion = xcodeCLIVersion.trim();
const {stdout} = await exec('ps aux | grep CoreSimulator');
for (let line of stdout.split('\n')) {
const match = line.match(
/\/Applications\/Xcode[^/]*\.app\/Contents\/Developer/,
);
const runningVersion = match && match.length > 0 ? match[0].trim() : null;
if (runningVersion && runningVersion !== xcodeCLIVersion) {
console.error(
`Xcode version mismatch: Simulator is running from "${runningVersion}" while Xcode CLI is "${xcodeCLIVersion}". Running "xcode-select --switch ${runningVersion}" can fix this.`,
);
xcodeVersionMismatchFound = true;
break;
}
}
} catch (e) {
console.error(e);
}
}
export async function getActiveDevicesAndSimulators(): Promise<
Array<IOSDevice>,
> {