@@ -323,14 +323,6 @@ func (pm *PackageManager) loadPlatformRelease(platform *cores.PlatformRelease, p
323
323
324
324
if platform .Properties .SubTree ("discovery" ).Size () > 0 {
325
325
platform .PluggableDiscoveryAware = true
326
-
327
- discoveries , err := pm .LoadDiscoveries (platform )
328
- if err != nil {
329
- return fmt .Errorf ("loading discovery properties: %s" , err )
330
- }
331
- for _ , discovery := range discoveries {
332
- pm .discoveryManager .Add (discovery )
333
- }
334
326
}
335
327
336
328
if platform .Platform .Name == "" {
@@ -600,17 +592,25 @@ func (pm *PackageManager) LoadToolsFromBundleDirectory(toolsPath *paths.Path) er
600
592
return nil
601
593
}
602
594
603
- // LoadDiscoveries returns a list of PluggableDiscoveries supported by the specfied PlatformRelease.
595
+ // LoadDiscoveries load all discoveries for all loaded platforms
604
596
// Returns error if:
605
597
// * A PluggableDiscovery instance can't be created
606
598
// * Tools required by the PlatformRelease cannot be found
607
599
// * Command line to start PluggableDiscovery has malformed or mismatched quotes
608
- func (pm * PackageManager ) LoadDiscoveries (release * cores.PlatformRelease ) ([]* discovery.PluggableDiscovery , error ) {
609
- res := []* discovery.PluggableDiscovery {}
600
+ func (pm * PackageManager ) LoadDiscoveries () []* status.Status {
601
+ statuses := []* status.Status {}
602
+ for _ , platform := range pm .InstalledPlatformReleases () {
603
+ statuses = append (statuses , pm .loadDiscoveries (platform )... )
604
+ }
605
+ return statuses
606
+ }
607
+
608
+ func (pm * PackageManager ) loadDiscoveries (release * cores.PlatformRelease ) []* status.Status {
609
+ statuses := []* status.Status {}
610
610
discoveryProperties := release .Properties .SubTree ("discovery" ).Clone ()
611
611
612
612
if discoveryProperties .Size () == 0 {
613
- return res , nil
613
+ return nil
614
614
}
615
615
616
616
// Handles discovery properties formatted like so:
@@ -624,14 +624,19 @@ func (pm *PackageManager) LoadDiscoveries(release *cores.PlatformRelease) ([]*di
624
624
//
625
625
// If both indexed and unindexed properties are found the unindexed are ignored
626
626
for _ , id := range discoveryProperties .ExtractSubIndexLists ("required" ) {
627
- tool := release .Platform .Package .Tools [id ]
627
+ tool := pm .GetTool (id )
628
+ if tool == nil {
629
+ statuses = append (statuses , status .Newf (codes .FailedPrecondition , "discovery not found: %s" , id ))
630
+ continue
631
+ }
628
632
toolRelease := tool .GetLatestInstalled ()
629
633
discoveryPath := toolRelease .InstallDir .Join (tool .Name ).String ()
630
634
d , err := discovery .New (id , discoveryPath )
631
635
if err != nil {
632
- return nil , fmt .Errorf ("creating discovery: %s" , err )
636
+ statuses = append (statuses , status .Newf (codes .FailedPrecondition , "creating discovery: %s" , err ))
637
+ continue
633
638
}
634
- res = append ( res , d )
639
+ pm . discoveryManager . Add ( d )
635
640
}
636
641
637
642
// "discovery.teensy.pattern": "\"{runtime.tools.teensy_ports.path}/hardware/tools/teensy_ports\" -J2",
@@ -647,7 +652,7 @@ func (pm *PackageManager) LoadDiscoveries(release *cores.PlatformRelease) ([]*di
647
652
var err error
648
653
tools , err = pm .FindToolsRequiredFromPlatformRelease (release )
649
654
if err != nil {
650
- return nil , err
655
+ statuses = append ( statuses , status . New ( codes . Internal , err . Error ()))
651
656
}
652
657
}
653
658
@@ -657,7 +662,8 @@ func (pm *PackageManager) LoadDiscoveries(release *cores.PlatformRelease) ([]*di
657
662
for discoveryID , props := range discoveryIDs {
658
663
pattern , ok := props .GetOk ("pattern" )
659
664
if ! ok {
660
- return nil , fmt .Errorf ("can't find pattern for discovery with id %s" , discoveryID )
665
+ statuses = append (statuses , status .Newf (codes .FailedPrecondition , "can't find pattern for discovery with id %s" , discoveryID ))
666
+ continue
661
667
}
662
668
configuration := release .Properties .Clone ()
663
669
configuration .Merge (release .RuntimeProperties ())
@@ -669,13 +675,13 @@ func (pm *PackageManager) LoadDiscoveries(release *cores.PlatformRelease) ([]*di
669
675
670
676
cmd := configuration .ExpandPropsInString (pattern )
671
677
if cmdArgs , err := properties .SplitQuotedString (cmd , `"'` , true ); err != nil {
672
- return nil , err
678
+ statuses = append ( statuses , status . New ( codes . Internal , err . Error ()))
673
679
} else if d , err := discovery .New (discoveryID , cmdArgs ... ); err != nil {
674
- return nil , err
680
+ statuses = append ( statuses , status . New ( codes . Internal , err . Error ()))
675
681
} else {
676
- res = append ( res , d )
682
+ pm . discoveryManager . Add ( d )
677
683
}
678
684
}
679
685
680
- return res , nil
686
+ return statuses
681
687
}
0 commit comments