Skip to content

Commit

Permalink
exact command to run for all xcode select issues when possible
Browse files Browse the repository at this point in the history
Reviewed By: lblasa

Differential Revision: D57724756

fbshipit-source-id: fbf0c523def83cb51464720019ea10a3e6cf5210
  • Loading branch information
antonk52 authored and facebook-github-bot committed May 23, 2024
1 parent 93f378c commit 3693b49
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {FlipperDoctor} from 'flipper-common';

export async function validateSelectedXcodeVersion(
_selectedPath: string,
_availableXcode: string | null,
): Promise<FlipperDoctor.HealthcheckRunResult> {
return {
hasProblem: false,
Expand Down
30 changes: 25 additions & 5 deletions desktop/doctor/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,35 +251,55 @@ export function getHealthchecks(): FlipperDoctor.Healthchecks {
run: async (
_: FlipperDoctor.EnvironmentInfo,
): Promise<FlipperDoctor.HealthcheckRunResult> => {
// 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) {
return {
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;
}
Expand Down
10 changes: 7 additions & 3 deletions desktop/flipper-common/src/doctor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
{
Expand All @@ -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': [];
Expand Down
32 changes: 15 additions & 17 deletions desktop/flipper-ui/src/sandy-chrome/doctor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ const CommonOpenSSLInstalled = (
<CodeBlock>{props.output}</CodeBlock>
</div>
);
const XcodeSelectSwitch = ({
availableXcode,
}: {
availableXcode: string | null;
}) => (
<CliCommand
title="Select Xcode version foo bar baz"
command={`sudo xcode-select -switch ${availableXcode ?? '<path/to/>/Xcode.app'}`}
/>
);

const CommonOpenSSLNotInstalled = (
props: PropsFor<'common.openssl--not_installed'>,
Expand Down Expand Up @@ -162,28 +172,20 @@ const XcodeSelectSet = (props: PropsFor<'ios.xcode-select--set'>) => (
<CodeBlock>{props.selected}</CodeBlock>
</Typography.Paragraph>
);
const XcodeSelectNotSet = (_props: PropsFor<'ios.xcode-select--not_set'>) => (
const XcodeSelectNotSet = (props: PropsFor<'ios.xcode-select--not_set'>) => (
<Typography.Paragraph>
xcode-select path not selected. <code>xcode-select -p</code> failed. To fix
it run this command:
<CliCommand
title="Select Xcode version foo bar baz"
// TODO provide latest path to installed xcode from /Applications
command={`sudo xcode-select -switch <path/to/>/Xcode.app`}
/>
<XcodeSelectSwitch availableXcode={props.availableXcode} />
</Typography.Paragraph>
);

const XcodeSelectNoXcode = (
_props: PropsFor<'ios.xcode-select--no_xcode_selected'>,
props: PropsFor<'ios.xcode-select--no_xcode_selected'>,
) => (
<Typography.Paragraph>
xcode-select has no Xcode selected. To fix it it run this command:
<CliCommand
title="Select Xcode version foo bar baz"
// TODO provide latest path to installed xcode from /Applications
command={`sudo xcode-select -switch <path/to/>/Xcode.app`}
/>
<XcodeSelectSwitch availableXcode={props.availableXcode} />
</Typography.Paragraph>
);

Expand All @@ -206,11 +208,7 @@ const XcodeSelectNonExistingSelected = (
<Typography.Paragraph>
xcode-select is pointing at a path that does not exist:
<CodeBlock size="s">{props.selected}</CodeBlock>
<CliCommand
title="Select existing Xcode application"
// TODO provide latest path to installed xcode from /Applications
command={`sudo xcode-select -switch <path/to/>/Xcode.app`}
/>
<XcodeSelectSwitch availableXcode={props.availableXcode} />
</Typography.Paragraph>
);

Expand Down

0 comments on commit 3693b49

Please sign in to comment.