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

Don't check generator on PATH if manually specified #4026

Closed
wants to merge 3 commits into from
Closed
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
66 changes: 40 additions & 26 deletions src/drivers/cmakeDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,12 +727,23 @@ export abstract class CMakeDriver implements vscode.Disposable {
this._kitDetect = await getKitDetect(this._kit);
log.debug(localize('cmakedriver.kit.set.to', 'CMakeDriver Kit set to {0}', kit.name));
this._kitEnvironmentVariables = await effectiveKitEnvironment(kit, this.expansionOptions);
let usingFallbackGenerators = false;

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

// If a generator is set in the "cmake.generator" setting, push it to the front
// of the "best generator" logic
if (this.config.generator) {
preferredGenerators.unshift({
name: this.config.generator,
platform: this.config.platform || undefined,
toolset: this.config.toolset || undefined
});
}

// 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
Expand All @@ -742,19 +753,10 @@ export abstract class CMakeDriver implements vscode.Disposable {
) {
preferredGenerators.push({ name: "Ninja" });
preferredGenerators.push({ name: "Unix Makefiles" });
usingFallbackGenerators = true;
}

// If a generator is set in the "cmake.generator" setting, push it to the front
// of the "best generator" logic
if (this.config.generator) {
preferredGenerators.unshift({
name: this.config.generator,
platform: this.config.platform || undefined,
toolset: this.config.toolset || undefined
});
}

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

protected abstract doSetConfigurePreset(needsClean: boolean, cb: () => Promise<void>): Promise<void>;
Expand Down Expand Up @@ -979,27 +981,39 @@ export abstract class CMakeDriver implements vscode.Disposable {
/**
* Picks the best generator to use on the current system
*/
async findBestGenerator(preferredGenerators: CMakeGenerator[]): Promise<CMakeGenerator | null> {
async findBestGenerator(preferredGenerators: CMakeGenerator[], usingFallbackGenerators: boolean): Promise<CMakeGenerator | null> {
log.debug(localize('trying.to.detect.generator', 'Trying to detect generator supported by system'));
const platform = process.platform;

for (const gen of preferredGenerators) {
const gen_name = gen.name;
const generator_present = await (async (): Promise<boolean> => {
if (gen_name === 'Ninja' || gen_name === 'Ninja Multi-Config') {
return await this.testHaveCommand('ninja') || this.testHaveCommand('ninja-build');
}
if (gen_name === 'MinGW Makefiles') {
return platform === 'win32' && this.testHaveCommand('mingw32-make');
}
if (gen_name === 'NMake Makefiles') {
return platform === 'win32' && this.testHaveCommand('nmake', ['/?']);
}
if (gen_name === 'Unix Makefiles') {
return this.testHaveCommand('make');
}
if (gen_name === 'MSYS Makefiles') {
return platform === 'win32' && this.testHaveCommand('make');
// If we're not using the default generators, then the generator was manually specified
// in that case, assume it exists and don't check the PATH, only check if it's a supported generator.
// If we are using the default generators, then we should also check if it is on the PATH
if (!usingFallbackGenerators) {
return gen_name === 'Ninja' ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going back to, if the user has cmake.generator set, we use it without conditions, I don't think we should have these conditions here, we should simply return true.

gen_name === 'Ninja Multi-Config' ||
(gen_name === 'MinGW Makefiles' && platform === 'win32') ||
(gen_name === 'MinGW Makefiles' && platform === 'win32') ||
gen_name === 'Unix Makefiles' ||
(gen_name === 'MSYS Makefiles' && platform === 'win32');
} else {
if (gen_name === 'Ninja' || gen_name === 'Ninja Multi-Config') {
return await this.testHaveCommand('ninja') || this.testHaveCommand('ninja-build');
}
if (gen_name === 'MinGW Makefiles') {
return platform === 'win32' && this.testHaveCommand('mingw32-make');
}
if (gen_name === 'NMake Makefiles') {
return platform === 'win32' && this.testHaveCommand('nmake', ['/?']);
}
if (gen_name === 'Unix Makefiles') {
return this.testHaveCommand('make');
}
if (gen_name === 'MSYS Makefiles') {
return platform === 'win32' && this.testHaveCommand('make');
}
}
return false;
})();
Expand Down
Loading