Skip to content

Commit cfd5712

Browse files
CopilotOmotolahanniavalera
authored
Fix test presets not auto-switching when build preset changes (#4819)
* Initial plan * Fix test presets not auto-switching when build preset changes When switching build presets (especially with multi-config generators like Ninja Multi-Config), incompatible test presets were unloaded but no compatible one was auto-selected. Users had to manually switch test presets. Changes: 1. setBuildPreset() now calls guessTestPreset() after loading the build preset if no test preset is currently set. 2. guessTestPreset() now properly checks testPresetCompatible (including build type matching) instead of only checking buildPresetCompatible (which only verified configure preset matching). Fixes #4336 Co-authored-by: Omotola <[email protected]> * Update CHANGELOG entry to cite issue #4395 instead of #4336 Co-authored-by: Omotola <[email protected]> * switch the check of test preset compatibility to run regardless of configure preset check guard --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Omotola <[email protected]> Co-authored-by: Omotola <[email protected]> Co-authored-by: Hannia Valera <[email protected]>
1 parent 9c676d3 commit cfd5712

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Improvements:
3131
- Honor `debugger.workingDirectory` from the CMake File API when debugging a target, so that the `DEBUGGER_WORKING_DIRECTORY` target property is used as the debugger working directory. [#4595](https://github.com/microsoft/vscode-cmake-tools/issues/4595)
3232

3333
Bug Fixes:
34+
- Fix test presets not automatically switching when the build preset changes in multi-config generator setups (e.g., Ninja Multi-Config). The extension now auto-selects a compatible test preset after a build preset change, and properly considers build type when guessing the test preset. [#4395](https://github.com/microsoft/vscode-cmake-tools/issues/4395)
3435
- Fix `cmake.additionalCompilerSearchDirs` ignoring per-folder overrides in multiroot workspaces. The setting is now read from each folder's scoped configuration with `${workspaceFolder}` expanded per-folder, and the results are unioned. Also fix `cmake.cmakePath` resolution during kit scanning to try all workspace folders instead of only the first.
3536
- Fix `${workspaceFolder}` expansion in `cmake.additionalCompilerSearchDirs` for single-root workspaces. Previously only the multi-root `${workspaceFolder:name}` syntax worked. [#4571](https://github.com/microsoft/vscode-cmake-tools/issues/4571)
3637
- Fix `cmake.revealLog` set to `"focus"` not revealing the output panel or stealing focus. The output channel now correctly appears and takes focus on both configure success and failure when this setting is used. [#4471](https://github.com/microsoft/vscode-cmake-tools/issues/4471)

src/presets/presetsController.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,8 +1040,9 @@ export class PresetsController implements vscode.Disposable {
10401040
(_preset) =>
10411041
this.checkCompatibility(
10421042
this.project.configurePreset,
1043+
this.project.buildPreset,
10431044
_preset
1044-
).buildPresetCompatible &&
1045+
).testPresetCompatible &&
10451046
preset.evaluatePresetCondition(_preset, allPresets)
10461047
);
10471048
for (const testPreset of testPresets) {
@@ -1193,11 +1194,11 @@ export class PresetsController implements vscode.Disposable {
11931194
this._isChangingPresets = true;
11941195
}
11951196

1196-
if (needToCheckConfigurePreset && presetName !== preset.defaultBuildPreset.name) {
1197+
if (presetName !== preset.defaultBuildPreset.name) {
11971198
preset.expandConfigurePresetForPresets(this.folderPath, 'build');
11981199
const _preset = preset.getPresetByName(preset.allBuildPresets(this.folderPath), presetName);
11991200
const compatibility = this.checkCompatibility(this.project.configurePreset, _preset, this.project.testPreset, this.project.packagePreset, this.project.workflowPreset);
1200-
if (!compatibility.buildPresetCompatible) {
1201+
if (needToCheckConfigurePreset && !compatibility.buildPresetCompatible) {
12011202
log.warning(localize('build.preset.configure.preset.not.match', 'Build preset {0}: The configure preset does not match the active configure preset', presetName));
12021203
await vscode.window.withProgress(
12031204
{
@@ -1221,7 +1222,6 @@ export class PresetsController implements vscode.Disposable {
12211222
},
12221223
() => this.project.setTestPreset(null)
12231224
);
1224-
// Not sure we need to do the same for package/workflow build
12251225
}
12261226
}
12271227
// Load the build preset into the backend
@@ -1233,6 +1233,11 @@ export class PresetsController implements vscode.Disposable {
12331233
() => this.project.setBuildPreset(presetName)
12341234
);
12351235

1236+
// Auto-select a compatible test preset if none is currently set
1237+
if (!this.project.testPreset) {
1238+
await this.guessTestPreset();
1239+
}
1240+
12361241
if (checkChangingPreset) {
12371242
this._isChangingPresets = false;
12381243
}

0 commit comments

Comments
 (0)