Skip to content

Commit

Permalink
compute the incompatible version at commit time
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Sep 21, 2023
1 parent 02060b2 commit 18af151
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 34 deletions.
34 changes: 0 additions & 34 deletions arduino/cores/packageindex/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,40 +147,6 @@ func (index Index) MergeIntoPackages(outPackages cores.Packages) {
for _, inPackage := range index.Packages {
inPackage.extractPackageIn(outPackages, index.IsTrusted, index.isInstalledJSON)
}

// calculates Incompatible PlatformRelease
for _, op := range outPackages {
for _, p := range op.Platforms {
for _, pr := range p.Releases {
platformHasIncompatibleTools := func() bool {
for _, td := range pr.ToolDependencies {
if td == nil {
return true
}

_, ok := outPackages[td.ToolPackager]
if !ok {
return true
}
tool := outPackages[td.ToolPackager].Tools[td.ToolName]
if tool == nil {
return true
}
tr := tool.Releases[td.ToolVersion.NormalizedString()]
if tr == nil {
return true
}

if tr.GetCompatibleFlavour() == nil {
return true
}
}
return false
}
pr.Incompatible = platformHasIncompatibleTools()
}
}
}
}

// IndexFromPlatformRelease creates an Index that contains a single indexPackage
Expand Down
37 changes: 37 additions & 0 deletions arduino/cores/packagemanager/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,50 @@ func (pmb *Builder) Build() *PackageManager {
}
}

func (pmb *Builder) calculateIncompatibleVersions() {
// calculates Incompatible PlatformRelease
for _, op := range pmb.packages {
for _, p := range op.Platforms {
for _, pr := range p.Releases {
platformHasIncompatibleTools := func() bool {
for _, td := range pr.ToolDependencies {
if td == nil {
return true
}

_, ok := pmb.packages[td.ToolPackager]
if !ok {
return true
}
tool := pmb.packages[td.ToolPackager].Tools[td.ToolName]
if tool == nil {
return true
}
tr := tool.Releases[td.ToolVersion.NormalizedString()]
if tr == nil {
return true
}

if tr.GetCompatibleFlavour() == nil {
return true
}
}
return false
}
pr.Incompatible = platformHasIncompatibleTools()
}
}
}
}

// NewBuilder creates a Builder with the same configuration
// of this PackageManager. A "commit" function callback is returned: calling
// this function will make the builder write the new configuration into this
// PackageManager.
func (pm *PackageManager) NewBuilder() (builder *Builder, commit func()) {
pmb := NewBuilder(pm.IndexDir, pm.PackagesDir, pm.DownloadDir, pm.tempDir, pm.userAgent)
return pmb, func() {
pmb.calculateIncompatibleVersions()
pmb.BuildIntoExistingPackageManager(pm)
}
}
Expand Down

0 comments on commit 18af151

Please sign in to comment.