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 1 commit
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
Prev Previous commit
Next Next commit
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.
  • Loading branch information
cmaglie committed Aug 23, 2022
commit 46eeee2dff339dd1021b4dcb6a8ac3b5734c156e
41 changes: 23 additions & 18 deletions arduino/cores/packagemanager/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,27 @@ type PackageManager struct {
// Builder is used to create a new PackageManager. The builder
// has methods to load patforms and tools to actually build the PackageManager.
// Once the PackageManager is built, it cannot be changed anymore.
type Builder struct {
*PackageManager
}
type Builder PackageManager

// Explorer is used to query the PackageManager. When used it holds
// a read-only lock on the PackageManager that must be released when the
// job is completed.
type Explorer struct {
*PackageManager
}
type Explorer PackageManager

var tr = i18n.Tr

// NewBuilder returns a new Builder
func NewBuilder(indexDir, packagesDir, downloadDir, tempDir *paths.Path, userAgent string) *Builder {
return &Builder{
PackageManager: &PackageManager{
log: logrus.StandardLogger(),
packages: cores.NewPackages(),
IndexDir: indexDir,
PackagesDir: packagesDir,
DownloadDir: downloadDir,
tempDir: tempDir,
packagesCustomGlobalProperties: properties.NewMap(),
discoveryManager: discoverymanager.New(),
userAgent: userAgent,
},
log: logrus.StandardLogger(),
packages: cores.NewPackages(),
IndexDir: indexDir,
PackagesDir: packagesDir,
DownloadDir: downloadDir,
tempDir: tempDir,
packagesCustomGlobalProperties: properties.NewMap(),
discoveryManager: discoverymanager.New(),
userAgent: userAgent,
}
}

Expand Down Expand Up @@ -128,7 +122,18 @@ func (pm *PackageManager) NewBuilder() (builder *Builder, commit func()) {
// to correctly dispose it.
func (pm *PackageManager) NewExplorer() (explorer *Explorer, release func()) {
pm.packagesLock.RLock()
return &Explorer{pm}, pm.packagesLock.RUnlock
return &Explorer{
log: pm.log,
packages: pm.packages,
IndexDir: pm.IndexDir,
PackagesDir: pm.PackagesDir,
DownloadDir: pm.DownloadDir,
tempDir: pm.tempDir,
packagesCustomGlobalProperties: pm.packagesCustomGlobalProperties,
profile: pm.profile,
discoveryManager: pm.discoveryManager,
userAgent: pm.userAgent,
}, pm.packagesLock.RUnlock
}

// GetProfile returns the active profile for this package manager, or nil if no profile is selected.
Expand Down
8 changes: 2 additions & 6 deletions legacy/builder/builder_utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@ func compileFileWithRecipe(ctx *types.Context, sourcePath *paths.Path, source *p
return nil, errors.WithStack(err)
}

pme, release := ctx.PackageManager.NewExplorer()
command, err := PrepareCommandForRecipe(properties, recipe, false, pme.GetEnvVarsForSpawnedProcess())
release()
command, err := PrepareCommandForRecipe(properties, recipe, false, ctx.PackageManager.GetEnvVarsForSpawnedProcess())
if err != nil {
return nil, errors.WithStack(err)
}
Expand Down Expand Up @@ -413,9 +411,7 @@ func ArchiveCompiledFiles(ctx *types.Context, buildPath *paths.Path, archiveFile
properties.SetPath(constants.BUILD_PROPERTIES_ARCHIVE_FILE_PATH, archiveFilePath)
properties.SetPath(constants.BUILD_PROPERTIES_OBJECT_FILE, objectFile)

pme, release := ctx.PackageManager.NewExplorer()
command, err := PrepareCommandForRecipe(properties, constants.RECIPE_AR_PATTERN, false, pme.GetEnvVarsForSpawnedProcess())
release()
command, err := PrepareCommandForRecipe(properties, constants.RECIPE_AR_PATTERN, false, ctx.PackageManager.GetEnvVarsForSpawnedProcess())
if err != nil {
return nil, errors.WithStack(err)
}
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy