Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: show slightly better sdk error during init #670

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/utils/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,9 @@ function maybeRemoveOldXcodes() {

// Extract the SDK version from the toolchain file and normalize it.
function extractSDKVersion(toolchainFile) {
if (!fs.existsSync(toolchainFile)) {
return null;
}

const contents = fs.readFileSync(toolchainFile, 'utf8');
const match = /macOS\s(\d+(\.\d+)?)\sSDK\n\#/.exec(contents);

if (!match) {
return null;
}
if (!match) return null;

return match[1].includes('.') ? match[1] : `${match[1]}.0`;
}
Expand All @@ -103,14 +96,22 @@ function expectedSDKVersion() {

// The current Xcode version and associated SDK can be found in build/mac_toolchain.py.
const macToolchainPy = path.resolve(root, 'src', 'build', 'mac_toolchain.py');
const version = extractSDKVersion(macToolchainPy);
if (!fs.existsSync(macToolchainPy)) {
console.warn(
color.warn,
`Could not find ${color.path(macToolchainPy)} - falling back to default of`,
fallbackSDK(),
);
return fallbackSDK();
}

const version = extractSDKVersion(macToolchainPy);
if (isNaN(Number(version)) || !SDKs[version]) {
console.warn(
color.warn,
`Automatically detected an unknown macOS SDK ${color.path(
version,
)} - falling back to default of`,
version ? `${version} ` : '',
)}- falling back to default of`,
fallbackSDK(),
);
return fallbackSDK();
Expand Down