Skip to content

Commit

Permalink
refactor: show slightly better sdk error during init (#670)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere authored Oct 30, 2024
1 parent 9be145c commit 5904e37
Showing 1 changed file with 12 additions and 11 deletions.
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

0 comments on commit 5904e37

Please sign in to comment.