From eb36e667d4d1ef31eadbe610385bfab8c607990c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=BCchele?= Date: Thu, 13 Jun 2019 06:38:53 -0700 Subject: [PATCH] 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 --- src/dispatcher/iOSDevice.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/dispatcher/iOSDevice.js b/src/dispatcher/iOSDevice.js index de78bc359..2f1222128 100644 --- a/src/dispatcher/iOSDevice.js +++ b/src/dispatcher/iOSDevice.js @@ -53,6 +53,7 @@ if (typeof window !== 'undefined') { } function queryDevices(store: Store, logger: Logger): Promise { + checkXcodeVersionMismatch(); const {connections} = store.getState(); const currentDeviceIDs: Set = new Set( connections.devices @@ -143,6 +144,34 @@ function getActiveDevices(): Promise> { }); } +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, > {