diff --git a/docs/cmake-settings.md b/docs/cmake-settings.md index 36b9e37247..0eb5a1c506 100644 --- a/docs/cmake-settings.md +++ b/docs/cmake-settings.md @@ -30,6 +30,7 @@ Options that support substitution, in the table below, allow variable references | `cmake.configureOnOpen` | Automatically configure CMake project directories when they are opened. | `true` | no | | `cmake.configureSettings` | An object containing `key:value` pairs, which will be passed to CMake when configuring. The same as passing `-DVAR_NAME=ON` via `cmake.configureArgs`. NOTE: If you are setting an array argument within `cmake.configureSettings`, you should use array notation, i.e. `"CONFIGURE_SETTINGS_LIST": [ "a", "b" ]` | `{}` (no values) | yes | | `cmake.copyCompileCommands`| If not `null`, copies the `compile_commands.json` file generated by CMake to the path specified by this setting whenever CMake successfully configures. | `null` (do not copy the file) | yes | +| `cmake.postConfigureTask`| If not `null`, the task with this name is executed whenever CMake successfully configures. | `null` (do not run any task) | yes | | `cmake.coverageInfoFiles` | LCOV coverage info files to be processed after running tests with coverage using the test explorer. | `[]` | yes | | `cmake.cpackArgs` | An array of additional arguments to pass to cpack. | `[]` | yes | | `cmake.cpackEnvironment` | An object containing `key:value` pairs of environment variables, which will be available when running cpack. | `{}` | yes | diff --git a/package.json b/package.json index c75adadf17..0773f0a9c1 100644 --- a/package.json +++ b/package.json @@ -2649,6 +2649,12 @@ "description": "%cmake-tools.configuration.cmake.copyCompileCommands.description%", "scope": "resource" }, + "cmake.postConfigureTask": { + "type": "string", + "default": null, + "description": "%cmake-tools.configuration.cmake.postConfigureTask.description%", + "scope": "resource" + }, "cmake.configureOnOpen": { "type": "boolean", "default": true, diff --git a/src/cmakeProject.ts b/src/cmakeProject.ts index afea14ba4a..b72cce68ae 100644 --- a/src/cmakeProject.ts +++ b/src/cmakeProject.ts @@ -1612,6 +1612,36 @@ export class CMakeProject { return; } } + + } + + /** + * Execute the postConfigureTask if configured + */ + private async executePostConfigureTask(): Promise { + const postConfigureTask = this.workspaceContext.config.postConfigureTask; + if (postConfigureTask) { + try { + log.debug(localize('executing.post.configure.task', 'Executing post configure task: {0}', postConfigureTask)); + + // Fetch all available tasks + const tasks = await vscode.tasks.fetchTasks(); + + // Find the task by label + const task = tasks.find(t => t.name === postConfigureTask); + + if (task) { + await vscode.tasks.executeTask(task); + } else { + const errorMsg = localize('task.not.found', 'Task "{0}" not found. Available tasks: {1}', postConfigureTask, tasks.map(t => t.name).join(', ')); + void vscode.window.showErrorMessage(errorMsg); + log.error(errorMsg); + } + } catch (error: any) { + void vscode.window.showErrorMessage(localize('failed.to.execute.post.configure.task', 'Failed to execute post configure task: {0}', error.toString())); + log.error(localize('post.configure.task.error', 'Error executing post configure task'), error); + } + } } /** @@ -1635,6 +1665,7 @@ export class CMakeProject { const result: ConfigureResult = await drv.configure(trigger, []); if (result.exitCode === 0) { await this.refreshCompileDatabase(drv.expansionOptions); + await this.executePostConfigureTask(); } else { log.showChannel(true); } @@ -1736,6 +1767,7 @@ export class CMakeProject { if (result.exitCode === 0) { await enableFullFeatureSet(true); await this.refreshCompileDatabase(drv.expansionOptions); + await this.executePostConfigureTask(); } else if (result.exitCode !== 0 && (await this.getCMakeExecutable()).isDebuggerSupported && cmakeConfiguration.get(showDebuggerConfigurationString) && !forciblyCanceled && !cancelInformation.canceled && result.resultType === ConfigureResultType.NormalOperation) { log.showChannel(true); const yesButtonTitle: string = localize( diff --git a/src/config.ts b/src/config.ts index 1048da7e9d..ff7513ea81 100644 --- a/src/config.ts +++ b/src/config.ts @@ -193,6 +193,7 @@ export interface ExtensionConfigurationSettings { emscriptenSearchDirs: string[]; mergedCompileCommands: string | null; copyCompileCommands: string | null; + postConfigureTask: string | null; loadCompileCommands: boolean; configureOnOpen: boolean; configureOnEdit: boolean; @@ -535,6 +536,9 @@ export class ConfigurationReader implements vscode.Disposable { get copyCompileCommands(): string | null { return this.configData.copyCompileCommands; } + get postConfigureTask(): string | null { + return this.configData.postConfigureTask; + } get loadCompileCommands(): boolean { return this.configData.loadCompileCommands; } @@ -642,6 +646,7 @@ export class ConfigurationReader implements vscode.Disposable { emscriptenSearchDirs: new vscode.EventEmitter(), mergedCompileCommands: new vscode.EventEmitter(), copyCompileCommands: new vscode.EventEmitter(), + postConfigureTask: new vscode.EventEmitter(), loadCompileCommands: new vscode.EventEmitter(), configureOnOpen: new vscode.EventEmitter(), configureOnEdit: new vscode.EventEmitter(), diff --git a/test/unit-tests/config.test.ts b/test/unit-tests/config.test.ts index 1f857eb291..94e69083c4 100644 --- a/test/unit-tests/config.test.ts +++ b/test/unit-tests/config.test.ts @@ -84,7 +84,8 @@ function createConfig(conf: Partial): Configurat preRunCoverageTarget: null, postRunCoverageTarget: null, coverageInfoFiles: [], - useFolderPropertyInBuildTargetDropdown: true + useFolderPropertyInBuildTargetDropdown: true, + postConfigureTask: null }); ret.updatePartial(conf); return ret;