@@ -323,14 +323,6 @@ func (pm *PackageManager) loadPlatformRelease(platform *cores.PlatformRelease, p
323323
324324 if platform .Properties .SubTree ("discovery" ).Size () > 0 {
325325 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- }
334326 }
335327
336328 if platform .Platform .Name == "" {
@@ -600,17 +592,25 @@ func (pm *PackageManager) LoadToolsFromBundleDirectory(toolsPath *paths.Path) er
600592 return nil
601593}
602594
603- // LoadDiscoveries returns a list of PluggableDiscoveries supported by the specfied PlatformRelease.
595+ // LoadDiscoveries load all discoveries for all loaded platforms
604596// Returns error if:
605597// * A PluggableDiscovery instance can't be created
606598// * Tools required by the PlatformRelease cannot be found
607599// * 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 {}
610610 discoveryProperties := release .Properties .SubTree ("discovery" ).Clone ()
611611
612612 if discoveryProperties .Size () == 0 {
613- return res , nil
613+ return nil
614614 }
615615
616616 // Handles discovery properties formatted like so:
@@ -624,14 +624,19 @@ func (pm *PackageManager) LoadDiscoveries(release *cores.PlatformRelease) ([]*di
624624 //
625625 // If both indexed and unindexed properties are found the unindexed are ignored
626626 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+ }
628632 toolRelease := tool .GetLatestInstalled ()
629633 discoveryPath := toolRelease .InstallDir .Join (tool .Name ).String ()
630634 d , err := discovery .New (id , discoveryPath )
631635 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
633638 }
634- res = append ( res , d )
639+ pm . discoveryManager . Add ( d )
635640 }
636641
637642 // "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
647652 var err error
648653 tools , err = pm .FindToolsRequiredFromPlatformRelease (release )
649654 if err != nil {
650- return nil , err
655+ statuses = append ( statuses , status . New ( codes . Internal , err . Error ()))
651656 }
652657 }
653658
@@ -657,7 +662,8 @@ func (pm *PackageManager) LoadDiscoveries(release *cores.PlatformRelease) ([]*di
657662 for discoveryID , props := range discoveryIDs {
658663 pattern , ok := props .GetOk ("pattern" )
659664 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
661667 }
662668 configuration := release .Properties .Clone ()
663669 configuration .Merge (release .RuntimeProperties ())
@@ -669,13 +675,13 @@ func (pm *PackageManager) LoadDiscoveries(release *cores.PlatformRelease) ([]*di
669675
670676 cmd := configuration .ExpandPropsInString (pattern )
671677 if cmdArgs , err := properties .SplitQuotedString (cmd , `"'` , true ); err != nil {
672- return nil , err
678+ statuses = append ( statuses , status . New ( codes . Internal , err . Error ()))
673679 } else if d , err := discovery .New (discoveryID , cmdArgs ... ); err != nil {
674- return nil , err
680+ statuses = append ( statuses , status . New ( codes . Internal , err . Error ()))
675681 } else {
676- res = append ( res , d )
682+ pm . discoveryManager . Add ( d )
677683 }
678684 }
679685
680- return res , nil
686+ return statuses
681687}
0 commit comments