Skip to content

Commit

Permalink
Specialize error message when no xcode selected
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lawrencelomax authored and facebook-github-bot committed Feb 11, 2022
1 parent c8c40bc commit ef2b03e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
24 changes: 17 additions & 7 deletions desktop/doctor/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path/to/>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 <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 {
hasProblem,
message,
hasProblem: false,
message: `xcode-select has path of ${selectedXcode}.`,
};
},
},
Expand Down Expand Up @@ -290,12 +299,13 @@ export async function runHealthchecks(): Promise<

async function tryExecuteCommand(
command: string,
): Promise<FlipperDoctor.HealthcheckRunResult> {
): Promise<FlipperDoctor.SubprocessHealtcheckRunResult> {
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 {
Expand Down
4 changes: 4 additions & 0 deletions desktop/flipper-common/src/doctor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export namespace FlipperDoctor {
message: string;
};

export type SubprocessHealtcheckRunResult = HealthcheckRunResult & {
stdout?: string;
};

export type CategoryResult = [
string,
{
Expand Down

0 comments on commit ef2b03e

Please sign in to comment.