@@ -19,6 +19,7 @@ import (
19
19
"fmt"
20
20
"os"
21
21
"path/filepath"
22
+ "strings"
22
23
23
24
"github.com/arduino/arduino-cli/arduino/cores"
24
25
"github.com/arduino/arduino-cli/configuration"
@@ -250,8 +251,7 @@ func (pm *PackageManager) loadPlatform(targetPackage *cores.Package, platformPat
250
251
pm .Log .Infof ("Package is built-in" )
251
252
}
252
253
if err := pm .loadPlatformRelease (release , platformPath ); err != nil {
253
- return status .Newf (codes .FailedPrecondition , "loading platform release: %s" , err )
254
-
254
+ return status .Newf (codes .FailedPrecondition , "loading platform release %s: %s" , release , err )
255
255
}
256
256
pm .Log .WithField ("platform" , release ).Infof ("Loaded platform" )
257
257
@@ -279,7 +279,7 @@ func (pm *PackageManager) loadPlatform(targetPackage *cores.Package, platformPat
279
279
}
280
280
release := platform .GetOrCreateRelease (version )
281
281
if err := pm .loadPlatformRelease (release , versionDir ); err != nil {
282
- return status .Newf (codes .FailedPrecondition , "loading platform release: %s" , err )
282
+ return status .Newf (codes .FailedPrecondition , "loading platform release %s : %s" , release , err )
283
283
}
284
284
pm .Log .WithField ("platform" , release ).Infof ("Loaded platform" )
285
285
}
@@ -341,7 +341,7 @@ func (pm *PackageManager) loadPlatformRelease(platform *cores.PlatformRelease, p
341
341
}
342
342
343
343
if err := pm .loadBoards (platform ); err != nil {
344
- return err
344
+ return fmt . Errorf ( "loading boards: %s" , err )
345
345
}
346
346
347
347
return nil
@@ -374,14 +374,47 @@ func (pm *PackageManager) loadBoards(platform *cores.PlatformRelease) error {
374
374
375
375
propertiesByBoard := boardsProperties .FirstLevelOf ()
376
376
377
- platform .Menus = propertiesByBoard ["menu" ]
377
+ if menus , ok := propertiesByBoard ["menu" ]; ok {
378
+ platform .Menus = menus
379
+ } else {
380
+ platform .Menus = properties .NewMap ()
381
+ }
378
382
379
- delete (propertiesByBoard , "menu" ) // TODO: check this one
383
+ // This is not a board id so we remove it to correctly
384
+ // set all other boards properties
385
+ delete (propertiesByBoard , "menu" )
380
386
387
+ skippedBoards := []string {}
381
388
for boardID , boardProperties := range propertiesByBoard {
382
- boardProperties .Set ("_id" , boardID ) // TODO: What is that for??
383
- board := platform .GetOrCreateBoard (boardID )
389
+ var board * cores.Board
390
+ for key := range boardProperties .AsMap () {
391
+ if ! strings .HasPrefix (key , "menu." ) {
392
+ continue
393
+ }
394
+ // Menu keys are formed like this:
395
+ // menu.cache.off=false
396
+ // menu.cache.on=true
397
+ // so we assume that the a second element in the slice exists
398
+ menuName := strings .Split (key , "." )[1 ]
399
+ if ! platform .Menus .ContainsKey (menuName ) {
400
+ fqbn := fmt .Sprintf ("%s:%s:%s" , platform .Platform .Package .Name , platform .Platform .Architecture , boardID )
401
+ skippedBoards = append (skippedBoards , fqbn )
402
+ goto next_board
403
+ }
404
+ }
405
+ // The board's ID must be available in a board's properties since it can
406
+ // be used in all configuration files for several reasons, like setting compilation
407
+ // flags depending on the board id.
408
+ // For more info:
409
+ // https://arduino.github.io/arduino-cli/dev/platform-specification/#global-predefined-properties
410
+ boardProperties .Set ("_id" , boardID )
411
+ board = platform .GetOrCreateBoard (boardID )
384
412
board .Properties .Merge (boardProperties )
413
+ next_board:
414
+ }
415
+
416
+ if len (skippedBoards ) > 0 {
417
+ return fmt .Errorf ("skipping loading of boards %s: malformed custom board options" , strings .Join (skippedBoards , ", " ))
385
418
}
386
419
387
420
return nil
0 commit comments