Skip to content

Commit 276b0cc

Browse files
cmaglieper1234
andauthored
[breaking] daemon: Fix concurrency and streamline access to PackageManager (#1828)
* legacy: Removed ToolsLoader step It has been splitted and merged into HardwareLoader and TargetBoardResolver that are more appropriate. * Fixed some function comments * Thread-safe protect access to instances map * Removed state-altering methods from PackageManager They have been moved into a Builder object that has the ability to build a new PackageManager. This allows to clearly separate subrotuines that actually change the status of the PackageManager from subroutines that just need to query it. * Created packagemanager.Explorer to query PackageManager data The Explorer object can be see as a read-only "view" to the underlying PackageManager: we may ask the PackageManager to create an Explorer on itself. The returned explorer will held a read-lock on the PackageManager until it's disposed. This architecture should prevent unwanted changes on the PackageManager while it's being used, and viceversa, when the PackageManager is updated it should be guaranteed that no Explorers are reading it. * PlatformInstall/Uninstall must release PackageManager.Explorer before calling commands.Init Otherwise, since Init will try to take a write-lock, it will block indefinitely. * Moved commands.InstanceContainer -> rpc.InstanceCommand * Created a coreInstancesContainer This container will handle all the atomic access to the instances map. * Made CoreInstance.PackageManager field private * Moved the reminder of PackageManager functions to Explorer or Builder * Now GetPackageManager accepts an rpc.InstanceCommand It has also been deprecated in favor of GetPackageManagerExplorer. * Now GetLibraryManager accepts an rpc.InstanceCommand * Refactored automatic builtin-tool installation * Added gRPC LibraryUpgrade call and fixed 'lib upgrade' command * Explorer and Builder should not extend PackageManager Previuosly the methods PackageManager.NewBuilder and PackageManager.NewExplorer were available also on Builder and Explorer. Now Builder and Explorer does not inherith these methods anymore, avoiding trivial errors like the one fixed in this commit in the builder_utils package. * Updated documentation * Apply suggestions from code review Co-authored-by: per1234 <[email protected]>
1 parent 9c334ed commit 276b0cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2129
-1356
lines changed

Diff for: arduino/cores/packagemanager/download.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ func (platform *PlatformReference) String() string {
4343

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

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

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

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

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

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

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

138138
// DownloadPlatformRelease downloads a PlatformRelease. If the platform is already downloaded a
139139
// nil Downloader is returned.
140-
func (pm *PackageManager) DownloadPlatformRelease(platform *cores.PlatformRelease, config *downloader.Config, progressCB rpc.DownloadProgressCB) error {
140+
func (pme *Explorer) DownloadPlatformRelease(platform *cores.PlatformRelease, config *downloader.Config, progressCB rpc.DownloadProgressCB) error {
141141
if platform.Resource == nil {
142142
return &arduino.PlatformNotFoundError{Platform: platform.String()}
143143
}
144-
return platform.Resource.Download(pm.DownloadDir, config, platform.String(), progressCB)
144+
return platform.Resource.Download(pme.DownloadDir, config, platform.String(), progressCB)
145145
}

Diff for: arduino/cores/packagemanager/identify.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ import (
2222

2323
// IdentifyBoard returns a list of boards whose identification properties match the
2424
// provided ones.
25-
func (pm *PackageManager) IdentifyBoard(idProps *properties.Map) []*cores.Board {
25+
func (pme *Explorer) IdentifyBoard(idProps *properties.Map) []*cores.Board {
2626
if idProps.Size() == 0 {
2727
return []*cores.Board{}
2828
}
2929
foundBoards := []*cores.Board{}
30-
for _, board := range pm.InstalledBoards() {
30+
for _, board := range pme.InstalledBoards() {
3131
if board.IsBoardMatchingIDProperties(idProps) {
3232
foundBoards = append(foundBoards, board)
3333
}

0 commit comments

Comments
 (0)