@@ -36,7 +36,9 @@ export enum BuildMode {
36
36
Verify = "Verifying" ,
37
37
Analyze = "Analyzing" ,
38
38
Upload = "Uploading" ,
39
+ CliUpload = "Uploading using Arduino CLI" ,
39
40
UploadProgrammer = "Uploading (programmer)" ,
41
+ CliUploadProgrammer = "Uploading (programmer) using Arduino CLI" ,
40
42
} ;
41
43
42
44
/**
@@ -74,7 +76,7 @@ export class ArduinoApp {
74
76
const analysisDelayMs = 1000 * 3 ;
75
77
this . _analysisManager = new AnalysisManager (
76
78
( ) => this . _building ,
77
- async ( ) => { await this . build ( BuildMode . Analyze , true ) ; } ,
79
+ async ( ) => { await this . build ( BuildMode . Analyze ) ; } ,
78
80
analysisDelayMs ) ;
79
81
}
80
82
@@ -159,23 +161,22 @@ export class ArduinoApp {
159
161
* something is missing, it tries to query the user for the missing piece
160
162
* of information (sketch, board, etc.). Analyze runs non interactively and
161
163
* just returns false.
162
- * @param {bool } compile - Indicates whether to compile the code when using the CLI to upload
163
164
* @param buildDir Override the build directory set by the project settings
164
165
* with the given directory.
165
166
* @returns true on success, false if
166
167
* * another build is currently in progress
167
168
* * board- or programmer-manager aren't initialized yet
168
169
* * or something went wrong during the build
169
170
*/
170
- public async build ( buildMode : BuildMode , compile : boolean , buildDir ?: string ) {
171
+ public async build ( buildMode : BuildMode , buildDir ?: string ) {
171
172
172
173
if ( ! this . _boardManager || ! this . _programmerManager || this . _building ) {
173
174
return false ;
174
175
}
175
176
176
177
this . _building = true ;
177
178
178
- return await this . _build ( buildMode , compile , buildDir )
179
+ return await this . _build ( buildMode , buildDir )
179
180
. then ( ( ret ) => {
180
181
this . _building = false ;
181
182
return ret ;
@@ -498,7 +499,7 @@ export class ArduinoApp {
498
499
* @param buildDir See build()
499
500
* @see https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc
500
501
*/
501
- private async _build ( buildMode : BuildMode , compile : boolean , buildDir ?: string ) : Promise < boolean > {
502
+ private async _build ( buildMode : BuildMode , buildDir ?: string ) : Promise < boolean > {
502
503
const dc = DeviceContext . getInstance ( ) ;
503
504
const args : string [ ] = [ ] ;
504
505
let restoreSerialMonitor : boolean = false ;
@@ -549,22 +550,28 @@ export class ArduinoApp {
549
550
return false ;
550
551
}
551
552
552
- if ( ! compile && ! this . useArduinoCli ( ) ) {
553
- arduinoChannel . error ( "This command is only available when using the Arduino CLI" ) ;
553
+ if ( ! this . useArduinoCli ( ) ) {
554
+ args . push ( "--upload" ) ;
555
+ } else {
556
+ args . push ( "compile" , "--upload" ) ;
557
+ }
558
+
559
+ if ( dc . port ) {
560
+ args . push ( "--port" , dc . port ) ;
561
+ }
562
+ } else if ( buildMode === BuildMode . CliUpload ) {
563
+ if ( ( ! dc . configuration || ! / u p l o a d _ m e t h o d = [ ^ = , ] * s t [ ^ , ] * l i n k / i. test ( dc . configuration ) ) && ! dc . port ) {
564
+ await selectSerial ( ) ;
554
565
return false ;
555
566
}
556
567
557
568
if ( ! this . useArduinoCli ( ) ) {
558
- args . push ( "--upload" ) ;
559
- } else {
560
- // TODO: add the --clean argument to the cli args when v 0.14 is released (this will clean up the build folder after uploading)
561
- if ( compile ) {
562
- args . push ( "compile" , "--upload" ) ;
563
- } else {
564
- args . push ( "upload" ) ;
565
- }
569
+ arduinoChannel . error ( "This command is only available when using the Arduino CLI" ) ;
570
+ return false ;
566
571
}
567
572
573
+ args . push ( "upload" ) ;
574
+
568
575
if ( dc . port ) {
569
576
args . push ( "--port" , dc . port ) ;
570
577
}
@@ -578,20 +585,12 @@ export class ArduinoApp {
578
585
await selectSerial ( ) ;
579
586
return false ;
580
587
}
581
- if ( ! compile && ! this . useArduinoCli ( ) ) {
582
- arduinoChannel . error ( "This command is only available when using the Arduino CLI" ) ;
583
- return false ;
584
- }
585
588
586
589
if ( ! this . useArduinoCli ( ) ) {
587
590
args . push ( "--upload" ) ;
588
591
} else {
589
592
// TODO: add the --clean argument to the cli args when v 0.14 is released (this will clean up the build folder after uploading)
590
- if ( compile ) {
591
- args . push ( "compile" , "--upload" ) ;
592
- } else {
593
- args . push ( "upload" ) ;
594
- }
593
+ args . push ( "upload" ) ;
595
594
}
596
595
597
596
if ( this . useArduinoCli ( ) ) {
@@ -604,6 +603,24 @@ export class ArduinoApp {
604
603
if ( ! this . useArduinoCli ( ) ) {
605
604
args . push ( "--verify" ) ;
606
605
}
606
+ } else if ( buildMode === BuildMode . CliUploadProgrammer ) {
607
+ const programmer = this . programmerManager . currentProgrammer ;
608
+ if ( ! programmer ) {
609
+ logger . notifyUserError ( "programmerManager.currentProgrammer" , new Error ( constants . messages . NO_PROGRAMMMER_SELECTED ) ) ;
610
+ return false ;
611
+ }
612
+ if ( ! dc . port ) {
613
+ await selectSerial ( ) ;
614
+ return false ;
615
+ }
616
+ if ( ! this . useArduinoCli ( ) ) {
617
+ arduinoChannel . error ( "This command is only available when using the Arduino CLI" ) ;
618
+ return false ;
619
+ }
620
+
621
+ args . push ( "compile" , "--upload" ) ;
622
+ args . push ( "--programmer" , programmer )
623
+ args . push ( "--port" , dc . port ) ;
607
624
} else {
608
625
if ( ! this . useArduinoCli ( ) ) {
609
626
args . push ( "--verify" ) ;
@@ -631,7 +648,7 @@ export class ArduinoApp {
631
648
arduinoChannel . show ( ) ;
632
649
arduinoChannel . start ( `${ buildMode } sketch '${ dc . sketch } '` ) ;
633
650
634
- if ( ( buildDir || dc . output ) && compile ) {
651
+ if ( buildDir || dc . output ) {
635
652
// 2020-02-29, EW: This whole code appears a bit wonky to me.
636
653
// What if the user specifies an output directory "../builds/my project"
637
654
buildDir = path . resolve ( ArduinoWorkspace . rootPath , buildDir || dc . output ) ;
0 commit comments