From 810cd002e874ee37ea9d47b56834260846f16644 Mon Sep 17 00:00:00 2001 From: Garrett Campbell <86264750+gcampbell-msft@users.noreply.github.com> Date: Fri, 16 Feb 2024 13:31:14 -0500 Subject: [PATCH] Fix order of CMakePresets inheritance (#3595) * fix order of inherit * add changelog --- CHANGELOG.md | 1 + src/preset.ts | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bc97cf89..c58e5c4a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Bug Fixes: - Fix an issue where we weren't able to run tests when not using Presets. [#3589](https://github.com/microsoft/vscode-cmake-tools/issues/3589) +- Fix the order of preference for CMake Presets `inherit` field. [#3594](https://github.com/microsoft/vscode-cmake-tools/issues/3594) ## 1.17.15 diff --git a/src/preset.ts b/src/preset.ts index b5bcba298..7ffbdd485 100644 --- a/src/preset.ts +++ b/src/preset.ts @@ -625,7 +625,8 @@ function getVendorForConfigurePresetHelper(folder: string, preset: ConfigurePres if (util.isString(preset.inherits)) { preset.inherits = [preset.inherits]; } - for (const parent of preset.inherits) { + const reversedInherits = preset.inherits.slice().reverse(); + for (const parent of reversedInherits) { const parentVendor = getVendorForConfigurePresetImpl(folder, parent, allowUserPreset); if (parentVendor) { for (const key in parentVendor) { @@ -763,6 +764,7 @@ export async function expandConfigurePreset(folder: string, name: string, worksp const expandedPreset: ConfigurePreset = { name }; const expansionOpts: ExpansionOptions = await getExpansionOptions(workspaceFolder, sourceDir, preset); + preset.environment = EnvironmentUtils.mergePreserveNull([process.env, preset.environment]); // Expand environment vars first since other fields may refer to them if (preset.environment) { expandedPreset.environment = EnvironmentUtils.createPreserveNull(); @@ -1109,7 +1111,8 @@ async function expandConfigurePresetHelper(folder: string, preset: ConfigurePres if (util.isString(preset.inherits)) { preset.inherits = [preset.inherits]; } - for (const parentName of preset.inherits) { + const reversedInherits = preset.inherits.slice().reverse(); + for (const parentName of reversedInherits) { const parent = await expandConfigurePresetImpl(folder, parentName, workspaceFolder, sourceDir, allowUserPreset); if (parent) { // Inherit environment @@ -1132,7 +1135,6 @@ async function expandConfigurePresetHelper(folder: string, preset: ConfigurePres } } - inheritedEnv = EnvironmentUtils.mergePreserveNull([process.env, inheritedEnv]); preset.environment = EnvironmentUtils.mergePreserveNull([inheritedEnv, preset.environment]); preset.__expanded = true; @@ -1293,7 +1295,8 @@ function getConfigurePresetForPresetHelper(folder: string, preset: BuildPreset | if (util.isString(preset.inherits)) { preset.inherits = [preset.inherits]; } - for (const parent of preset.inherits) { + const reversedInherits = preset.inherits.slice().reverse(); + for (const parent of reversedInherits) { const parentConfigurePreset = getConfigurePresetForPresetImpl(folder, parent, presetType, allowUserPreset); if (parentConfigurePreset) { preset.configurePreset = parentConfigurePreset; @@ -1415,7 +1418,8 @@ async function expandBuildPresetHelper(folder: string, preset: BuildPreset, work if (util.isString(preset.inherits)) { preset.inherits = [preset.inherits]; } - for (const parentName of preset.inherits) { + const reversedInherits = preset.inherits.slice().reverse(); + for (const parentName of reversedInherits) { const parent = await expandBuildPresetImpl(folder, parentName, workspaceFolder, sourceDir, parallelJobs, preferredGeneratorName, allowUserPreset); if (parent) { // Inherit environment @@ -1600,7 +1604,8 @@ async function expandTestPresetHelper(folder: string, preset: TestPreset, worksp if (util.isString(preset.inherits)) { preset.inherits = [preset.inherits]; } - for (const parentName of preset.inherits) { + const reversedInherits = preset.inherits.slice().reverse(); + for (const parentName of reversedInherits) { const parent = await expandTestPresetImpl(folder, parentName, workspaceFolder, sourceDir, preferredGeneratorName, allowUserPreset); if (parent) { // Inherit environment @@ -1728,7 +1733,8 @@ async function expandPackagePresetHelper(folder: string, preset: PackagePreset, if (util.isString(preset.inherits)) { preset.inherits = [preset.inherits]; } - for (const parentName of preset.inherits) { + const reversedInherits = preset.inherits.slice().reverse(); + for (const parentName of reversedInherits) { const parent = await expandPackagePresetImpl(folder, parentName, workspaceFolder, sourceDir, preferredGeneratorName, allowUserPreset); if (parent) { // Inherit environment @@ -1862,7 +1868,8 @@ async function expandWorkflowPresetHelper(folder: string, preset: WorkflowPreset if (util.isString(preset.inherits)) { preset.inherits = [preset.inherits]; } - for (const parentName of preset.inherits) { + const reversedInherits = preset.inherits.slice().reverse(); + for (const parentName of reversedInherits) { const parent = await expandWorkflowPresetImpl(folder, parentName, workspaceFolder, sourceDir, preferredGeneratorName, allowUserPreset); if (parent) { // Inherit environment