@@ -31,6 +31,11 @@ export class CppBuildTask extends Task {
31
31
isDefault ?: boolean ;
32
32
}
33
33
34
+ interface BuildOptions {
35
+ taskUsesActiveFile : boolean ;
36
+ insertStd ?: boolean ;
37
+ }
38
+
34
39
export class CppBuildTaskProvider implements TaskProvider {
35
40
static CppBuildScriptType : string = 'cppbuild' ;
36
41
@@ -166,6 +171,7 @@ export class CppBuildTaskProvider implements TaskProvider {
166
171
private getTask : ( compilerPath : string , appendSourceToName : boolean , compilerArgs ?: string [ ] , definition ?: CppBuildTaskDefinition , detail ?: string ) => Task = ( compilerPath : string , appendSourceToName : boolean , compilerArgs ?: string [ ] , definition ?: CppBuildTaskDefinition , detail ?: string ) => {
167
172
const compilerPathBase : string = path . basename ( compilerPath ) ;
168
173
const isCl : boolean = compilerPathBase . toLowerCase ( ) === "cl.exe" ;
174
+ const isClang : boolean = ! isCl && compilerPathBase . toLowerCase ( ) . includes ( "clang" ) ;
169
175
// Double-quote the command if it is not already double-quoted.
170
176
let resolvedcompilerPath : string = isCl ? compilerPathBase : compilerPath ;
171
177
if ( resolvedcompilerPath && ! resolvedcompilerPath . startsWith ( "\"" ) && resolvedcompilerPath . includes ( " " ) ) {
@@ -177,12 +183,12 @@ export class CppBuildTaskProvider implements TaskProvider {
177
183
const taskLabel : string = ( ( appendSourceToName && ! compilerPathBase . startsWith ( ext . configPrefix ) ) ?
178
184
ext . configPrefix : "" ) + compilerPathBase + " " + localize ( "build_active_file" , "build active file" ) ;
179
185
const programName : string = util . defaultExePath ( ) ;
180
- const isClang : boolean = ! isCl && compilerPathBase . toLowerCase ( ) . includes ( "clang" ) ;
181
186
let args : string [ ] = isCl ?
182
187
[ '/Zi' , '/EHsc' , '/nologo' , `/Fe${ programName } ` , '${file}' ] :
183
188
isClang ?
184
189
[ '-fcolor-diagnostics' , '-fansi-escape-codes' , '-g' , '${file}' , '-o' , programName ] :
185
190
[ '-fdiagnostics-color=always' , '-g' , '${file}' , '-o' , programName ] ;
191
+
186
192
if ( compilerArgs && compilerArgs . length > 0 ) {
187
193
args = args . concat ( compilerArgs ) ;
188
194
}
@@ -205,7 +211,7 @@ export class CppBuildTaskProvider implements TaskProvider {
205
211
const task : CppBuildTask = new Task ( definition , scope , definition . label , ext . CppSourceStr ,
206
212
new CustomExecution ( async ( resolvedDefinition : TaskDefinition ) : Promise < Pseudoterminal > =>
207
213
// When the task is executed, this callback will run. Here, we setup for running the task.
208
- new CustomBuildTaskTerminal ( resolvedcompilerPath , resolvedDefinition . args , resolvedDefinition . options , taskUsesActiveFile )
214
+ new CustomBuildTaskTerminal ( resolvedcompilerPath , resolvedDefinition . args , resolvedDefinition . options , { taskUsesActiveFile, insertStd : isClang && os . platform ( ) === 'darwin' } )
209
215
) , isCl ? '$msCompile' : '$gcc' ) ;
210
216
211
217
task . group = TaskGroup . Build ;
@@ -352,15 +358,20 @@ class CustomBuildTaskTerminal implements Pseudoterminal {
352
358
public get onDidClose ( ) : Event < number > { return this . closeEmitter . event ; }
353
359
private endOfLine : string = "\r\n" ;
354
360
355
- constructor ( private command : string , private args : string [ ] , private options : cp . ExecOptions | cp . SpawnOptions | undefined , private taskUsesActiveFile : boolean ) {
361
+ constructor ( private command : string , private args : string [ ] , private options : cp . ExecOptions | cp . SpawnOptions | undefined , private buildOptions : BuildOptions ) {
356
362
}
357
363
358
364
async open ( _initialDimensions : TerminalDimensions | undefined ) : Promise < void > {
359
- if ( this . taskUsesActiveFile && ! util . isCppOrCFile ( window . activeTextEditor ?. document . uri ) ) {
365
+ if ( this . buildOptions . taskUsesActiveFile && ! util . isCppOrCFile ( window . activeTextEditor ?. document . uri ) ) {
360
366
this . writeEmitter . fire ( localize ( "cannot.build.non.cpp" , 'Cannot build and debug because the active file is not a C or C++ source file.' ) + this . endOfLine ) ;
361
367
this . closeEmitter . fire ( - 1 ) ;
362
368
return ;
363
369
}
370
+
371
+ // TODO: Remove when compiler query work goes in and we can determine the standard version from TypeScript
372
+ if ( this . buildOptions . taskUsesActiveFile && window . activeTextEditor ?. document . languageId === 'cpp' && this . buildOptions . insertStd ) {
373
+ this . args . unshift ( '-std=gnu++14' ) ;
374
+ }
364
375
telemetry . logLanguageServerEvent ( "cppBuildTaskStarted" ) ;
365
376
// At this point we can start using the terminal.
366
377
this . writeEmitter . fire ( localize ( "starting_build" , "Starting build..." ) + this . endOfLine ) ;
0 commit comments