Skip to content

Commit

Permalink
add clean and clean-rebuild task (#2562)
Browse files Browse the repository at this point in the history
  • Loading branch information
elahehrashedi authored May 20, 2022
1 parent 38fe599 commit fda9640
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ Improvements:
- Add c++23 support. [#2475](https://github.com/microsoft/vscode-cmake-tools/issues/2475) [@sweemer](https://github.com/sweemer)
- Add support for multiple targets in the CMake task provider. [#2122](https://github.com/microsoft/vscode-cmake-tools/issues/2122)
- Add setting `cmake.showSystemKits`. [PR #2520](https://github.com/microsoft/vscode-cmake-tools/pull/2520) [@bharatvaj](https://github.com/bharatvaj)
- Add support for "configure", "install" and "test" task. [#2452](https://github.com/microsoft/vscode-cmake-tools/issues/2452)
- Add support for "Configure", "Install" and "Test" tasks. [#2452](https://github.com/microsoft/vscode-cmake-tools/issues/2452)
- Add setting `cmake.ignoreCMakeListsMissing`. [PR #2537](https://github.com/microsoft/vscode-cmake-tools/pull/2537) [@ilg-ul](https://github.com/ilg-ul)
- Add support for "Clean" and "Clean Rebuild" tasks. [#2555](https://github.com/microsoft/vscode-cmake-tools/issues/2555)

Bug Fixes:
- `Clean All Projects` menu item builds rather than cleans. [#2460](https://github.com/microsoft/vscode-cmake-tools/issues/2460)
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,9 @@
"build",
"configure",
"install",
"test"
"test",
"clean",
"cleanRebuild"
],
"description": "CMake build command"
},
Expand Down
32 changes: 30 additions & 2 deletions src/cmakeTaskProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ enum CommandType {
build = "build",
config = "configure",
install = "install",
test = "test"
test = "test",
clean = "clean",
cleanRebuild = "cleanRebuild"
}

const localizeCommandType = (cmd: CommandType): string => {
Expand All @@ -45,6 +47,12 @@ const localizeCommandType = (cmd: CommandType): string => {
case CommandType.config: {
return localize("configure", "configure");
}
case CommandType.clean: {
return localize("clean", "clean");
}
case CommandType.cleanRebuild: {
return localize("clean.rebuild", "clean rebuild");
}
default: {
return "";
}
Expand Down Expand Up @@ -79,6 +87,8 @@ export class CMakeTaskProvider implements vscode.TaskProvider {
result.push(await this.provideTask(CommandType.config));
result.push(await this.provideTask(CommandType.install));
result.push(await this.provideTask(CommandType.test));
result.push(await this.provideTask(CommandType.clean));
result.push(await this.provideTask(CommandType.cleanRebuild));
return result;
}

Expand Down Expand Up @@ -151,6 +161,12 @@ class CustomBuildTaskTerminal implements vscode.Pseudoterminal, proc.OutputConsu
case CommandType.test:
await this.runTestTask();
break;
case CommandType.clean:
await this.runCleanTask();
break;
case CommandType.cleanRebuild:
await this.runCleanRebuildTask();
break;
default:
this.writeEmitter.fire(localize("command.not.recognized", '{0} is not a recognized command.', `"${this.command}"`) + endOfLine);
this.closeEmitter.fire(-1);
Expand Down Expand Up @@ -220,8 +236,20 @@ class CustomBuildTaskTerminal implements vscode.Pseudoterminal, proc.OutputConsu
}

private async runTestTask(): Promise<any> {
this.writeEmitter.fire(localize("Test.started", "Test Started...") + endOfLine);
this.writeEmitter.fire(localize("test.started", "Test Started...") + endOfLine);
const result: number | undefined = await vscode.commands.executeCommand('cmake.ctest');
this.closeEmitter.fire(result ? result : -1);
}

private async runCleanTask(): Promise<any> {
this.writeEmitter.fire(localize("clean.started", "Clean Started...") + endOfLine);
const result: number | undefined = await vscode.commands.executeCommand('cmake.clean');
this.closeEmitter.fire(result ? result : -1);
}

private async runCleanRebuildTask(): Promise<any> {
this.writeEmitter.fire(localize("clean.rebuild.started", "Clean Rebuild Started...") + endOfLine);
const result: number | undefined = await vscode.commands.executeCommand('cmake.cleanRebuild');
this.closeEmitter.fire(result ? result : -1);
}
}

0 comments on commit fda9640

Please sign in to comment.