Skip to content

Commit

Permalink
Allow CMake to select a default internal generator when the user sele…
Browse files Browse the repository at this point in the history
…cts "__unspec__" for the kit (#3889)

* updated to allow no generator when using file api and cmake 3.15.0 or greater

* fixed kit name check

* updated changelog

* throw nogenerator error if kit isn't __unspec__
  • Loading branch information
snehara99 authored Jul 11, 2024
1 parent 32a07ff commit 46aac7d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ Improvements:
Bug Fixes:

- Attempt to fix stringifying the extension context. [#3797](https://github.com/microsoft/vscode-cmake-tools/issues/3797)
- 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)
- Potential fix for attempting to load a non-variants file as a variants file and throwing a parse exception [#3727](https://github.com/microsoft/vscode-cmake-tools/issues/3727)
- 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)
- Potential fix for attempting to load a non-variants file as a variants file and throwing a parse exception. [#3727](https://github.com/microsoft/vscode-cmake-tools/issues/3727)
- Fix issue where `cmakeUserPresets.json` not showing up in project outline. [#3832](https://github.com/microsoft/vscode-cmake-tools/issues/3832)
- Fix edge case where parsing tests fails when additional output is printed before tests json. [#3750](https://github.com/microsoft/vscode-cmake-tools/issues/3750)
- Fix issue where `Configure with CMake Debugger` fails on restart because the previously used pipe to CMake Debugger is no longer available. [#3582](https://github.com/microsoft/vscode-cmake-tools/issues/3582)
- Fix custom kit PATH being overriden [#3849](https://github.com/microsoft/vscode-cmake-tools/issues/3849)
- Fix custom kit PATH being overriden. [#3849](https://github.com/microsoft/vscode-cmake-tools/issues/3849)

## 1.18.43

Expand Down
8 changes: 7 additions & 1 deletion src/cmake/cmakeExecutable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ export interface CMakeExecutable {
isServerModeSupported?: boolean;
isFileApiModeSupported?: boolean;
isDebuggerSupported?: boolean;
isDefaultGeneratorSupported?: boolean;
version?: util.Version;
minimalServerModeVersion: util.Version;
minimalFileApiModeVersion: util.Version;
minimalDefaultGeneratorVersion: util.Version;
}

const cmakeInfo = new Map<string, CMakeExecutable>();
Expand All @@ -27,7 +29,8 @@ export async function getCMakeExecutableInformation(path: string): Promise<CMake
path,
isPresent: false,
minimalServerModeVersion: util.parseVersion('3.7.1'),
minimalFileApiModeVersion: util.parseVersion('3.14.0')
minimalFileApiModeVersion: util.parseVersion('3.14.0'),
minimalDefaultGeneratorVersion: util.parseVersion('3.15.0')
};

// The check for 'path' seems unnecessary, but crash logs tell us otherwise. It is not clear
Expand Down Expand Up @@ -61,6 +64,9 @@ export async function getCMakeExecutableInformation(path: string): Promise<CMake
// Support for new file based API, it replace the server mode
cmake.isFileApiModeSupported = util.versionGreaterOrEquals(cmake.version, cmake.minimalFileApiModeVersion);
cmake.isPresent = true;

// Support for CMake using an internal default generator when one isn't provided
cmake.isDefaultGeneratorSupported = util.versionGreaterOrEquals(cmake.version, cmake.minimalDefaultGeneratorVersion);
}
const debuggerPresent = await proc.execute(path, ['-E', 'capabilities'], null, execOpt).result;
if (debuggerPresent.retc === 0 && debuggerPresent.stdout) {
Expand Down
14 changes: 12 additions & 2 deletions src/drivers/cmakeDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ export abstract class CMakeDriver implements vscode.Disposable {
protected sourceDirUnexpanded: string, // The un-expanded original source directory path, where the CMakeLists.txt exists.
private readonly isMultiProject: boolean,
private readonly __workspaceFolder: string,
readonly preconditionHandler: CMakePreconditionProblemSolver) {
readonly preconditionHandler: CMakePreconditionProblemSolver,
private readonly usingFileApi: boolean = false
) {
this.sourceDir = this.sourceDirUnexpanded;
// We have a cache of file-compilation terminals. Wipe them out when the
// user closes those terminals.
Expand Down Expand Up @@ -375,6 +377,10 @@ export abstract class CMakeDriver implements vscode.Disposable {
*/
private _kit: Kit | null = null;

get kit(): Kit | null {
return this._kit;
}

private _kitDetect: KitDetect | null = null;

private _useCMakePresets: boolean = true;
Expand Down Expand Up @@ -728,7 +734,11 @@ export abstract class CMakeDriver implements vscode.Disposable {

// If no preferred generator is defined by the current kit or the user settings,
// it's time to consider the defaults.
if (preferredGenerators.length === 0) {
if (preferredGenerators.length === 0
&& !(this.usingFileApi
&& (this.cmake.version && util.versionGreaterOrEquals(this.cmake.version, this.cmake.minimalDefaultGeneratorVersion))
&& kit.name === "__unspec__")
) {
preferredGenerators.push({ name: "Ninja" });
preferredGenerators.push({ name: "Unix Makefiles" });
}
Expand Down
8 changes: 4 additions & 4 deletions src/drivers/cmakeFileApiDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const localize: nls.LocalizeFunc = nls.loadMessageBundle();

const log = logging.createLogger('cmakefileapi-driver');
/**
* The CMake driver with FileApi of CMake >= 3.15.0
* The CMake driver with FileApi of CMake >= 3.14.0
*/
export class CMakeFileApiDriver extends CMakeDriver {

Expand All @@ -52,7 +52,7 @@ export class CMakeFileApiDriver extends CMakeDriver {
isMultiProject: boolean,
workspaceRootPath: string,
preconditionHandler: CMakePreconditionProblemSolver) {
super(cmake, config, sourceDir, isMultiProject, workspaceRootPath, preconditionHandler);
super(cmake, config, sourceDir, isMultiProject, workspaceRootPath, preconditionHandler, true);
}

static async create(cmake: CMakeExecutable,
Expand Down Expand Up @@ -148,7 +148,7 @@ export class CMakeFileApiDriver extends CMakeDriver {

this._generatorInformation = this.generator;
}
if (!this.generator && !this.useCMakePresets) {
if (!(this.cmake.isDefaultGeneratorSupported && this.kit?.name === '__unspec__') && !this.generator && !this.useCMakePresets) {
throw new NoGeneratorError();
}

Expand All @@ -169,7 +169,7 @@ export class CMakeFileApiDriver extends CMakeDriver {
async doSetKit(cb: () => Promise<void>): Promise<void> {
this._needsReconfigure = true;
await cb();
if (!this.generator) {
if (!(this.cmake.isDefaultGeneratorSupported && this.kit?.name === '__unspec__') && !this.generator) {
throw new NoGeneratorError();
}
}
Expand Down

0 comments on commit 46aac7d

Please sign in to comment.