Skip to content

Commit c1dcf01

Browse files
authored
Reduce priority for IDE-bundled platform releases (arduino#579)
Fix arduino/Arduino#9724
1 parent 553b7be commit c1dcf01

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

arduino/cores/cores.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type PlatformRelease struct {
4747
Programmers map[string]*properties.Map `json:"-"`
4848
Menus *properties.Map `json:"-"`
4949
InstallDir *paths.Path `json:"-"`
50+
IsIDEBundled bool `json:"-"`
5051
}
5152

5253
// BoardManifest contains information about a board. These metadata are usually

arduino/cores/packagemanager/loader.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir
179179
}
180180

181181
// check if package_bundled_index.json exists
182+
isIDEBundled := false
182183
packageBundledIndexPath := packageDir.Parent().Join("package_index_bundled.json")
183184
if packageBundledIndexPath.Exist() {
184185
// particular case: ARCHITECTURE/boards.txt with package_bundled_index.json
@@ -204,13 +205,19 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir
204205
} else {
205206
version = tmpPlatformRelease.Version
206207
}
208+
209+
isIDEBundled = true
207210
}
208211

209212
platform := targetPackage.GetOrCreatePlatform(architecture)
210213
release, err := platform.GetOrCreateRelease(version)
211214
if err != nil {
212215
return fmt.Errorf("loading platform release: %s", err)
213216
}
217+
release.IsIDEBundled = isIDEBundled
218+
if isIDEBundled {
219+
pm.Log.Infof("Package is built-in")
220+
}
214221
if err := pm.loadPlatformRelease(release, platformPath); err != nil {
215222
return fmt.Errorf("loading platform release: %s", err)
216223
}

arduino/cores/packagemanager/package_manager.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,23 +323,42 @@ func (tr *ToolReleaseActions) Get() (*cores.ToolRelease, error) {
323323

324324
// GetInstalledPlatformRelease returns the PlatformRelease installed (it is chosen)
325325
func (pm *PackageManager) GetInstalledPlatformRelease(platform *cores.Platform) *cores.PlatformRelease {
326+
pm.Log.Infof("Selecting installed platform release for %s", platform)
326327
releases := platform.GetAllInstalled()
327328
if len(releases) == 0 {
328329
return nil
329330
}
331+
332+
log := func(msg string, pl *cores.PlatformRelease) {
333+
pm.Log.WithField("bundle", pl.IsIDEBundled).
334+
WithField("version", pl.Version).
335+
WithField("managed", pm.IsManagedPlatformRelease(pl)).
336+
Infof("%s: %s", msg, pl)
337+
}
338+
330339
best := releases[0]
331340
bestIsManaged := pm.IsManagedPlatformRelease(best)
341+
log("current best", best)
342+
332343
for _, candidate := range releases[1:] {
333344
candidateIsManaged := pm.IsManagedPlatformRelease(candidate)
345+
log("candidate", candidate)
346+
// TODO: Disentangle this algorithm and make it more straightforward
334347
if bestIsManaged == candidateIsManaged {
335-
if candidate.Version.GreaterThan(best.Version) {
348+
if best.IsIDEBundled == candidate.IsIDEBundled {
349+
if candidate.Version.GreaterThan(best.Version) {
350+
best = candidate
351+
}
352+
}
353+
if best.IsIDEBundled && !candidate.IsIDEBundled {
336354
best = candidate
337355
}
338356
}
339357
if !bestIsManaged && candidateIsManaged {
340358
best = candidate
341359
bestIsManaged = true
342360
}
361+
log("current best", best)
343362
}
344363
return best
345364
}

0 commit comments

Comments
 (0)
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