Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Preferred Generator selection logic #3869

Merged
merged 4 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Bug Fixes:
- Fix issue where `preferredGenerator.platform` and `preferredGenerator.toolset` wasn't being compared between the old and new kit to trigger a clean configure on a kit selection change. [#2699](https://github.com/microsoft/vscode-cmake-tools/issues/2699)
- Still allow for users to add `--warn-unused-cli`. Now instead of overriding, it will remove our default `--no-warn-unused-cli`. [#1090](https://github.com/microsoft/vscode-cmake-tools/issues/1090)
- Ensure `useCMakePresets` context is set after making a CMakePreset.json with `Quick Start`. [#3734](https://github.com/microsoft/vscode-cmake-tools/issues/3734)
- Fix issue where `cmake.preferredGenerators` wasn't falling back to the next entry when the first entry didn't exist [#2709](https://github.com/microsoft/vscode-cmake-tools/issues/2709)

## 1.18.42

Expand Down
10 changes: 6 additions & 4 deletions src/cmakeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -823,18 +823,20 @@ export class CMakeProject {
}

private getPreferredGenerators(): CMakeGenerator[] {
// User can override generator with a setting
const userPreferred: CMakeGenerator[] = this.workspaceContext.config.preferredGenerators
.map(g => ({ name: g }));

// The generator setting is placed at the front of user preferred generators
const userGenerator = this.workspaceContext.config.generator;
if (userGenerator) {
log.debug(localize('using.user.generator', 'Using generator from user configuration: {0}', userGenerator));
return [{
userPreferred.unshift({
name: userGenerator,
platform: this.workspaceContext.config.platform || undefined,
toolset: this.workspaceContext.config.toolset || undefined
}];
});
}

const userPreferred = this.workspaceContext.config.preferredGenerators.map(g => ({ name: g }));
return userPreferred;
}

Expand Down
21 changes: 10 additions & 11 deletions src/drivers/cmakeDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,8 +721,9 @@ export abstract class CMakeDriver implements vscode.Disposable {
log.debug(localize('cmakedriver.kit.set.to', 'CMakeDriver Kit set to {0}', kit.name));
this._kitEnvironmentVariables = await effectiveKitEnvironment(kit, this.expansionOptions);

// Place a kit preferred generator at the front of the list
if (kit.preferredGenerator) {
preferredGenerators.push(kit.preferredGenerator);
preferredGenerators.unshift(kit.preferredGenerator);
}

// If no preferred generator is defined by the current kit or the user settings,
Expand All @@ -732,17 +733,17 @@ export abstract class CMakeDriver implements vscode.Disposable {
preferredGenerators.push({ name: "Unix Makefiles" });
}

// Use the "best generator" selection logic only if the user did not define already
// in settings (via "cmake.generator") a particular generator to be used.
// If a generator is set in the "cmake.generator" setting, push it to the front
// of the "best generator" logic
if (this.config.generator) {
this._generator = {
preferredGenerators.unshift({
name: this.config.generator,
platform: this.config.platform || undefined,
toolset: this.config.toolset || undefined
};
} else {
this._generator = await this.findBestGenerator(preferredGenerators);
});
}

this._generator = await this.findBestGenerator(preferredGenerators);
}

protected abstract doSetConfigurePreset(needsClean: boolean, cb: () => Promise<void>): Promise<void>;
Expand Down Expand Up @@ -1003,10 +1004,8 @@ export abstract class CMakeDriver implements vscode.Disposable {
if (gen.name.toLowerCase().startsWith('xcode') && platform === 'darwin') {
return gen;
}
// If it is not a common generator that we can find, but it is a known cmake generator (cmakeGenerators), return it.
if (this.cmakeGenerators.indexOf(gen.name) >= 0 && !this.isCommonGenerator(gen.name)) {
return gen;
}

// If the generator isn't found, move on to the next one
continue;
} else {
return gen;
Expand Down
Loading