From 3832029be4d973222bd2b868bfe849f1643a94e1 Mon Sep 17 00:00:00 2001 From: Elaheh Rashedi Date: Thu, 22 Oct 2020 16:47:23 -0700 Subject: [PATCH] don't overwrite options and args (#6374) * dont overwrite options and args * linter error * update changelog --- Extension/CHANGELOG.md | 1 + .../LanguageServer/cppBuildTaskProvider.ts | 19 +++++++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Extension/CHANGELOG.md b/Extension/CHANGELOG.md index 50c3e6eefc..4291b8c107 100644 --- a/Extension/CHANGELOG.md +++ b/Extension/CHANGELOG.md @@ -23,6 +23,7 @@ * Fix issue with compiler querying not handling various clang command line options correctly. [6359](https://github.com/microsoft/vscode-cpptools/issues/6356) * Fix issue where std change warnings were not generated if IntelliSense mode was not set. * Fix issue macOS Framework search to only parse the "Current" framework folder when the "Headers" folder is not found. [#2046](https://github.com/microsoft/vscode-cpptools/issues/2046) +* Fix issue to not overwrite the compiler options and args when building from a custom defined task. [#6366](https://github.com/microsoft/vscode-cpptools/issues/6366) ## Version 1.1.0-insiders2: October 15, 2020 ### Bug Fixes diff --git a/Extension/src/LanguageServer/cppBuildTaskProvider.ts b/Extension/src/LanguageServer/cppBuildTaskProvider.ts index a652aa6b8d..959a015e80 100644 --- a/Extension/src/LanguageServer/cppBuildTaskProvider.ts +++ b/Extension/src/LanguageServer/cppBuildTaskProvider.ts @@ -154,19 +154,10 @@ export class CppBuildTaskProvider implements TaskProvider { } private getTask: (compilerPath: string, appendSourceToName: boolean, compilerArgs?: string[], definition?: CppBuildTaskDefinition) => Task = (compilerPath: string, appendSourceToName: boolean, compilerArgs?: string[], definition?: CppBuildTaskDefinition) => { - const filePath: string = path.join('${fileDirname}', '${fileBasenameNoExtension}'); const compilerPathBase: string = path.basename(compilerPath); const taskLabel: string = ((appendSourceToName && !compilerPathBase.startsWith(CppBuildTaskProvider.CppBuildSourceStr)) ? CppBuildTaskProvider.CppBuildSourceStr + ": " : "") + compilerPathBase + " build active file"; const isCl: boolean = compilerPathBase === "cl.exe"; - const isWindows: boolean = os.platform() === 'win32'; - const cwd: string = isCl ? "${workspaceFolder}" : path.dirname(compilerPath); - let args: string[] = isCl ? ['/Zi', '/EHsc', '/Fe:', filePath + '.exe', '${file}'] : ['-g', '${file}', '-o', filePath + (isWindows ? '.exe' : '')]; - if (!definition && compilerArgs && compilerArgs.length > 0) { - args = args.concat(compilerArgs); - } - const options: cp.ExecOptions | undefined = { cwd: cwd }; - // Double-quote the command if it is not already double-quoted. let resolvedcompilerPath: string = isCl ? compilerPathBase : compilerPath; if (resolvedcompilerPath && !resolvedcompilerPath.startsWith("\"") && resolvedcompilerPath.includes(" ")) { @@ -174,6 +165,14 @@ export class CppBuildTaskProvider implements TaskProvider { } if (!definition) { + const filePath: string = path.join('${fileDirname}', '${fileBasenameNoExtension}'); + const isWindows: boolean = os.platform() === 'win32'; + let args: string[] = isCl ? ['/Zi', '/EHsc', '/Fe:', filePath + '.exe', '${file}'] : ['-g', '${file}', '-o', filePath + (isWindows ? '.exe' : '')]; + if (compilerArgs && compilerArgs.length > 0) { + args = args.concat(compilerArgs); + } + const cwd: string = isCl ? "${workspaceFolder}" : path.dirname(compilerPath); + const options: cp.ExecOptions | undefined = { cwd: cwd }; definition = { type: CppBuildTaskProvider.CppBuildScriptType, label: taskLabel, @@ -196,7 +195,7 @@ export class CppBuildTaskProvider implements TaskProvider { const task: CppBuildTask = new Task(definition, scope, taskLabel, CppBuildTaskProvider.CppBuildSourceStr, new CustomExecution(async (): Promise => // When the task is executed, this callback will run. Here, we setup for running the task. - new CustomBuildTaskTerminal(resolvedcompilerPath, args, options) + new CustomBuildTaskTerminal(resolvedcompilerPath, definition ? definition.args : [], definition ? definition.options : undefined) ), isCl ? '$msCompile' : '$gcc'); task.group = TaskGroup.Build;