Skip to content

Commit

Permalink
don't overwrite options and args (#6374)
Browse files Browse the repository at this point in the history
* dont overwrite options and args

* linter error

* update changelog
  • Loading branch information
elahehrashedi authored Oct 22, 2020
1 parent 61ab30f commit 3832029
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
1 change: 1 addition & 0 deletions Extension/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 9 additions & 10 deletions Extension/src/LanguageServer/cppBuildTaskProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,26 +154,25 @@ 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(" ")) {
resolvedcompilerPath = "\"" + resolvedcompilerPath + "\"";
}

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,
Expand All @@ -196,7 +195,7 @@ export class CppBuildTaskProvider implements TaskProvider {
const task: CppBuildTask = new Task(definition, scope, taskLabel, CppBuildTaskProvider.CppBuildSourceStr,
new CustomExecution(async (): Promise<Pseudoterminal> =>
// 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;
Expand Down

0 comments on commit 3832029

Please sign in to comment.