Unverified Commit c1dcf018 authored by Cristian Maglie's avatar Cristian Maglie Committed by GitHub

Reduce priority for IDE-bundled platform releases (#579)

Fix https://github.com/arduino/Arduino/issues/9724
parent 553b7be3
......@@ -47,6 +47,7 @@ type PlatformRelease struct {
Programmers map[string]*properties.Map `json:"-"`
Menus *properties.Map `json:"-"`
InstallDir *paths.Path `json:"-"`
IsIDEBundled bool `json:"-"`
}
// BoardManifest contains information about a board. These metadata are usually
......
......@@ -179,6 +179,7 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir
}
// check if package_bundled_index.json exists
isIDEBundled := false
packageBundledIndexPath := packageDir.Parent().Join("package_index_bundled.json")
if packageBundledIndexPath.Exist() {
// particular case: ARCHITECTURE/boards.txt with package_bundled_index.json
......@@ -204,6 +205,8 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir
} else {
version = tmpPlatformRelease.Version
}
isIDEBundled = true
}
platform := targetPackage.GetOrCreatePlatform(architecture)
......@@ -211,6 +214,10 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir
if err != nil {
return fmt.Errorf("loading platform release: %s", err)
}
release.IsIDEBundled = isIDEBundled
if isIDEBundled {
pm.Log.Infof("Package is built-in")
}
if err := pm.loadPlatformRelease(release, platformPath); err != nil {
return fmt.Errorf("loading platform release: %s", err)
}
......
......@@ -323,16 +323,34 @@ func (tr *ToolReleaseActions) Get() (*cores.ToolRelease, error) {
// GetInstalledPlatformRelease returns the PlatformRelease installed (it is chosen)
func (pm *PackageManager) GetInstalledPlatformRelease(platform *cores.Platform) *cores.PlatformRelease {
pm.Log.Infof("Selecting installed platform release for %s", platform)
releases := platform.GetAllInstalled()
if len(releases) == 0 {
return nil
}
log := func(msg string, pl *cores.PlatformRelease) {
pm.Log.WithField("bundle", pl.IsIDEBundled).
WithField("version", pl.Version).
WithField("managed", pm.IsManagedPlatformRelease(pl)).
Infof("%s: %s", msg, pl)
}
best := releases[0]
bestIsManaged := pm.IsManagedPlatformRelease(best)
log("current best", best)
for _, candidate := range releases[1:] {
candidateIsManaged := pm.IsManagedPlatformRelease(candidate)
log("candidate", candidate)
// TODO: Disentangle this algorithm and make it more straightforward
if bestIsManaged == candidateIsManaged {
if candidate.Version.GreaterThan(best.Version) {
if best.IsIDEBundled == candidate.IsIDEBundled {
if candidate.Version.GreaterThan(best.Version) {
best = candidate
}
}
if best.IsIDEBundled && !candidate.IsIDEBundled {
best = candidate
}
}
......@@ -340,6 +358,7 @@ func (pm *PackageManager) GetInstalledPlatformRelease(platform *cores.Platform)
best = candidate
bestIsManaged = true
}
log("current best", best)
}
return best
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment