@@ -36,7 +36,9 @@ export enum BuildMode {
36
36
Verify = "Verifying" ,
37
37
Analyze = "Analyzing" ,
38
38
Upload = "Uploading" ,
39
+ CliUpload = "Uploading latest binaries" ,
39
40
UploadProgrammer = "Uploading (programmer)" ,
41
+ CliUploadProgrammer = "Uploading latest binaries (programmer)" ,
40
42
} ;
41
43
42
44
/**
@@ -219,34 +221,44 @@ export class ArduinoApp {
219
221
}
220
222
}
221
223
222
- /**
223
- * Install arduino board package based on package name and platform hardware architecture.
224
- */
224
+ /**
225
+ * Installs arduino board package.
226
+ * (If using the aduino CLI this installs the corrosponding core.)
227
+ * @param {string } packageName - board vendor
228
+ * @param {string } arch - board architecture
229
+ * @param {string } version - version of board package or core to download
230
+ * @param {boolean } [showOutput=true] - show raw output from command
231
+ */
225
232
public async installBoard ( packageName : string , arch : string = "" , version : string = "" , showOutput : boolean = true ) {
226
233
arduinoChannel . show ( ) ;
227
234
const updatingIndex = packageName === "dummy" && ! arch && ! version ;
228
235
if ( updatingIndex ) {
229
236
arduinoChannel . start ( `Update package index files...` ) ;
230
237
} else {
231
238
try {
232
- const packagePath = path . join ( this . _settings . packagePath , "packages" , packageName ) ;
239
+ const packagePath = path . join ( this . _settings . packagePath , "packages" , packageName , arch ) ;
233
240
if ( util . directoryExistsSync ( packagePath ) ) {
234
241
util . rmdirRecursivelySync ( packagePath ) ;
235
242
}
236
243
arduinoChannel . start ( `Install package - ${ packageName } ...` ) ;
237
244
} catch ( error ) {
238
245
arduinoChannel . start ( `Install package - ${ packageName } failed under directory : ${ error . path } ${ os . EOL }
239
- Please make sure the folder is not occupied by other procedures .` ) ;
246
+ Please make sure the folder is not occupied by other procedures .`) ;
240
247
arduinoChannel . error ( `Error message - ${ error . message } ${ os . EOL } ` ) ;
241
248
arduinoChannel . error ( `Exit with code=${ error . code } ${ os . EOL } ` ) ;
242
249
return ;
243
250
}
244
251
}
252
+ arduinoChannel . info ( `${ packageName } ${ arch && ":" + arch } ${ version && ":" + version } ` ) ;
245
253
try {
246
- await util . spawn ( this . _settings . commandPath ,
247
- [ "--install-boards" , `${ packageName } ${ arch && ":" + arch } ${ version && ":" + version } ` ] ,
248
- undefined ,
249
- { channel : showOutput ? arduinoChannel . channel : null } ) ;
254
+ this . _settings . useArduinoCli ?
255
+ await util . spawn ( this . _settings . commandPath ,
256
+ [ "core" , "install" , `${ packageName } ${ arch && ":" + arch } ${ version && "@" + version } ` ] , undefined ,
257
+ { channel : showOutput ? arduinoChannel . channel : null } ) :
258
+ await util . spawn ( this . _settings . commandPath ,
259
+ [ "--install-boards" , `${ packageName } ${ arch && ":" + arch } ${ version && ":" + version } ` ] , undefined ,
260
+ { channel : showOutput ? arduinoChannel . channel : null } ) ;
261
+
250
262
if ( updatingIndex ) {
251
263
arduinoChannel . end ( "Updated package index files." ) ;
252
264
} else {
@@ -272,6 +284,13 @@ Please make sure the folder is not occupied by other procedures .`);
272
284
arduinoChannel . end ( `Uninstalled board package - ${ boardName } ${ os . EOL } ` ) ;
273
285
}
274
286
287
+ /**
288
+ * Downloads or updates a library
289
+ * @param {string } libName - name of the library to download
290
+ * @param {string } version - version of library to download
291
+ * @param {boolean } [showOutput=true] - show raw output from command
292
+ */
293
+
275
294
public async installLibrary ( libName : string , version : string = "" , showOutput : boolean = true ) {
276
295
arduinoChannel . show ( ) ;
277
296
const updatingIndex = ( libName === "dummy" && ! version ) ;
@@ -281,6 +300,11 @@ Please make sure the folder is not occupied by other procedures .`);
281
300
arduinoChannel . start ( `Install library - ${ libName } ` ) ;
282
301
}
283
302
try {
303
+ this . useArduinoCli ( ) ?
304
+ await util . spawn ( this . _settings . commandPath ,
305
+ [ "lib" , "install" , `${ libName } ${ version && "@" + version } ` ] ,
306
+ undefined ,
307
+ { channel : showOutput ? arduinoChannel . channel : undefined } ) :
284
308
await util . spawn ( this . _settings . commandPath ,
285
309
[ "--install-library" , `${ libName } ${ version && ":" + version } ` ] ,
286
310
undefined ,
@@ -450,8 +474,25 @@ Please make sure the folder is not occupied by other procedures .`);
450
474
arduinoChannel . error ( `Running ${ what } -build command failed: ${ os . EOL } ${ msg } ` ) ;
451
475
return false ;
452
476
}
477
+ return true ;
478
+ }
479
+ }
480
+
481
+ /**
482
+ * Checks if the arduino cli is being used
483
+ * @returns {bool } - true if arduino cli is being use
484
+ */
485
+ private useArduinoCli ( ) {
486
+ return this . _settings . useArduinoCli ;
487
+ // return VscodeSettings.getInstance().useArduinoCli;
488
+ }
489
+
490
+ private getProgrammerString ( ) : string {
491
+ const selectProgrammer = this . programmerManager . currentProgrammer ;
492
+ if ( ! selectProgrammer ) {
493
+ logger . notifyUserError ( "getProgrammerString" , new Error ( constants . messages . NO_PROGRAMMMER_SELECTED ) ) ;
494
+ return ;
453
495
}
454
- return true ;
455
496
}
456
497
457
498
/**
@@ -475,7 +516,7 @@ Please make sure the folder is not occupied by other procedures .`);
475
516
}
476
517
const boardDescriptor = this . boardManager . currentBoard . getBuildConfig ( ) ;
477
518
478
- args . push ( "--board" , boardDescriptor ) ;
519
+ this . _settings . useArduinoCli ? args . push ( "-b" , boardDescriptor ) : args . push ( "--board" , boardDescriptor ) ;
479
520
480
521
if ( ! ArduinoWorkspace . rootPath ) {
481
522
vscode . window . showWarningMessage ( "Workspace doesn't seem to have a folder added to it yet." ) ;
@@ -507,7 +548,26 @@ Please make sure the folder is not occupied by other procedures .`);
507
548
await selectSerial ( ) ;
508
549
return false ;
509
550
}
510
- args . push ( "--upload" ) ;
551
+
552
+ this . _settings . useArduinoCli ? args . push ( "compile" , "--upload" ) : args . push ( "--upload" ) ;
553
+
554
+ if ( dc . port ) {
555
+ args . push ( "--port" , dc . port ) ;
556
+ }
557
+
558
+ } else if ( mode === BuildMode . CliUpload ) {
559
+ 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 ) {
560
+ await selectSerial ( ) ;
561
+ return false ;
562
+ }
563
+
564
+ if ( ! this . _settings . useArduinoCli ) {
565
+ arduinoChannel . error ( "This command is only avaialble while using the Arduino CLI" ) ;
566
+ return false ;
567
+ }
568
+
569
+ args . push ( "upload" ) ;
570
+
511
571
if ( dc . port ) {
512
572
args . push ( "--port" , dc . port ) ;
513
573
}
@@ -521,15 +581,43 @@ Please make sure the folder is not occupied by other procedures .`);
521
581
await selectSerial ( ) ;
522
582
return false ;
523
583
}
524
- args . push ( "--upload" ,
525
- "--port" , dc . port ,
526
- "--useprogrammer" ,
527
- "--pref" , `programmer=${ programmer } ` ) ;
584
+ this . _settings . useArduinoCli ?
585
+ args . push ( "compile" ,
586
+ "--upload" ,
587
+ "--porgrammer" , programmer ) :
588
+ args . push ( "--upload" ,
589
+ "--useprogrammer" ,
590
+ "--pref" , `programmer=${ programmer } ` ) ;
591
+
592
+ args . push ( "--port" , dc . port ) ;
593
+
594
+ } else if ( mode === BuildMode . CliUploadProgrammer ) {
595
+ const programmer = this . programmerManager . currentProgrammer ;
596
+ if ( ! programmer ) {
597
+ logger . notifyUserError ( "getProgrammerString" , new Error ( constants . messages . NO_PROGRAMMMER_SELECTED ) ) ;
598
+ return false ;
599
+ }
600
+ if ( ! dc . port ) {
601
+ await selectSerial ( ) ;
602
+ return false ;
603
+ }
604
+
605
+ if ( ! this . _settings . useArduinoCli ) {
606
+ arduinoChannel . error ( "This command is only avaialble while using the Arduino CLI" ) ;
607
+ return false ;
608
+ }
609
+
610
+ args . push ( "compile" ,
611
+ "--upload" ,
612
+ "--porgrammer" , programmer ,
613
+ "--port" , dc . port ) ;
614
+
528
615
} else {
529
616
args . push ( "--verify" ) ;
530
617
}
531
618
532
- if ( dc . buildPreferences ) {
619
+ // TODO: Option to add prefrences when using the CLI
620
+ if ( dc . buildPreferences && ! this . _settings . useArduinoCli ) {
533
621
for ( const pref of dc . buildPreferences ) {
534
622
// Note: BuildPrefSetting makes sure that each preference
535
623
// value consists of exactly two items (key and value).
@@ -538,9 +626,12 @@ Please make sure the folder is not occupied by other procedures .`);
538
626
}
539
627
540
628
// We always build verbosely but filter the output based on the settings
541
- args . push ( "--verbose-build" ) ;
629
+ if ( ! this . _settings . useArduinoCli ) {
630
+ args . push ( "--verbose-build" ) ;
631
+ }
632
+
542
633
if ( verbose ) {
543
- args . push ( "--verbose-upload" ) ;
634
+ this . _settings . useArduinoCli ? args . push ( "--verbose" ) : args . push ( "--verbose-upload" ) ;
544
635
}
545
636
546
637
await vscode . workspace . saveAll ( false ) ;
@@ -559,7 +650,7 @@ Please make sure the folder is not occupied by other procedures .`);
559
650
logger . notifyUserError ( "InvalidOutPutPath" , new Error ( constants . messages . INVALID_OUTPUT_PATH + buildDir ) ) ;
560
651
return false ;
561
652
}
562
- args . push ( "--pref" , `build.path=${ buildDir } ` ) ;
653
+ this . _settings . useArduinoCli ? args . push ( "--build-path" , buildDir ) : args . push ( "--pref" , `build.path=${ buildDir } ` ) ;
563
654
arduinoChannel . info ( `Please see the build logs in output path: ${ buildDir } ` ) ;
564
655
} else {
565
656
const msg = "Output path is not specified. Unable to reuse previously compiled files. Build will be slower. See README." ;
0 commit comments