From 9973014116fcaf14407fa2c898b51fcd5bf3e61c Mon Sep 17 00:00:00 2001 From: Lawrence Lomax Date: Fri, 11 Feb 2022 00:32:28 -0800 Subject: [PATCH] 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 --- .../devices/ios/__tests__/iOSDevice.node.tsx | 30 ++++++++++++++++++- .../src/devices/ios/iOSDeviceManager.tsx | 29 ++++++++++++++---- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/desktop/flipper-server-core/src/devices/ios/__tests__/iOSDevice.node.tsx b/desktop/flipper-server-core/src/devices/ios/__tests__/iOSDevice.node.tsx index 0b659858b..307053f47 100644 --- a/desktop/flipper-server-core/src/devices/ios/__tests__/iOSDevice.node.tsx +++ b/desktop/flipper-server-core/src/devices/ios/__tests__/iOSDevice.node.tsx @@ -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, diff --git a/desktop/flipper-server-core/src/devices/ios/iOSDeviceManager.tsx b/desktop/flipper-server-core/src/devices/ios/iOSDeviceManager.tsx index a419d6808..f40ba3fce 100644 --- a/desktop/flipper-server-core/src/devices/ios/iOSDeviceManager.tsx +++ b/desktop/flipper-server-core/src/devices/ios/iOSDeviceManager.tsx @@ -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, xcodeCLIVersion: string, ): string | undefined { @@ -241,3 +240,23 @@ export function checkXcodeVersionMismatch( } return undefined; } + +export function checkXcodeVersionMismatch( + runningSimulatorApps: Array, + 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"`; +}