Skip to content

Commit eb405e3

Browse files
committed
Pick the correct version for packages bundled in the IDE
See #28
1 parent 969142f commit eb405e3

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

arduino/cores/packagemanager/loader.go

+29
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir
164164
} else if exist {
165165

166166
// case: ARCHITECTURE/boards.txt
167+
// this is the general case for unversioned Platform
167168
version := semver.MustParse("")
168169

169170
// FIXME: this check is duplicated, find a better way to handle this
@@ -173,6 +174,34 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir
173174
continue
174175
}
175176

177+
// check if package_bundled_index.json exists
178+
packageBundledIndexPath := packageDir.Parent().Join("package_index_bundled.json")
179+
if packageBundledIndexPath.Exist() {
180+
// particular case: ARCHITECTURE/boards.txt with package_bundled_index.json
181+
182+
// this is an unversioned Platform with a package_index_bundled.json that
183+
// gives information about the version and tools needed
184+
185+
// Parse the bundled index and merge to the general index
186+
index, err := pm.LoadPackageIndexFromFile(packageBundledIndexPath)
187+
if err != nil {
188+
return fmt.Errorf("parsing IDE bundled index: %s", err)
189+
}
190+
191+
// Now export the bundled index in a temporary core.Packages to retrieve the bundled package version
192+
tmp := cores.NewPackages()
193+
index.MergeIntoPackages(tmp)
194+
if tmpPackage := tmp.GetOrCreatePackage(targetPackage.Name); tmpPackage == nil {
195+
pm.Log.Warnf("Can't determine bundle platform version for %s", targetPackage.Name)
196+
} else if tmpPlatform := tmpPackage.GetOrCreatePlatform(architecure); tmpPlatform == nil {
197+
pm.Log.Warnf("Can't determine bundle platform version for %s:%s", targetPackage.Name, architecure)
198+
} else if tmpPlatformRelease := tmpPlatform.GetLatestRelease(); tmpPlatformRelease == nil {
199+
pm.Log.Warnf("Can't determine bundle platform version for %s:%s, no valid release found", targetPackage.Name, architecure)
200+
} else {
201+
version = tmpPlatformRelease.Version
202+
}
203+
}
204+
176205
platform := targetPackage.GetOrCreatePlatform(architecure)
177206
release, err := platform.GetOrCreateRelease(version)
178207
if err != nil {

arduino/cores/packagemanager/package_manager.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,19 @@ func (pm *PackageManager) ResolveFQBN(fqbn *cores.FQBN) (
198198

199199
// LoadPackageIndex loads a package index by looking up the local cached file from the specified URL
200200
func (pm *PackageManager) LoadPackageIndex(URL *url.URL) error {
201-
indexPath := pm.IndexDir.Join(path.Base(URL.Path))
201+
_, err := pm.LoadPackageIndexFromFile(pm.IndexDir.Join(path.Base(URL.Path)))
202+
return err
203+
}
204+
205+
// LoadPackageIndexFromFile load a package index from the specified file
206+
func (pm *PackageManager) LoadPackageIndexFromFile(indexPath *paths.Path) (*packageindex.Index, error) {
202207
index, err := packageindex.LoadIndex(indexPath)
203208
if err != nil {
204-
return fmt.Errorf("loading json index file %s: %s", indexPath, err)
209+
return nil, fmt.Errorf("loading json index file %s: %s", indexPath, err)
205210
}
206211

207212
index.MergeIntoPackages(pm.packages)
208-
return nil
213+
return index, nil
209214
}
210215

211216
// Package looks for the Package with the given name, returning a structure

0 commit comments

Comments
 (0)