Skip to content

Commit 0ce967d

Browse files
committed
Fix builtin discoveries not loaded if no platform is installed
1 parent 22ac0f3 commit 0ce967d

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

arduino/cores/packagemanager/loader.go

+35-16
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,39 @@ func (pm *PackageManager) LoadDiscoveries() []*status.Status {
683683
for _, platform := range pm.InstalledPlatformReleases() {
684684
statuses = append(statuses, pm.loadDiscoveries(platform)...)
685685
}
686+
if st := pm.loadBuiltinDiscoveries(); len(st) > 0 {
687+
statuses = append(statuses, st...)
688+
}
689+
return statuses
690+
}
691+
692+
// loadDiscovery loads the discovery tool with id, if it cannot be found a non-nil status is returned
693+
func (pm *PackageManager) loadDiscovery(id string) *status.Status {
694+
tool := pm.GetTool(id)
695+
if tool == nil {
696+
return status.Newf(codes.FailedPrecondition, tr("discovery not found: %s"), id)
697+
}
698+
toolRelease := tool.GetLatestInstalled()
699+
if toolRelease == nil {
700+
return status.Newf(codes.FailedPrecondition, tr("discovery not installed: %s"), id)
701+
}
702+
discoveryPath := toolRelease.InstallDir.Join(tool.Name).String()
703+
d, err := discovery.New(id, discoveryPath)
704+
if err != nil {
705+
return status.Newf(codes.FailedPrecondition, tr("creating discovery: %s"), err)
706+
}
707+
pm.discoveryManager.Add(d)
708+
return nil
709+
}
710+
711+
// loadBuiltinDiscoveries loads the discovery tools that are part of the builtin package
712+
func (pm *PackageManager) loadBuiltinDiscoveries() []*status.Status {
713+
statuses := []*status.Status{}
714+
for _, id := range []string{"builtin:serial-discovery", "builtin:mdns-discovery"} {
715+
if st := pm.loadDiscovery(id); st != nil {
716+
statuses = append(statuses, st)
717+
}
718+
}
686719
return statuses
687720
}
688721

@@ -705,23 +738,9 @@ func (pm *PackageManager) loadDiscoveries(release *cores.PlatformRelease) []*sta
705738
//
706739
// If both indexed and unindexed properties are found the unindexed are ignored
707740
for _, id := range discoveryProperties.ExtractSubIndexLists("required") {
708-
tool := pm.GetTool(id)
709-
if tool == nil {
710-
statuses = append(statuses, status.Newf(codes.FailedPrecondition, tr("discovery not found: %s"), id))
711-
continue
712-
}
713-
toolRelease := tool.GetLatestInstalled()
714-
if toolRelease == nil {
715-
statuses = append(statuses, status.Newf(codes.FailedPrecondition, tr("discovery not installed: %s"), id))
716-
continue
717-
}
718-
discoveryPath := toolRelease.InstallDir.Join(tool.Name).String()
719-
d, err := discovery.New(id, discoveryPath)
720-
if err != nil {
721-
statuses = append(statuses, status.Newf(codes.FailedPrecondition, tr("creating discovery: %s"), err))
722-
continue
741+
if st := pm.loadDiscovery(id); st != nil {
742+
statuses = append(statuses, st)
723743
}
724-
pm.discoveryManager.Add(d)
725744
}
726745

727746
discoveryIDs := discoveryProperties.FirstLevelOf()

0 commit comments

Comments
 (0)