Fix error message when there's no xcode-select'ed Xcode

Summary:
This error messaging is confusing for device only users. These users may only be running against a device **without xcode installed**, which is supported.

However, we also need to handle the case where a user has a sim running and they haven't xcode-select'd as this will mean that the sim is working fine, but the user has no way of knowing why Flipper is not working.

Reviewed By: passy

Differential Revision: D34140277

fbshipit-source-id: f9b035b6c7918424d6131d1dfcdba10acf438fa8
This commit is contained in:
Lawrence Lomax
2022-02-11 00:32:28 -08:00
committed by Facebook GitHub Bot
parent 9bee6759cb
commit 9973014116
2 changed files with 53 additions and 6 deletions

View File

@@ -75,6 +75,14 @@ test('test checkXcodeVersionMismatch with correct Simulator.app', () => {
expect(invalidVersion).toEqual(undefined);
});
test('test checkXcodeVersionMismatch with no running Simulator.app', () => {
const invalidVersion = checkXcodeVersionMismatch(
[],
'/Applications/Xcode.app/Contents/Developer',
);
expect(invalidVersion).toEqual(undefined);
});
test('test checkXcodeVersionMismatch with an incorrect Simulator.app', () => {
const invalidVersion = checkXcodeVersionMismatch(
[
@@ -82,11 +90,31 @@ test('test checkXcodeVersionMismatch with an incorrect Simulator.app', () => {
],
'/Applications/Xcode.app/Contents/Developer',
);
expect(invalidVersion).toEqual(
expect(invalidVersion).toContain(
'/Applications/Xcode_Incorrect.app/Contents/Developer',
);
});
test('test checkXcodeVersionMismatch with no sims running and no xcode-select', () => {
const invalidVersion = checkXcodeVersionMismatch(
[],
'/Library/Developer/CommandLineTools',
);
expect(invalidVersion).toEqual(undefined);
});
test('test checkXcodeVersionMismatch with no sims running and no xcode-select', () => {
const invalidVersion = checkXcodeVersionMismatch(
[
'/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/Contents/MacOS/Simulator',
],
'/Library/Developer/CommandLineTools',
);
expect(invalidVersion).toContain(
'A Simulator is running and "xcode-select" has not been used',
);
});
test('test queryDevices when simctl used', async () => {
const ios = new IOSDeviceManager(
fakeFlipperServer,

View File

@@ -204,18 +204,17 @@ export class IOSDeviceManager {
.toString()
.split('\n')
.filter((application) => application.length > 0);
const mismatchedVersion = checkXcodeVersionMismatch(
const errorMessage = checkXcodeVersionMismatch(
runningSimulatorApplications,
xcodeCLIVersion,
);
if (mismatchedVersion === undefined) {
if (errorMessage === undefined) {
return;
}
const errorMessage = `Xcode version mismatch: Simulator is running from "${mismatchedVersion}" while Xcode CLI is "${xcodeCLIVersion}". Running "xcode-select --switch ${xcodeCLIVersion}" 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,
description: errorMessage,
});
} catch (e) {
console.error('Failed to determine Xcode version:', e);
@@ -223,7 +222,7 @@ export class IOSDeviceManager {
}
}
export function checkXcodeVersionMismatch(
function confirmSimulatorAppMatchesThatOfXcodeSelect(
runningSimulatorApps: Array<string>,
xcodeCLIVersion: string,
): string | undefined {
@@ -241,3 +240,23 @@ export function checkXcodeVersionMismatch(
}
return undefined;
}
export function checkXcodeVersionMismatch(
runningSimulatorApps: Array<string>,
xcodeCLIVersion: string,
): string | undefined {
if (runningSimulatorApps.length === 0) {
return undefined;
}
if (xcodeCLIVersion == '/Library/Developer/CommandLineTools') {
return `A Simulator is running and "xcode-select" has not been used, please run "xcode-select" for the Xcode that is running the simulator at ${runningSimulatorApps}`;
}
const mismatchedVersion = confirmSimulatorAppMatchesThatOfXcodeSelect(
runningSimulatorApps,
xcodeCLIVersion,
);
if (mismatchedVersion === undefined) {
return;
}
return `Xcode version mismatch: Simulator is running from "${mismatchedVersion}" while Xcode CLI is "${xcodeCLIVersion}". Running "xcode-select --switch ${xcodeCLIVersion}" can fix this. For example: "sudo xcode-select -s /Applications/Xcode.app/Contents/Developer"`;
}