Skip to content

Reduce priority for IDE-bundled platform releases #579

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 1 commit into from
Feb 12, 2020
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
1 change: 1 addition & 0 deletions arduino/cores/cores.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions arduino/cores/packagemanager/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -204,13 +205,19 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir
} else {
version = tmpPlatformRelease.Version
}

isIDEBundled = true
}

platform := targetPackage.GetOrCreatePlatform(architecture)
release, err := platform.GetOrCreateRelease(version)
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)
}
Expand Down
21 changes: 20 additions & 1 deletion arduino/cores/packagemanager/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,23 +323,42 @@ 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
}
}
if !bestIsManaged && candidateIsManaged {
best = candidate
bestIsManaged = true
}
log("current best", best)
}
return best
}
Expand Down