From ef2b03ea95c66913ddd4c5bcaa501db5c33d3cd8 Mon Sep 17 00:00:00 2001 From: Lawrence Lomax Date: Fri, 11 Feb 2022 04:19:42 -0800 Subject: [PATCH] Specialize error message when no xcode selected Summary: We can detect an xcode-select failure earlier on, right now this will be misleading as later healtchecks around `xctrace`/`xcodebuild` will fail and it's not clear why. If you don't have any Xcode selected, then we can detect this and mark it as an error. This can be done by looking out the output of the command. To do this we have to propogate the stdout of the shell-out back, so there's a subtype of the regular healtcheck. This is then inspected for it's path since `xcode-select` returns the same exit code if xcode isn't selected or at it's default state. Reviewed By: passy Differential Revision: D34168673 fbshipit-source-id: c0aa846bb251aaf026beb976a042b727c7cf1c24 --- desktop/doctor/src/index.tsx | 24 +++++++++++++++++------- desktop/flipper-common/src/doctor.tsx | 4 ++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/desktop/doctor/src/index.tsx b/desktop/doctor/src/index.tsx index 35991f2ea96..b5661855ad6 100644 --- a/desktop/doctor/src/index.tsx +++ b/desktop/doctor/src/index.tsx @@ -175,13 +175,22 @@ export function getHealthchecks(): FlipperDoctor.Healthchecks { isRequired: true, run: async (_: FlipperDoctor.EnvironmentInfo) => { const result = await tryExecuteCommand('xcode-select -p'); - const hasProblem = result.hasProblem; - const message = hasProblem - ? `Xcode version is not selected. You can select it using command "sudo xcode-select -switch Xcode.app". ${result.message}.` - : `Xcode version is selected. ${result.message}.`; + if (result.hasProblem) { + return { + hasProblem: true, + message: `Xcode version is not selected. You can select it using command "sudo xcode-select -switch Xcode.app". ${result.message}.`, + }; + } + const selectedXcode = result.stdout!.toString().trim(); + if (selectedXcode == '/Library/Developer/CommandLineTools') { + return { + hasProblem: true, + message: `xcode-select has no Xcode selected, You can select it using command "sudo xcode-select -switch Xcode.app".`, + }; + } return { - hasProblem, - message, + hasProblem: false, + message: `xcode-select has path of ${selectedXcode}.`, }; }, }, @@ -290,12 +299,13 @@ export async function runHealthchecks(): Promise< async function tryExecuteCommand( command: string, -): Promise { +): Promise { try { const output = await promisify(exec)(command); return { hasProblem: false, message: `Command "${command}" successfully executed with output: ${output.stdout}`, + stdout: output.stdout, }; } catch (err) { return { diff --git a/desktop/flipper-common/src/doctor.tsx b/desktop/flipper-common/src/doctor.tsx index 0c4f3aea4d4..aabb07728ac 100644 --- a/desktop/flipper-common/src/doctor.tsx +++ b/desktop/flipper-common/src/doctor.tsx @@ -69,6 +69,10 @@ export namespace FlipperDoctor { message: string; }; + export type SubprocessHealtcheckRunResult = HealthcheckRunResult & { + stdout?: string; + }; + export type CategoryResult = [ string, {