Skip to content

Commit 7bf1f05

Browse files
authored
Revert "Revert "Add setting "postConfigureTask" (#4566)" (#4750)" (#4751)
This reverts commit b0882e2.
1 parent 5f07d3b commit 7bf1f05

7 files changed

Lines changed: 47 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Features:
1313
- Clear build diagnostics from the Problems pane when a new build starts and populate them incrementally during the build. [#4608](https://github.com/microsoft/vscode-cmake-tools/issues/4608)
1414
- 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)
1515
- 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)
16+
- 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)
1617
- 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)
1718
- Add `cmake.setBuildTargetSameAsLaunchTarget` setting to automatically set the build target when the launch/debug target is changed. [#4519](https://github.com/microsoft/vscode-cmake-tools/pull/4519) [@nikita-karatun](https://github.com/nikita-karatun)
1819
- Add `cmake.additionalBuildProblemMatchers` setting to define custom problem matchers for build output. Supports tools like clang-tidy, PCLint Plus, cppcheck, or custom scripts integrated via `add_custom_command`/`add_custom_target`. [#4077](https://github.com/microsoft/vscode-cmake-tools/issues/4077)

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
@@ -3108,6 +3108,12 @@
31083108
"description": "%cmake-tools.configuration.cmake.copyCompileCommands.description%",
31093109
"scope": "resource"
31103110
},
3111+
"cmake.postConfigureTask": {
3112+
"type": "string",
3113+
"default": null,
3114+
"description": "%cmake-tools.configuration.cmake.postConfigureTask.description%",
3115+
"scope": "resource"
3116+
},
31113117
"cmake.configureOnOpen": {
31123118
"type": "boolean",
31133119
"default": true,

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@
272272
"cmake-tools.configuration.cmake.emscriptenSearchDirs.description": "Directories where Emscripten may be installed.",
273273
"cmake-tools.configuration.cmake.mergedCompileCommands.description": "Recursively collect and merge all compile_commands.json found in the cmake.buildDirectory.",
274274
"cmake-tools.configuration.cmake.copyCompileCommands.description": "Copy compile_commands.json to this location after a successful configure.",
275+
"cmake-tools.configuration.cmake.postConfigureTask.description": "If set, this named task will be executed after a successful CMake configure.",
275276
"cmake-tools.configuration.cmake.configureOnOpen.description": "Automatically configure CMake project directories when they are opened.",
276277
"cmake-tools.configuration.cmake.configureOnEdit.description": "Automatically configure CMake project directories when cmake.sourceDirectory or CMakeLists.txt content are saved.",
277278
"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
@@ -1632,6 +1632,36 @@ export class CMakeProject {
16321632
return;
16331633
}
16341634
}
1635+
1636+
}
1637+
1638+
/**
1639+
* Execute the postConfigureTask if configured
1640+
*/
1641+
private async executePostConfigureTask(): Promise<void> {
1642+
const postConfigureTask = this.workspaceContext.config.postConfigureTask;
1643+
if (postConfigureTask) {
1644+
try {
1645+
log.debug(localize('executing.post.configure.task', 'Executing post configure task: {0}', postConfigureTask));
1646+
1647+
// Fetch all available tasks
1648+
const tasks = await vscode.tasks.fetchTasks();
1649+
1650+
// Find the task by label
1651+
const task = tasks.find(t => t.name === postConfigureTask);
1652+
1653+
if (task) {
1654+
await vscode.tasks.executeTask(task);
1655+
} else {
1656+
const errorMsg = localize('task.not.found', 'Task "{0}" not found. Available tasks: {1}', postConfigureTask, tasks.map(t => t.name).join(', '));
1657+
void vscode.window.showErrorMessage(errorMsg);
1658+
log.error(errorMsg);
1659+
}
1660+
} catch (error: any) {
1661+
void vscode.window.showErrorMessage(localize('failed.to.execute.post.configure.task', 'Failed to execute post configure task: {0}', error.toString()));
1662+
log.error(localize('post.configure.task.error', 'Error executing post configure task'), error);
1663+
}
1664+
}
16351665
}
16361666

16371667
/**
@@ -1655,6 +1685,7 @@ export class CMakeProject {
16551685
const result: ConfigureResult = await drv.configure(trigger, []);
16561686
if (result.exitCode === 0) {
16571687
await this.refreshCompileDatabase(drv.expansionOptions);
1688+
await this.executePostConfigureTask();
16581689
} else {
16591690
log.showChannel(true);
16601691
}
@@ -1760,6 +1791,7 @@ export class CMakeProject {
17601791
if (result.exitCode === 0) {
17611792
await enableFullFeatureSet(true);
17621793
await this.refreshCompileDatabase(drv.expansionOptions);
1794+
await this.executePostConfigureTask();
17631795
} else if (result.exitCode !== 0 && (await this.getCMakeExecutable()).isDebuggerSupported && cmakeConfiguration.get(showDebuggerConfigurationString) && !forciblyCanceled && !cancelInformation.canceled && result.resultType === ConfigureResultType.NormalOperation) {
17641796
log.showChannel(true);
17651797
const yesButtonTitle: string = localize(

src/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ export interface ExtensionConfigurationSettings {
223223
emscriptenSearchDirs: string[];
224224
mergedCompileCommands: string | null;
225225
copyCompileCommands: string | null;
226+
postConfigureTask: string | null;
226227
loadCompileCommands: boolean;
227228
configureOnOpen: boolean;
228229
configureOnEdit: boolean;
@@ -598,6 +599,9 @@ export class ConfigurationReader implements vscode.Disposable {
598599
get copyCompileCommands(): string | null {
599600
return this.configData.copyCompileCommands;
600601
}
602+
get postConfigureTask(): string | null {
603+
return this.configData.postConfigureTask;
604+
}
601605
get loadCompileCommands(): boolean {
602606
return this.configData.loadCompileCommands;
603607
}
@@ -725,6 +729,7 @@ export class ConfigurationReader implements vscode.Disposable {
725729
emscriptenSearchDirs: new vscode.EventEmitter<string[]>(),
726730
mergedCompileCommands: new vscode.EventEmitter<string | null>(),
727731
copyCompileCommands: new vscode.EventEmitter<string | null>(),
732+
postConfigureTask: new vscode.EventEmitter<string | null>(),
728733
loadCompileCommands: new vscode.EventEmitter<boolean>(),
729734
configureOnOpen: new vscode.EventEmitter<boolean>(),
730735
configureOnEdit: new vscode.EventEmitter<boolean>(),

test/unit-tests/config.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ function createConfig(conf: Partial<ExtensionConfigurationSettings>): Configurat
8888
postRunCoverageTarget: null,
8989
coverageInfoFiles: [],
9090
useFolderPropertyInBuildTargetDropdown: true,
91+
postConfigureTask: null,
9192
additionalBuildProblemMatchers: [],
9293
shell: null,
9394
setBuildTargetSameAsLaunchTarget: false,

0 commit comments

Comments
 (0)