Skip to content

Commit

Permalink
Fix order of CMakePresets inheritance (#3595)
Browse files Browse the repository at this point in the history
* fix order of inherit

* add changelog
  • Loading branch information
gcampbell-msft authored Feb 16, 2024
1 parent 2878725 commit 810cd00
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 15 additions & 8 deletions src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 810cd00

Please sign in to comment.