From cbcdfaf60de90a82be70e09bf3f1fa801e262bb2 Mon Sep 17 00:00:00 2001 From: Guillaume Peillex Date: Sat, 7 Dec 2024 13:42:07 +0100 Subject: [PATCH 1/4] Adds default argument to CMakeProject:buildWithTarget method --- src/cmakeProject.ts | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/cmakeProject.ts b/src/cmakeProject.ts index 61e067d18..a5294d0b3 100644 --- a/src/cmakeProject.ts +++ b/src/cmakeProject.ts @@ -75,7 +75,7 @@ export enum ConfigureTrigger { api = "api", runTests = "runTests", package = "package", - workflow = "workflow", + workflow = "workflow", badHomeDir = "badHomeDir", configureOnOpen = "configureOnOpen", configureWithCache = "configureWithCache", @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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. @@ -1740,9 +1740,9 @@ export class CMakeProject { const doNotShowAgainTitle = localize('options.configureWithDebuggerOnFail.do.not.show', "Don't Show Again"); void vscode.window.showErrorMessage( 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) { @@ -2228,8 +2228,14 @@ export class CMakeProject { return 0; } - async buildWithTarget(): Promise { - const target = await this.showTargetSelector(); + async buildWithTarget(specified_target: string | null = null): Promise { + const target_selector = async (spec_target: string | null) => { + if (!spec_target) { + return this.showTargetSelector(); + } + return spec_target; + }; + const target = await target_selector(specified_target); if (target === null) { return -1; } @@ -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); } @@ -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); @@ -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; From 127d9ef3864aa5a729a4b90867cfc00fc61596bd Mon Sep 17 00:00:00 2001 From: Guillaume Peillex Date: Sat, 7 Dec 2024 14:02:14 +0100 Subject: [PATCH 2/4] Use optional parameters instead of null default value --- src/cmakeProject.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmakeProject.ts b/src/cmakeProject.ts index a5294d0b3..2cdb0d3de 100644 --- a/src/cmakeProject.ts +++ b/src/cmakeProject.ts @@ -2228,8 +2228,8 @@ export class CMakeProject { return 0; } - async buildWithTarget(specified_target: string | null = null): Promise { - const target_selector = async (spec_target: string | null) => { + async buildWithTarget(specified_target?: string): Promise { + const target_selector = async (spec_target: string | undefined) => { if (!spec_target) { return this.showTargetSelector(); } From cd943fea5f3d5560a440cff646bdba2457f6beaa Mon Sep 17 00:00:00 2001 From: Guillaume Peillex Date: Sat, 7 Dec 2024 14:04:04 +0100 Subject: [PATCH 3/4] Add optional target parameter to the ExtensionManager:buildWithTarget method --- src/extension.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index b22908de8..b5eefe92b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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(); @@ -1438,7 +1438,7 @@ export class ExtensionManager implements vscode.Disposable { return; // Error or nothing is opened } } else { - return activeProject.buildWithTarget(); + return activeProject.buildWithTarget(target); } } From 4950fd43ea2a688c39c6fc0e0462c8575f1e56b7 Mon Sep 17 00:00:00 2001 From: Guillaume Peillex Date: Sat, 21 Dec 2024 10:53:06 +0100 Subject: [PATCH 4/4] CHANGELOG update --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b6413557..e7a997216 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)