Skip to content

Commit 265af0d

Browse files
Copilothanniavalerasnehara99
authored
Fix #4484: compileFile with presets (#4681)
* Initial plan * Fix compileFile with presets Co-authored-by: hanniavalera <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: hanniavalera <[email protected]> Co-authored-by: snehara99 <[email protected]>
1 parent c8ff2ef commit 265af0d

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Bug Fixes:
99

1010
- Fix CMake script path links not working in CHS/CSY/FRA/PLK locales due to localized quotes. [#4383](https://github.com/microsoft/vscode-cmake-tools/issues/4383)
1111
- Fix user-level tasks defined in `~/.config/Code/User/tasks.json` causing infinite spinner. [#4659](https://github.com/microsoft/vscode-cmake-tools/pull/4659)
12+
- Fix `cmake.compileFile` failing to find compilation info when using presets without `CMAKE_EXPORT_COMPILE_COMMANDS`. [#4484](https://github.com/microsoft/vscode-cmake-tools/issues/4484)
1213
- Fix "Copy Value" in CMake debugger copying variable name instead of value. [#4551](https://github.com/microsoft/vscode-cmake-tools/issues/4551)
1314
- cmakeDriver: Fixes getCompilerVersion by using compilerPath instead of compilerName. [#4647](https://github.com/microsoft/vscode-cmake-tools/pull/4647) [@lygstate](https://github.com/lygstate)
1415

src/drivers/cmakeDriver.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,20 @@ export abstract class CMakeDriver implements vscode.Disposable {
14361436
// Cache flags will construct the command line for cmake.
14371437
const init_cache_flags = await this.generateInitCacheFlags();
14381438
// Make sure that we expand the config.configureArgs. Right now, preset args are expanded upon switching to the preset.
1439-
return init_cache_flags.concat(preset.configureArgs(configPreset), await Promise.all(this.config.configureArgs.map(async (value) => expand.expandString(value, { ...this.expansionOptions, envOverride: await this.getConfigureEnvironment()}))));
1439+
const expandedConfigureArgs = await Promise.all(this.config.configureArgs.map(async (value) => expand.expandString(value, { ...this.expansionOptions, envOverride: await this.getConfigureEnvironment()})));
1440+
const expandedArgs = init_cache_flags.concat(preset.configureArgs(configPreset), expandedConfigureArgs);
1441+
const configurationScope = this.workspaceFolder ? vscode.Uri.file(this.workspaceFolder) : null;
1442+
const config = vscode.workspace.getConfiguration("cmake", configurationScope);
1443+
const exportCompileCommandsSetting = config.get<boolean>("exportCompileCommandsFile");
1444+
const exportCompileCommandsFile: boolean = exportCompileCommandsSetting === undefined ? true : (exportCompileCommandsSetting || false);
1445+
const presetCacheVariables = configPreset.cacheVariables ?? {};
1446+
const hasExportCompileCommands = Object.prototype.hasOwnProperty.call(presetCacheVariables, 'CMAKE_EXPORT_COMPILE_COMMANDS')
1447+
|| expandedArgs.some(arg => arg.startsWith('-DCMAKE_EXPORT_COMPILE_COMMANDS'));
1448+
if (!hasExportCompileCommands) {
1449+
const exportCompileCommandsValue = util.cmakeify(exportCompileCommandsFile);
1450+
expandedArgs.push(`-DCMAKE_EXPORT_COMPILE_COMMANDS:${exportCompileCommandsValue.type}=${exportCompileCommandsValue.value}`);
1451+
}
1452+
return expandedArgs;
14401453
}
14411454

14421455
public async generateConfigArgsFromSettings(extra_args: string[] = [], withoutCmakeSettings: boolean = false): Promise<string[]> {

0 commit comments

Comments
 (0)