Improve xcode version mismatch messaging
Summary: This runs in a very hot loop (which I will change shortly) However, there's also some simplification that we can do here: - Only look for `Simulator.app` processes instead of all the processes. This limits the amount of string comparison to do. If there's a `Simulator.app` running, then we know a sim is running for that Xcode. - Use piping to extract the launch path of the process, instead of then regex'ing this out. - Use a simpler substring match to determine if paths have a different start. Reviewed By: passy Differential Revision: D33891296 fbshipit-source-id: e37d5f260fc6c6113be9c5268b7c8cffb4057b9a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1e309ddd5c
commit
e16662a28f
@@ -7,7 +7,7 @@
|
|||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {parseXcodeFromCoreSimPath} from '../iOSDeviceManager';
|
import {checkXcodeVersionMismatch} from '../iOSDeviceManager';
|
||||||
import {getLogger} from 'flipper-common';
|
import {getLogger} from 'flipper-common';
|
||||||
import {IOSBridge} from '../IOSBridge';
|
import {IOSBridge} from '../IOSBridge';
|
||||||
import {FlipperServerImpl} from '../../../FlipperServerImpl';
|
import {FlipperServerImpl} from '../../../FlipperServerImpl';
|
||||||
@@ -36,46 +36,28 @@ afterEach(() => {
|
|||||||
setFlipperServerConfig(undefined);
|
setFlipperServerConfig(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
const standardCoresimulatorLog =
|
test('test checkXcodeVersionMismatch with correct Simulator.app', () => {
|
||||||
'username 1264 0.0 0.1 5989740 41648 ?? Ss 2:23PM 0:12.92 /Applications/Xcode_12.4.0_fb.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/libexec/mobileassetd';
|
const invalidVersion = checkXcodeVersionMismatch(
|
||||||
|
[
|
||||||
const nonStandardCoresimulatorLog =
|
'/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator',
|
||||||
'username 1264 0.0 0.1 5989740 41648 ?? Ss 2:23PM 0:12.92 /Some/Random/Path/Xcode_12.4.0_fb.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/libexec/mobileassetd';
|
],
|
||||||
|
'/Applications/Xcode.app/Contents/Developer',
|
||||||
const nonStandardSpecialCharacterAphanumericCoresimulatorLog =
|
);
|
||||||
'username 1264 0.0 0.1 5989740 41648 ?? Ss 2:23PM 0:12.92 /Some_R@d0m/Path-3455355/path(2)+connection/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/libexec/mobileassetd';
|
expect(invalidVersion).toEqual(undefined);
|
||||||
|
|
||||||
test('test parseXcodeFromCoreSimPath from non standard locations', () => {
|
|
||||||
const match = parseXcodeFromCoreSimPath(nonStandardCoresimulatorLog);
|
|
||||||
expect(match && match.length > 0).toBeTruthy();
|
|
||||||
expect(
|
|
||||||
// @ts-ignore the null and non zero lenght check for match is already done above
|
|
||||||
match[0],
|
|
||||||
).toEqual('/Some/Random/Path/Xcode_12.4.0_fb.app/Contents/Developer');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('test parseXcodeFromCoreSimPath from non standard alphanumeric special character locations', () => {
|
test('test checkXcodeVersionMismatch with an incorrect Simulator.app', () => {
|
||||||
const match = parseXcodeFromCoreSimPath(
|
const invalidVersion = checkXcodeVersionMismatch(
|
||||||
nonStandardSpecialCharacterAphanumericCoresimulatorLog,
|
[
|
||||||
|
'/Applications/Xcode_Incorrect.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator',
|
||||||
|
],
|
||||||
|
'/Applications/Xcode.app/Contents/Developer',
|
||||||
);
|
);
|
||||||
expect(match && match.length > 0).toBeTruthy();
|
expect(invalidVersion).toEqual(
|
||||||
expect(
|
'/Applications/Xcode_Incorrect.app/Contents/Developer',
|
||||||
// @ts-ignore the null and non zero lenght check for match is already done above
|
|
||||||
match[0],
|
|
||||||
).toEqual(
|
|
||||||
'/Some_R@d0m/Path-3455355/path(2)+connection/Xcode.app/Contents/Developer',
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('test parseXcodeFromCoreSimPath from standard locations', () => {
|
|
||||||
const match = parseXcodeFromCoreSimPath(standardCoresimulatorLog);
|
|
||||||
expect(match && match.length > 0).toBeTruthy();
|
|
||||||
expect(
|
|
||||||
// @ts-ignore the null and non zero lenght check for match is already done above
|
|
||||||
match[0],
|
|
||||||
).toEqual('/Applications/Xcode_12.4.0_fb.app/Contents/Developer');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('test getAllPromisesForQueryingDevices when xcode detected', () => {
|
test('test getAllPromisesForQueryingDevices when xcode detected', () => {
|
||||||
const flipperServer = new FlipperServerImpl(
|
const flipperServer = new FlipperServerImpl(
|
||||||
getFlipperServerConfig(),
|
getFlipperServerConfig(),
|
||||||
|
|||||||
@@ -231,21 +231,27 @@ export class IOSDeviceManager {
|
|||||||
try {
|
try {
|
||||||
let {stdout: xcodeCLIVersion} = await exec('xcode-select -p');
|
let {stdout: xcodeCLIVersion} = await exec('xcode-select -p');
|
||||||
xcodeCLIVersion = xcodeCLIVersion!.toString().trim();
|
xcodeCLIVersion = xcodeCLIVersion!.toString().trim();
|
||||||
const {stdout} = await exec('ps aux | grep CoreSimulator');
|
const {stdout} = await exec(
|
||||||
for (const line of stdout!.toString().split('\n')) {
|
"pgrep Simulator | xargs ps | grep Simulator.app | awk '{print $NF}'",
|
||||||
const match = parseXcodeFromCoreSimPath(line);
|
);
|
||||||
const runningVersion =
|
for (const runningSimulatorApp of stdout!.toString().split('\n')) {
|
||||||
match && match.length > 0 ? match[0].trim() : null;
|
if (!runningSimulatorApp) {
|
||||||
if (runningVersion && runningVersion !== xcodeCLIVersion) {
|
continue;
|
||||||
const errorMessage = `Xcode version mismatch: Simulator is running from "${runningVersion}" while Xcode CLI is "${xcodeCLIVersion}". Running "xcode-select --switch ${runningVersion}" can fix this. For example: "sudo xcode-select -s /Applications/Xcode.app/Contents/Developer"`;
|
|
||||||
this.flipperServer.emit('notification', {
|
|
||||||
type: 'error',
|
|
||||||
title: 'Xcode version mismatch',
|
|
||||||
description: '' + errorMessage,
|
|
||||||
});
|
|
||||||
this.xcodeVersionMismatchFound = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
if (runningSimulatorApp.startsWith(xcodeCLIVersion)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const runningVersion =
|
||||||
|
runningSimulatorApp.split('/Contents/Developer')[0] +
|
||||||
|
'/Contents/Developer';
|
||||||
|
const errorMessage = `Xcode version mismatch: Simulator is running from "${runningVersion}" while Xcode CLI is "${xcodeCLIVersion}". Running "xcode-select --switch ${runningVersion}" can fix this. For example: "sudo xcode-select -s /Applications/Xcode.app/Contents/Developer"`;
|
||||||
|
this.flipperServer.emit('notification', {
|
||||||
|
type: 'error',
|
||||||
|
title: 'Xcode version mismatch',
|
||||||
|
description: '' + errorMessage,
|
||||||
|
});
|
||||||
|
this.xcodeVersionMismatchFound = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to determine Xcode version:', e);
|
console.error('Failed to determine Xcode version:', e);
|
||||||
@@ -253,15 +259,28 @@ export class IOSDeviceManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function checkXcodeVersionMismatch(
|
||||||
|
runningSimulatorApps: Array<string>,
|
||||||
|
xcodeCLIVersion: string,
|
||||||
|
): string | undefined {
|
||||||
|
for (const runningSimulatorApp of runningSimulatorApps) {
|
||||||
|
if (!runningSimulatorApp) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (runningSimulatorApp.startsWith(xcodeCLIVersion)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
runningSimulatorApp.split('/Contents/Developer')[0] +
|
||||||
|
'/Contents/Developer'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
function getActiveDevices(
|
function getActiveDevices(
|
||||||
idbPath: string,
|
idbPath: string,
|
||||||
isPhysicalDeviceEnabled: boolean,
|
isPhysicalDeviceEnabled: boolean,
|
||||||
): Promise<Array<IOSDeviceParams>> {
|
): Promise<Array<IOSDeviceParams>> {
|
||||||
return new IDBBridge(idbPath, isPhysicalDeviceEnabled).getActiveDevices(true);
|
return new IDBBridge(idbPath, isPhysicalDeviceEnabled).getActiveDevices(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseXcodeFromCoreSimPath(
|
|
||||||
line: string,
|
|
||||||
): RegExpMatchArray | null {
|
|
||||||
return line.match(/\/[\/\w@)(\-\+]*\/Xcode[^/]*\.app\/Contents\/Developer/);
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user