Skip to content

Commit 074387b

Browse files
Francois-Lesnehara99Copilot
authored
Add setting "postConfigureTask" (#4566)
* Squashed commit of the following: Add post configure task * add missing line in config.ts * Update documentation * Add changelog entry and localization string for postConfigureTask Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Sneha Ramachandran <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: snehara99 <[email protected]>
1 parent 293a61e commit 074387b

7 files changed

Lines changed: 48 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Features:
77
- Add command to clear build diagnostics from the Problems pane. [#4691](https://github.com/microsoft/vscode-cmake-tools/pull/4691)
88
- Add individual CTest test nodes to the Project Outline with inline run/debug buttons, and enable debugging tests from both the Outline and Test Explorer without requiring a launch.json. [#4721](https://github.com/microsoft/vscode-cmake-tools/pull/4721)
99
- Add "Delete Cache, Reconfigure and Build" command that chains cache deletion, reconfiguration, and build into a single action. [#4723](https://github.com/microsoft/vscode-cmake-tools/pull/4723)
10+
- Add `cmake.postConfigureTask` setting to execute a named VS Code task after every successful CMake configure. [#4566](https://github.com/microsoft/vscode-cmake-tools/pull/4566) [@Francois-Le](https://github.com/Francois-Le)
1011
- Add "Set Build and Launch/Debug Target" command that sets both the build target and launch target simultaneously. [#4732](https://github.com/microsoft/vscode-cmake-tools/pull/4732)
1112

1213
Improvements:

docs/cmake-settings.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Options that support substitution, in the table below, allow variable references
3030
| `cmake.configureOnOpen` | Automatically configure CMake project directories when they are opened. | `true` | no |
3131
| `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: Semicolons (`;`) in string values are automatically escaped to prevent CMake from interpreting them as list separators. If you want to pass a CMake list, use array notation instead, e.g. `"MY_LIST": [ "a", "b" ]`. | `{}` (no values) | yes |
3232
| `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 |
33+
| `cmake.postConfigureTask`| If not `null`, the task with this name is executed whenever CMake successfully configures. | `null` (do not run any task) | yes |
3334
| `cmake.coverageInfoFiles` | LCOV coverage info files to be processed after running tests with coverage using the test explorer. | `[]` | yes |
3435
| `cmake.cpackArgs` | An array of additional arguments to pass to cpack. | `[]` | yes |
3536
| `cmake.cpackEnvironment` | An object containing `key:value` pairs of environment variables, which will be available when running cpack. | `{}` | yes |

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2912,6 +2912,12 @@
29122912
"description": "%cmake-tools.configuration.cmake.copyCompileCommands.description%",
29132913
"scope": "resource"
29142914
},
2915+
"cmake.postConfigureTask": {
2916+
"type": "string",
2917+
"default": null,
2918+
"description": "%cmake-tools.configuration.cmake.postConfigureTask.description%",
2919+
"scope": "resource"
2920+
},
29152921
"cmake.configureOnOpen": {
29162922
"type": "boolean",
29172923
"default": true,

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@
226226
"cmake-tools.configuration.cmake.emscriptenSearchDirs.description": "Directories where Emscripten may be installed.",
227227
"cmake-tools.configuration.cmake.mergedCompileCommands.description": "Recursively collect and merge all compile_commands.json found in the cmake.buildDirectory.",
228228
"cmake-tools.configuration.cmake.copyCompileCommands.description": "Copy compile_commands.json to this location after a successful configure.",
229+
"cmake-tools.configuration.cmake.postConfigureTask.description": "If set, this named task will be executed after a successful CMake configure.",
229230
"cmake-tools.configuration.cmake.configureOnOpen.description": "Automatically configure CMake project directories when they are opened.",
230231
"cmake-tools.configuration.cmake.configureOnEdit.description": "Automatically configure CMake project directories when cmake.sourceDirectory or CMakeLists.txt content are saved.",
231232
"cmake-tools.configuration.cmake.deleteBuildDirOnCleanConfigure.description": "Delete the entire build directory when a clean configure is invoked.",

src/cmakeProject.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,36 @@ export class CMakeProject {
16151615
return;
16161616
}
16171617
}
1618+
1619+
}
1620+
1621+
/**
1622+
* Execute the postConfigureTask if configured
1623+
*/
1624+
private async executePostConfigureTask(): Promise<void> {
1625+
const postConfigureTask = this.workspaceContext.config.postConfigureTask;
1626+
if (postConfigureTask) {
1627+
try {
1628+
log.debug(localize('executing.post.configure.task', 'Executing post configure task: {0}', postConfigureTask));
1629+
1630+
// Fetch all available tasks
1631+
const tasks = await vscode.tasks.fetchTasks();
1632+
1633+
// Find the task by label
1634+
const task = tasks.find(t => t.name === postConfigureTask);
1635+
1636+
if (task) {
1637+
await vscode.tasks.executeTask(task);
1638+
} else {
1639+
const errorMsg = localize('task.not.found', 'Task "{0}" not found. Available tasks: {1}', postConfigureTask, tasks.map(t => t.name).join(', '));
1640+
void vscode.window.showErrorMessage(errorMsg);
1641+
log.error(errorMsg);
1642+
}
1643+
} catch (error: any) {
1644+
void vscode.window.showErrorMessage(localize('failed.to.execute.post.configure.task', 'Failed to execute post configure task: {0}', error.toString()));
1645+
log.error(localize('post.configure.task.error', 'Error executing post configure task'), error);
1646+
}
1647+
}
16181648
}
16191649

16201650
/**
@@ -1638,6 +1668,7 @@ export class CMakeProject {
16381668
const result: ConfigureResult = await drv.configure(trigger, []);
16391669
if (result.exitCode === 0) {
16401670
await this.refreshCompileDatabase(drv.expansionOptions);
1671+
await this.executePostConfigureTask();
16411672
} else {
16421673
log.showChannel(true);
16431674
}
@@ -1739,6 +1770,7 @@ export class CMakeProject {
17391770
if (result.exitCode === 0) {
17401771
await enableFullFeatureSet(true);
17411772
await this.refreshCompileDatabase(drv.expansionOptions);
1773+
await this.executePostConfigureTask();
17421774
} else if (result.exitCode !== 0 && (await this.getCMakeExecutable()).isDebuggerSupported && cmakeConfiguration.get(showDebuggerConfigurationString) && !forciblyCanceled && !cancelInformation.canceled && result.resultType === ConfigureResultType.NormalOperation) {
17431775
log.showChannel(true);
17441776
const yesButtonTitle: string = localize(

src/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ export interface ExtensionConfigurationSettings {
204204
emscriptenSearchDirs: string[];
205205
mergedCompileCommands: string | null;
206206
copyCompileCommands: string | null;
207+
postConfigureTask: string | null;
207208
loadCompileCommands: boolean;
208209
configureOnOpen: boolean;
209210
configureOnEdit: boolean;
@@ -549,6 +550,9 @@ export class ConfigurationReader implements vscode.Disposable {
549550
get copyCompileCommands(): string | null {
550551
return this.configData.copyCompileCommands;
551552
}
553+
get postConfigureTask(): string | null {
554+
return this.configData.postConfigureTask;
555+
}
552556
get loadCompileCommands(): boolean {
553557
return this.configData.loadCompileCommands;
554558
}
@@ -656,6 +660,7 @@ export class ConfigurationReader implements vscode.Disposable {
656660
emscriptenSearchDirs: new vscode.EventEmitter<string[]>(),
657661
mergedCompileCommands: new vscode.EventEmitter<string | null>(),
658662
copyCompileCommands: new vscode.EventEmitter<string | null>(),
663+
postConfigureTask: new vscode.EventEmitter<string | null>(),
659664
loadCompileCommands: new vscode.EventEmitter<boolean>(),
660665
configureOnOpen: new vscode.EventEmitter<boolean>(),
661666
configureOnEdit: new vscode.EventEmitter<boolean>(),

test/unit-tests/config.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ function createConfig(conf: Partial<ExtensionConfigurationSettings>): Configurat
8585
preRunCoverageTarget: null,
8686
postRunCoverageTarget: null,
8787
coverageInfoFiles: [],
88-
useFolderPropertyInBuildTargetDropdown: true
88+
useFolderPropertyInBuildTargetDropdown: true,
89+
postConfigureTask: null
8990
});
9091
ret.updatePartial(conf);
9192
return ret;

0 commit comments

Comments
 (0)