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
This commit is contained in:
Lawrence Lomax
2022-02-11 04:19:42 -08:00
committed by Facebook GitHub Bot
parent c8c40bca17
commit ef2b03ea95
2 changed files with 21 additions and 7 deletions

View File

@@ -175,13 +175,22 @@ export function getHealthchecks(): FlipperDoctor.Healthchecks {
isRequired: true, isRequired: true,
run: async (_: FlipperDoctor.EnvironmentInfo) => { run: async (_: FlipperDoctor.EnvironmentInfo) => {
const result = await tryExecuteCommand('xcode-select -p'); const result = await tryExecuteCommand('xcode-select -p');
const hasProblem = result.hasProblem; if (result.hasProblem) {
const message = hasProblem return {
? `Xcode version is not selected. You can select it using command "sudo xcode-select -switch <path/to/>Xcode.app". ${result.message}.` hasProblem: true,
: `Xcode version is selected. ${result.message}.`; message: `Xcode version is not selected. You can select it using command "sudo xcode-select -switch <path/to/>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 <path/to/>Xcode.app".`,
};
}
return { return {
hasProblem, hasProblem: false,
message, message: `xcode-select has path of ${selectedXcode}.`,
}; };
}, },
}, },
@@ -290,12 +299,13 @@ export async function runHealthchecks(): Promise<
async function tryExecuteCommand( async function tryExecuteCommand(
command: string, command: string,
): Promise<FlipperDoctor.HealthcheckRunResult> { ): Promise<FlipperDoctor.SubprocessHealtcheckRunResult> {
try { try {
const output = await promisify(exec)(command); const output = await promisify(exec)(command);
return { return {
hasProblem: false, hasProblem: false,
message: `Command "${command}" successfully executed with output: ${output.stdout}`, message: `Command "${command}" successfully executed with output: ${output.stdout}`,
stdout: output.stdout,
}; };
} catch (err) { } catch (err) {
return { return {

View File

@@ -69,6 +69,10 @@ export namespace FlipperDoctor {
message: string; message: string;
}; };
export type SubprocessHealtcheckRunResult = HealthcheckRunResult & {
stdout?: string;
};
export type CategoryResult = [ export type CategoryResult = [
string, string,
{ {