From 3693b4971c62ec08f5766dd0745795f2827343eb Mon Sep 17 00:00:00 2001 From: Anton Kastritskiy Date: Thu, 23 May 2024 08:02:44 -0700 Subject: [PATCH] exact command to run for all xcode select issues when possible Reviewed By: lblasa Differential Revision: D57724756 fbshipit-source-id: fbf0c523def83cb51464720019ea10a3e6cf5210 --- .../fb-stubs/validateSelectedXcodeVersion.tsx | 1 + desktop/doctor/src/index.tsx | 30 ++++++++++++++--- desktop/flipper-common/src/doctor.tsx | 10 ++++-- .../src/sandy-chrome/doctor/index.tsx | 32 +++++++++---------- 4 files changed, 48 insertions(+), 25 deletions(-) diff --git a/desktop/doctor/src/fb-stubs/validateSelectedXcodeVersion.tsx b/desktop/doctor/src/fb-stubs/validateSelectedXcodeVersion.tsx index 185020e92bb..1b5ca7d1e4f 100644 --- a/desktop/doctor/src/fb-stubs/validateSelectedXcodeVersion.tsx +++ b/desktop/doctor/src/fb-stubs/validateSelectedXcodeVersion.tsx @@ -11,6 +11,7 @@ import {FlipperDoctor} from 'flipper-common'; export async function validateSelectedXcodeVersion( _selectedPath: string, + _availableXcode: string | null, ): Promise { return { hasProblem: false, diff --git a/desktop/doctor/src/index.tsx b/desktop/doctor/src/index.tsx index efc956a14df..207153ada9b 100644 --- a/desktop/doctor/src/index.tsx +++ b/desktop/doctor/src/index.tsx @@ -251,22 +251,39 @@ export function getHealthchecks(): FlipperDoctor.Healthchecks { run: async ( _: FlipperDoctor.EnvironmentInfo, ): Promise => { - // TODO check for an existing Xcode + const allApps = + await fs_extra.promises.readdir('/Applications'); + // Xcode_14.2.0_xxxxxxx.app + // Xcode_14.3.1_xxxxxxxxxx.app + // Xcode_15.0.0_xxxxxxxxxx.app + // Xcode.app + const latestXCode = allApps + .filter((a) => a.startsWith('Xcode')) + .sort() + .pop(); + const availableXcode = latestXCode + ? path.join('/Applications', latestXCode) + : null; + const result = await tryExecuteCommand('xcode-select -p'); if (result.fail) { return { hasProblem: true, message: [ 'ios.xcode-select--not_set', - {message: result.message}, + {message: result.message, availableXcode}, ], }; } + const selectedXcode = result.stdout.toString().trim(); if (selectedXcode == '/Library/Developer/CommandLineTools') { return { hasProblem: true, - message: ['ios.xcode-select--no_xcode_selected'], + message: [ + 'ios.xcode-select--no_xcode_selected', + {availableXcode}, + ], }; } if ((await fs_extra.pathExists(selectedXcode)) == false) { @@ -274,12 +291,15 @@ export function getHealthchecks(): FlipperDoctor.Healthchecks { hasProblem: true, message: [ 'ios.xcode-select--nonexisting_selected', - {selected: selectedXcode}, + {selected: selectedXcode, availableXcode}, ], }; } const validatedXcodeVersion = - await validateSelectedXcodeVersion(selectedXcode); + await validateSelectedXcodeVersion( + selectedXcode, + availableXcode, + ); if (validatedXcodeVersion.hasProblem) { return validatedXcodeVersion; } diff --git a/desktop/flipper-common/src/doctor.tsx b/desktop/flipper-common/src/doctor.tsx index e4ac0e05a64..7798b635669 100644 --- a/desktop/flipper-common/src/doctor.tsx +++ b/desktop/flipper-common/src/doctor.tsx @@ -167,8 +167,10 @@ export namespace FlipperDoctor { 'ios.xcode--not_installed': []; 'ios.xcode-select--set': [{selected: string}]; - 'ios.xcode-select--not_set': [{message: string}]; - 'ios.xcode-select--no_xcode_selected': []; + 'ios.xcode-select--not_set': [ + {message: string; availableXcode: string | null}, + ]; + 'ios.xcode-select--no_xcode_selected': [{availableXcode: string | null}]; 'ios.xcode-select--noop': []; 'ios.xcode-select--custom_path': [ { @@ -182,7 +184,9 @@ export namespace FlipperDoctor { latestXCode: string; }, ]; - 'ios.xcode-select--nonexisting_selected': [{selected: string}]; + 'ios.xcode-select--nonexisting_selected': [ + {selected: string; availableXcode: string | null}, + ]; 'ios.sdk--installed': [{platforms: string[]}]; 'ios.sdk--not_installed': []; diff --git a/desktop/flipper-ui/src/sandy-chrome/doctor/index.tsx b/desktop/flipper-ui/src/sandy-chrome/doctor/index.tsx index 898794b679a..8f7dd4e2a53 100644 --- a/desktop/flipper-ui/src/sandy-chrome/doctor/index.tsx +++ b/desktop/flipper-ui/src/sandy-chrome/doctor/index.tsx @@ -33,6 +33,16 @@ const CommonOpenSSLInstalled = ( {props.output} ); +const XcodeSelectSwitch = ({ + availableXcode, +}: { + availableXcode: string | null; +}) => ( + /Xcode.app'}`} + /> +); const CommonOpenSSLNotInstalled = ( props: PropsFor<'common.openssl--not_installed'>, @@ -162,28 +172,20 @@ const XcodeSelectSet = (props: PropsFor<'ios.xcode-select--set'>) => ( {props.selected} ); -const XcodeSelectNotSet = (_props: PropsFor<'ios.xcode-select--not_set'>) => ( +const XcodeSelectNotSet = (props: PropsFor<'ios.xcode-select--not_set'>) => ( xcode-select path not selected. xcode-select -p failed. To fix it run this command: - /Xcode.app`} - /> + ); const XcodeSelectNoXcode = ( - _props: PropsFor<'ios.xcode-select--no_xcode_selected'>, + props: PropsFor<'ios.xcode-select--no_xcode_selected'>, ) => ( xcode-select has no Xcode selected. To fix it it run this command: - /Xcode.app`} - /> + ); @@ -206,11 +208,7 @@ const XcodeSelectNonExistingSelected = ( xcode-select is pointing at a path that does not exist: {props.selected} - /Xcode.app`} - /> + );