From aa4c5df4b704ebbb9c9bd482f6f6b18779ee601a Mon Sep 17 00:00:00 2001 From: Sean McManus Date: Thu, 3 Dec 2020 14:00:20 -0800 Subject: [PATCH 1/2] Fix cwd. (#6619) Fixes #6618 --- Extension/src/Debugger/configurationProvider.ts | 7 +++++-- Extension/src/LanguageServer/cppBuildTaskProvider.ts | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Extension/src/Debugger/configurationProvider.ts b/Extension/src/Debugger/configurationProvider.ts index a1e09cf090..3b65ac78c4 100644 --- a/Extension/src/Debugger/configurationProvider.ts +++ b/Extension/src/Debugger/configurationProvider.ts @@ -178,10 +178,13 @@ class CppConfigurationProvider implements vscode.DebugConfigurationProvider { newConfig.preLaunchTask = task.name; newConfig.externalConsole = false; const exeName: string = path.join("${fileDirname}", "${fileBasenameNoExtension}"); - newConfig.program = platform === "win32" ? exeName + ".exe" : exeName; + const isWindows: boolean = platform === 'win32'; + newConfig.program = isWindows ? exeName + ".exe" : exeName; // Add the "detail" property to show the compiler path in QuickPickItem. // This property will be removed before writing the DebugConfiguration in launch.json. newConfig.detail = task.detail ? task.detail : definition.command; + const isCl: boolean = compilerName === "cl.exe"; + newConfig.cwd = isWindows && !isCl && !process.env.PATH?.includes(compilerPath) ? path.dirname(compilerPath) : "${workspaceFolder}"; return new Promise(resolve => { if (platform === "darwin") { @@ -201,7 +204,7 @@ class CppConfigurationProvider implements vscode.DebugConfigurationProvider { debuggerName = "gdb"; } - if (platform === "win32") { + if (isWindows) { debuggerName += ".exe"; } diff --git a/Extension/src/LanguageServer/cppBuildTaskProvider.ts b/Extension/src/LanguageServer/cppBuildTaskProvider.ts index 78b250a555..fa93b334b0 100644 --- a/Extension/src/LanguageServer/cppBuildTaskProvider.ts +++ b/Extension/src/LanguageServer/cppBuildTaskProvider.ts @@ -167,7 +167,7 @@ export class CppBuildTaskProvider implements TaskProvider { if (compilerArgs && compilerArgs.length > 0) { args = args.concat(compilerArgs); } - const cwd: string = isCl ? "${workspaceFolder}" : path.dirname(compilerPath); + const cwd: string = isWindows && !isCl && !process.env.PATH?.includes(compilerPath) ? path.dirname(compilerPath) : "${workspaceFolder}"; const options: cp.ExecOptions | undefined = { cwd: cwd }; definition = { type: CppBuildTaskProvider.CppBuildScriptType, From 52fe7952d6735d4a78e053320fe8c9e5f68071fc Mon Sep 17 00:00:00 2001 From: Sean McManus Date: Thu, 3 Dec 2020 14:14:30 -0800 Subject: [PATCH 2/2] Update changelog. --- Extension/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Extension/CHANGELOG.md b/Extension/CHANGELOG.md index d33b5923c7..362d655ee4 100644 --- a/Extension/CHANGELOG.md +++ b/Extension/CHANGELOG.md @@ -7,6 +7,7 @@ * Fix various task variables not getting resolved with `cppbuild` tasks. [#6538](https://github.com/microsoft/vscode-cpptools/issues/6538) * Fix warnings not appearing with `cppbuild` tasks. [#6556](https://github.com/microsoft/vscode-cpptools/issues/6556) * Fix endless CPU/memory usage if the cpptools process crashes. [#6603](https://github.com/microsoft/vscode-cpptools/issues/6603) +* Fix the default `cwd` for `cppbuild` tasks. [#6618](https://github.com/microsoft/vscode-cpptools/issues/6618) ## Version 1.1.2: November 17, 2020 ### Bug Fix