Skip to content

Commit

Permalink
Update src/evm-config.js
Browse files Browse the repository at this point in the history
Co-authored-by: David Sanders <[email protected]>
  • Loading branch information
codebytere and dsanders11 committed Oct 10, 2024
1 parent c08248d commit f77719f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
6 changes: 6 additions & 0 deletions evm-config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"type": "string",
"default": "electron"
},
"preserveSDK": {
"description": "Preserve the N most recent Xcode SDK versions",
"type": "integer",
"default": 5,
"minimum": 1
},
"execName": {
"description": "Name of the built executable to run",
"type": "string",
Expand Down
1 change: 1 addition & 0 deletions example-configs/evm.base.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
root: /path/to/your/developer/folder
reclient: remote_exec
preserveSDK: 5
remotes:
electron:
# SSH or HTTPS url
Expand Down
10 changes: 1 addition & 9 deletions src/e-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function createConfig(options) {
args: gn_args,
out: options.out,
},
preserveSDK: 5,
env: {
CHROMIUM_BUILDTOOLS_PATH: path.resolve(root, 'src', 'buildtools'),
GIT_CACHE_PATH: process.env.GIT_CACHE_PATH
Expand Down Expand Up @@ -167,15 +168,6 @@ program
checkGlobalGitConfig();
}

// ensure xcode is loaded
if (process.platform === 'darwin') {
if (options.onlySdk) {
ensureSDK();
} else {
loadXcode();
}
}

// ensure macOS SDKs are loaded
if (process.platform === 'darwin') {
ensureSDK();
Expand Down
12 changes: 11 additions & 1 deletion src/evm-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,21 @@ function sanitizeConfig(name, config, overwrite = false) {
changes.push(`fixed invalid property ${color.config('reclient: none')}`);
}

if ('preserveXcode' in config) {
if (!('preserveSDK' in config)) {
config.preserveSDK = config.preserveXcode ?? 5;
changes.push(`added ${color.config('preserveSDK')} property`);
}

if (config.preserveXcode) {
delete config.preserveXcode;
changes.push(`removed ${color.config('preserveXcode')} property`);
}

if (config.onlySdk) {
delete config.onlySdk;
changes.push(`removed ${color.config('onlySdk')} property`);
}

if (config.goma) {
delete config.goma;
changes.push(`removed deprecated ${color.config('goma')} property`);
Expand Down
18 changes: 18 additions & 0 deletions src/utils/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ function getSDKVersion() {
return json.MinimalDisplayName;
}

function removeUnusedSDKs() {
const recent = fs
.readdirSync(SDKDir)
.map(sdk => {
const sdkPath = path.join(SDKDir, sdk);
const { atime } = fs.statSync(sdkPath);
return { name: sdkPath, atime };
})
.sort((a, b) => b.atime - a.atime);

const { preserveSDK } = evmConfig.current();
for (const { name } of recent.slice(preserveSDK)) {
deleteDir(name);
}
}

// Extract the SDK version from the toolchain file and normalize it.
function extractSDKVersion(toolchainFile) {
if (!fs.existsSync(toolchainFile)) {
Expand Down Expand Up @@ -227,6 +243,8 @@ function ensureSDK() {

deleteDir(SDKZip);

removeUnusedSDKs();

return eventualVersionedPath;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/evm-config.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const validConfig = {
origin: '[email protected]:electron/electron.git',
},
},
preserveSDK: 5,
reclient: 'none',
gen: {
args: [],
Expand Down Expand Up @@ -65,8 +66,7 @@ describe('example configs', () => {
},
configValidationLevel: 'strict',
reclient: 'remote_exec',
onlySdk: expect.any(Boolean),
preserveXcode: expect.any(Number),
preserveSDK: expect.any(Number),
gen: {
out: 'Testing',
args: expect.any(Array),
Expand Down

0 comments on commit f77719f

Please sign in to comment.