@@ -361,8 +361,6 @@ export class ArduinoApp {
361
361
UsbDetector . getInstance ( ) . pauseListening ( ) ;
362
362
}
363
363
364
- let success = false ;
365
-
366
364
// Push sketch as last argument
367
365
args . push ( path . join ( ArduinoWorkspace . rootPath , dc . sketch ) ) ;
368
366
@@ -378,25 +376,14 @@ export class ArduinoApp {
378
376
}
379
377
}
380
378
381
- // TODO: Get rid of spawn's channel parameter and just support
382
- // stdout and stderr callbacks
383
- const stdoutCallback = ( line : string ) => {
384
- if ( cocopa ) {
385
- cocopa . callback ( line ) ;
386
- if ( verbose ) {
387
- arduinoChannel . channel . append ( line ) ;
388
- }
389
- } else {
390
- arduinoChannel . channel . append ( line ) ;
391
- }
392
- }
393
-
394
- await util . spawn (
379
+ return await util . spawn (
395
380
this . _settings . commandPath ,
396
- arduinoChannel . channel ,
397
381
args ,
398
382
undefined ,
399
- stdoutCallback ,
383
+ {
384
+ channel : ! cocopa || cocopa && verbose ? arduinoChannel . channel : undefined ,
385
+ stdout : cocopa ? cocopa . callback : undefined ,
386
+ } ,
400
387
) . then ( async ( ) => {
401
388
await cleanup ( ) ;
402
389
if ( buildMode !== BuildMode . Analyze ) {
@@ -406,18 +393,15 @@ export class ArduinoApp {
406
393
arduinoChannel . info ( `To rebuild your IntelliSense configuration run "${ cmd } "` ) ;
407
394
}
408
395
arduinoChannel . end ( `${ buildMode } sketch '${ dc . sketch } '${ os . EOL } ` ) ;
409
- success = true ;
396
+ return true ;
410
397
} , async ( reason ) => {
411
398
await cleanup ( ) ;
412
399
const msg = reason . code
413
400
? `Exit with code=${ reason . code } `
414
- : reason . message
415
- ? reason . message
416
- : JSON . stringify ( reason ) ;
401
+ : JSON . stringify ( reason ) ;
417
402
arduinoChannel . error ( `${ buildMode } sketch '${ dc . sketch } ': ${ msg } ${ os . EOL } ` ) ;
403
+ return false ;
418
404
} ) ;
419
-
420
- return success ;
421
405
}
422
406
423
407
// Include the *.h header files from selected library to the arduino sketch.
@@ -481,14 +465,17 @@ export class ArduinoApp {
481
465
}
482
466
arduinoChannel . info ( `${ packageName } ${ arch && ":" + arch } ${ version && ":" + version } ` ) ;
483
467
try {
484
- this . useArduinoCli ( ) ?
468
+ if ( this . useArduinoCli ( ) ) {
485
469
await util . spawn ( this . _settings . commandPath ,
486
- showOutput ? arduinoChannel . channel : null ,
487
- [ "core" , "install" , `${ packageName } ${ arch && ":" + arch } ${ version && "@" + version } ` ] ) :
470
+ [ "core" , "install" , `${ packageName } ${ arch && ":" + arch } ${ version && "@" + version } ` ] ,
471
+ undefined ,
472
+ { channel : showOutput ? arduinoChannel . channel : null } ) ;
473
+ } else {
488
474
await util . spawn ( this . _settings . commandPath ,
489
- showOutput ? arduinoChannel . channel : null ,
490
- [ "--install-boards" , `${ packageName } ${ arch && ":" + arch } ${ version && ":" + version } ` ] ) ;
491
-
475
+ [ "--install-boards" , `${ packageName } ${ arch && ":" + arch } ${ version && ":" + version } ` ] ,
476
+ undefined ,
477
+ { channel : showOutput ? arduinoChannel . channel : null } ) ;
478
+ }
492
479
if ( updatingIndex ) {
493
480
arduinoChannel . end ( "Updated package index files." ) ;
494
481
} else {
@@ -530,14 +517,17 @@ export class ArduinoApp {
530
517
arduinoChannel . start ( `Install library - ${ libName } ` ) ;
531
518
}
532
519
try {
533
- this . useArduinoCli ( ) ?
534
- await util . spawn ( this . _settings . commandPath ,
535
- showOutput ? arduinoChannel . channel : null ,
536
- [ "lib" , "install" , `${ libName } ${ version && "@" + version } ` ] ) :
537
- await util . spawn ( this . _settings . commandPath ,
538
- showOutput ? arduinoChannel . channel : null ,
539
- [ "--install-library" , `${ libName } ${ version && ":" + version } ` ] ) ;
540
-
520
+ if ( this . useArduinoCli ( ) ) {
521
+ await util . spawn ( this . _settings . commandPath ,
522
+ [ "lib" , "install" , `${ libName } ${ version && "@" + version } ` ] ,
523
+ undefined ,
524
+ { channel : showOutput ? arduinoChannel . channel : undefined } ) ;
525
+ } else {
526
+ await util . spawn ( this . _settings . commandPath ,
527
+ [ "--install-library" , `${ libName } ${ version && ":" + version } ` ] ,
528
+ undefined ,
529
+ { channel : showOutput ? arduinoChannel . channel : undefined } ) ;
530
+ }
541
531
if ( updatingIndex ) {
542
532
arduinoChannel . end ( "Updated library index files." ) ;
543
533
} else {
@@ -671,9 +661,9 @@ export class ArduinoApp {
671
661
const cmd = args . shift ( ) ;
672
662
try {
673
663
await util . spawn ( cmd ,
674
- arduinoChannel . channel ,
675
664
args ,
676
- { shell : true , cwd : ArduinoWorkspace . rootPath } ) ;
665
+ { shell : true , cwd : ArduinoWorkspace . rootPath } ,
666
+ { channel : arduinoChannel . channel } ) ;
677
667
} catch ( ex ) {
678
668
arduinoChannel . error ( `Running pre-build command failed: ${ os . EOL } ${ ex . error } ` ) ;
679
669
return false ;
0 commit comments