Skip to content

Commit

Permalink
Fix_3598 (#4206)
Browse files Browse the repository at this point in the history
* Adds default argument to CMakeProject:buildWithTarget method

* Use optional parameters instead of null default value

* Add optional target parameter to the ExtensionManager:buildWithTarget method

* CHANGELOG update
  • Loading branch information
hippo91 authored Jan 6, 2025
1 parent 1237ed1 commit 4a1d9c6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Features:

Improvements:

- Add ability to pass custom target to "CMake: Build Target" command as argument. [#3598](https://github.com/microsoft/vscode-cmake-tools/issues/3598)
- Fix "Unable to resolve configuration with compilerPath" issue for Swift. [#4097](https://github.com/microsoft/vscode-cmake-tools/issues/4097)
- Ensure that any uses of `proc.spawn` work, especially for .bat and .cmd files, due to VS Code updating to Node 20. [#4037](https://github.com/microsoft/vscode-cmake-tools/issues/4037)
- Fix "Test output isn't visible when failed" and also mark skipped tests as so. [#4116](https://github.com/microsoft/vscode-cmake-tools/issues/4116)
Expand Down
34 changes: 20 additions & 14 deletions src/cmakeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export enum ConfigureTrigger {
api = "api",
runTests = "runTests",
package = "package",
workflow = "workflow",
workflow = "workflow",
badHomeDir = "badHomeDir",
configureOnOpen = "configureOnOpen",
configureWithCache = "configureWithCache",
Expand Down Expand Up @@ -314,7 +314,7 @@ export class CMakeProject {
preset.updateCachedExpandedPreset(this.folderPath, expandedConfigurePreset, "configurePresets");

// Make sure we pass CMakeDriver the preset defined env as well as the parent env
expandedConfigurePreset.environment = EnvironmentUtils.mergePreserveNull([expandedConfigurePreset.__parentEnvironment, expandedConfigurePreset.environment]);
expandedConfigurePreset.environment = EnvironmentUtils.mergePreserveNull([expandedConfigurePreset.__parentEnvironment, expandedConfigurePreset.environment]);

return expandedConfigurePreset;
}
Expand Down Expand Up @@ -411,7 +411,7 @@ export class CMakeProject {
}

// Make sure we pass CMakeDriver the preset defined env as well as the parent env
expandedBuildPreset.environment = EnvironmentUtils.mergePreserveNull([expandedBuildPreset.__parentEnvironment, expandedBuildPreset.environment]);
expandedBuildPreset.environment = EnvironmentUtils.mergePreserveNull([expandedBuildPreset.__parentEnvironment, expandedBuildPreset.environment]);

return expandedBuildPreset;
}
Expand Down Expand Up @@ -505,7 +505,7 @@ export class CMakeProject {
}

// Make sure we pass CMakeDriver the preset defined env as well as the parent env
expandedTestPreset.environment = EnvironmentUtils.mergePreserveNull([expandedTestPreset.__parentEnvironment, expandedTestPreset.environment]);
expandedTestPreset.environment = EnvironmentUtils.mergePreserveNull([expandedTestPreset.__parentEnvironment, expandedTestPreset.environment]);

return expandedTestPreset;
}
Expand Down Expand Up @@ -599,7 +599,7 @@ export class CMakeProject {
}

// Make sure we pass CMakeDriver the preset defined env as well as the parent env
expandedPackagePreset.environment = EnvironmentUtils.mergePreserveNull([expandedPackagePreset.__parentEnvironment, expandedPackagePreset.environment]);
expandedPackagePreset.environment = EnvironmentUtils.mergePreserveNull([expandedPackagePreset.__parentEnvironment, expandedPackagePreset.environment]);

return expandedPackagePreset;
}
Expand Down Expand Up @@ -1002,7 +1002,7 @@ export class CMakeProject {
// Keep the absolute path for CMakeLists.txt files that are located outside of the workspace folder.
selectedFile = cmakeListsFile[0].fsPath;
}
} else if (selection.label === dontAskAgain) {
} else if (selection.label === dontAskAgain) {
await vscode.workspace.getConfiguration('cmake', this.workspaceFolder).update('ignoreCMakeListsMissing', true, vscode.ConfigurationTarget.WorkspaceFolder);
} else {
// Keep the relative path for CMakeLists.txt files that are located inside of the workspace folder.
Expand Down Expand Up @@ -1740,9 +1740,9 @@ export class CMakeProject {
const doNotShowAgainTitle = localize('options.configureWithDebuggerOnFail.do.not.show', "Don't Show Again");
void vscode.window.showErrorMessage<MessageItem>(
localize('configure.failed.tryWithDebugger', 'Configure failed. Would you like to attempt to configure with the CMake Debugger?'),
{title: yesButtonTitle},
{title: localize('no.configureWithDebugger.button', 'Cancel')},
{title: doNotShowAgainTitle})
{ title: yesButtonTitle },
{ title: localize('no.configureWithDebugger.button', 'Cancel') },
{ title: doNotShowAgainTitle })
.then(async chosen => {
if (chosen) {
if (chosen.title === yesButtonTitle) {
Expand Down Expand Up @@ -2228,8 +2228,14 @@ export class CMakeProject {
return 0;
}

async buildWithTarget(): Promise<number> {
const target = await this.showTargetSelector();
async buildWithTarget(specified_target?: string): Promise<number> {
const target_selector = async (spec_target: string | undefined) => {
if (!spec_target) {
return this.showTargetSelector();
}
return spec_target;
};
const target = await target_selector(specified_target);
if (target === null) {
return -1;
}
Expand Down Expand Up @@ -2795,7 +2801,7 @@ export class CMakeProject {
env = EnvironmentUtils.merge([configureEnv, env]);

if (debugEnv) {
const options = {... await this.getExpansionOptions(), envOverride: env, penvOverride: configureEnv };
const options = { ... await this.getExpansionOptions(), envOverride: env, penvOverride: configureEnv };
for (const envPair of debugEnv) {
env[envPair.name] = await expandString(envPair.value, options);
}
Expand Down Expand Up @@ -3084,7 +3090,7 @@ export class CMakeProject {
label: 'CTest',
description: localize('ctest.support', 'CTest support')
}
], { canPickMany: true, placeHolder: localize('select.additional.options', 'Select additional options')}));
], { canPickMany: true, placeHolder: localize('select.additional.options', 'Select additional options') }));

// select current c/cpp files to add as targets, if any. If none, or none are selected, create a new one
const files = await fs.readdir(this.sourceDir);
Expand All @@ -3101,7 +3107,7 @@ export class CMakeProject {
const type = targetType.label;
const lang = targetLang.label;
const langName = lang === "C++" ? "C CXX" : "C";
const langExt = lang === "C++" ? "cpp" : "c";
const langExt = lang === "C++" ? "cpp" : "c";

let failedToCreate = false;

Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ export class ExtensionManager implements vscode.Disposable {
return this.runCMakeCommandForAll(cmakeProject => cmakeProject.cleanRebuild(), this.ensureActiveBuildPreset, true);
}

async buildWithTarget() {
async buildWithTarget(target?: string) {
telemetry.logEvent("build", { command: "buildWithTarget", all: "false"});
this.cleanOutputChannel();
let activeProject: CMakeProject | undefined = this.getActiveProject();
Expand All @@ -1438,7 +1438,7 @@ export class ExtensionManager implements vscode.Disposable {
return; // Error or nothing is opened
}
} else {
return activeProject.buildWithTarget();
return activeProject.buildWithTarget(target);
}
}

Expand Down

0 comments on commit 4a1d9c6

Please sign in to comment.