Skip to content

[breaking] daemon: Fix concurrency and streamline access to PackageManager #1828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions arduino/cores/packagemanager/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func (platform *PlatformReference) String() string {

// FindPlatform returns the Platform matching the PlatformReference or nil if not found.
// The PlatformVersion field of the reference is ignored.
func (pm *PackageManager) FindPlatform(ref *PlatformReference) *cores.Platform {
targetPackage, ok := pm.Packages[ref.Package]
func (pme *Explorer) FindPlatform(ref *PlatformReference) *cores.Platform {
targetPackage, ok := pme.packages[ref.Package]
if !ok {
return nil
}
Expand All @@ -56,8 +56,8 @@ func (pm *PackageManager) FindPlatform(ref *PlatformReference) *cores.Platform {
}

// FindPlatformRelease returns the PlatformRelease matching the PlatformReference or nil if not found
func (pm *PackageManager) FindPlatformRelease(ref *PlatformReference) *cores.PlatformRelease {
platform := pm.FindPlatform(ref)
func (pme *Explorer) FindPlatformRelease(ref *PlatformReference) *cores.PlatformRelease {
platform := pme.FindPlatform(ref)
if platform == nil {
return nil
}
Expand All @@ -70,8 +70,8 @@ func (pm *PackageManager) FindPlatformRelease(ref *PlatformReference) *cores.Pla

// FindPlatformReleaseDependencies takes a PlatformReference and returns a set of items to download and
// a set of outputs for non existing platforms.
func (pm *PackageManager) FindPlatformReleaseDependencies(item *PlatformReference) (*cores.PlatformRelease, []*cores.ToolRelease, error) {
targetPackage, exists := pm.Packages[item.Package]
func (pme *Explorer) FindPlatformReleaseDependencies(item *PlatformReference) (*cores.PlatformRelease, []*cores.ToolRelease, error) {
targetPackage, exists := pme.packages[item.Package]
if !exists {
return nil, nil, fmt.Errorf(tr("package %s not found"), item.Package)
}
Expand All @@ -94,22 +94,22 @@ func (pm *PackageManager) FindPlatformReleaseDependencies(item *PlatformReferenc
}

// replaces "latest" with latest version too
toolDeps, err := pm.Packages.GetPlatformReleaseToolDependencies(release)
toolDeps, err := pme.packages.GetPlatformReleaseToolDependencies(release)
if err != nil {
return nil, nil, fmt.Errorf(tr("getting tool dependencies for platform %[1]s: %[2]s"), release.String(), err)
}

// discovery dependencies differ from normal tool since we always want to use the latest
// available version for the platform package
discoveryDependencies, err := pm.Packages.GetPlatformReleaseDiscoveryDependencies(release)
discoveryDependencies, err := pme.packages.GetPlatformReleaseDiscoveryDependencies(release)
if err != nil {
return nil, nil, fmt.Errorf(tr("getting discovery dependencies for platform %[1]s: %[2]s"), release.String(), err)
}
toolDeps = append(toolDeps, discoveryDependencies...)

// monitor dependencies differ from normal tool since we always want to use the latest
// available version for the platform package
monitorDependencies, err := pm.Packages.GetPlatformReleaseMonitorDependencies(release)
monitorDependencies, err := pme.packages.GetPlatformReleaseMonitorDependencies(release)
if err != nil {
return nil, nil, fmt.Errorf(tr("getting monitor dependencies for platform %[1]s: %[2]s"), release.String(), err)
}
Expand All @@ -120,14 +120,14 @@ func (pm *PackageManager) FindPlatformReleaseDependencies(item *PlatformReferenc

// DownloadToolRelease downloads a ToolRelease. If the tool is already downloaded a nil Downloader
// is returned. Uses the given downloader configuration for download, or the default config if nil.
func (pm *PackageManager) DownloadToolRelease(tool *cores.ToolRelease, config *downloader.Config, progressCB rpc.DownloadProgressCB) error {
func (pme *Explorer) DownloadToolRelease(tool *cores.ToolRelease, config *downloader.Config, progressCB rpc.DownloadProgressCB) error {
resource := tool.GetCompatibleFlavour()
if resource == nil {
return &arduino.FailedDownloadError{
Message: tr("Error downloading tool %s", tool),
Cause: errors.New(tr("no versions available for the current OS"))}
}
if err := resource.Download(pm.DownloadDir, config, tool.String(), progressCB); err != nil {
if err := resource.Download(pme.DownloadDir, config, tool.String(), progressCB); err != nil {
return &arduino.FailedDownloadError{
Message: tr("Error downloading tool %s", tool),
Cause: err}
Expand All @@ -137,9 +137,9 @@ func (pm *PackageManager) DownloadToolRelease(tool *cores.ToolRelease, config *d

// DownloadPlatformRelease downloads a PlatformRelease. If the platform is already downloaded a
// nil Downloader is returned.
func (pm *PackageManager) DownloadPlatformRelease(platform *cores.PlatformRelease, config *downloader.Config, progressCB rpc.DownloadProgressCB) error {
func (pme *Explorer) DownloadPlatformRelease(platform *cores.PlatformRelease, config *downloader.Config, progressCB rpc.DownloadProgressCB) error {
if platform.Resource == nil {
return &arduino.PlatformNotFoundError{Platform: platform.String()}
}
return platform.Resource.Download(pm.DownloadDir, config, platform.String(), progressCB)
return platform.Resource.Download(pme.DownloadDir, config, platform.String(), progressCB)
}
4 changes: 2 additions & 2 deletions arduino/cores/packagemanager/identify.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import (

// IdentifyBoard returns a list of boards whose identification properties match the
// provided ones.
func (pm *PackageManager) IdentifyBoard(idProps *properties.Map) []*cores.Board {
func (pme *Explorer) IdentifyBoard(idProps *properties.Map) []*cores.Board {
if idProps.Size() == 0 {
return []*cores.Board{}
}
foundBoards := []*cores.Board{}
for _, board := range pm.InstalledBoards() {
for _, board := range pme.InstalledBoards() {
if board.IsBoardMatchingIDProperties(idProps) {
foundBoards = append(foundBoards, board)
}
Expand Down
Loading