Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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