Commit 0888f0f5 authored by Cristian Maglie's avatar Cristian Maglie

Pick the correct version for packages bundled in the IDE

See #28
parent 88f08c07
...@@ -164,6 +164,7 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir ...@@ -164,6 +164,7 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir
} else if exist { } else if exist {
// case: ARCHITECTURE/boards.txt // case: ARCHITECTURE/boards.txt
// this is the general case for unversioned Platform
version := semver.MustParse("") version := semver.MustParse("")
// FIXME: this check is duplicated, find a better way to handle this // FIXME: this check is duplicated, find a better way to handle this
...@@ -173,6 +174,34 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir ...@@ -173,6 +174,34 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir
continue continue
} }
// check if package_bundled_index.json exists
packageBundledIndexPath := packageDir.Parent().Join("package_index_bundled.json")
if packageBundledIndexPath.Exist() {
// particular case: ARCHITECTURE/boards.txt with package_bundled_index.json
// this is an unversioned Platform with a package_index_bundled.json that
// gives information about the version and tools needed
// Parse the bundled index and merge to the general index
index, err := pm.LoadPackageIndexFromFile(packageBundledIndexPath)
if err != nil {
return fmt.Errorf("parsing IDE bundled index: %s", err)
}
// Now export the bundled index in a temporary core.Packages to retrieve the bundled package version
tmp := cores.NewPackages()
index.MergeIntoPackages(tmp)
if tmpPackage := tmp.GetOrCreatePackage(targetPackage.Name); tmpPackage == nil {
pm.Log.Warnf("Can't determine bundle platform version for %s", targetPackage.Name)
} else if tmpPlatform := tmpPackage.GetOrCreatePlatform(architecure); tmpPlatform == nil {
pm.Log.Warnf("Can't determine bundle platform version for %s:%s", targetPackage.Name, architecure)
} else if tmpPlatformRelease := tmpPlatform.GetLatestRelease(); tmpPlatformRelease == nil {
pm.Log.Warnf("Can't determine bundle platform version for %s:%s, no valid release found", targetPackage.Name, architecure)
} else {
version = tmpPlatformRelease.Version
}
}
platform := targetPackage.GetOrCreatePlatform(architecure) platform := targetPackage.GetOrCreatePlatform(architecure)
release, err := platform.GetOrCreateRelease(version) release, err := platform.GetOrCreateRelease(version)
if err != nil { if err != nil {
......
...@@ -198,14 +198,19 @@ func (pm *PackageManager) ResolveFQBN(fqbn *cores.FQBN) ( ...@@ -198,14 +198,19 @@ func (pm *PackageManager) ResolveFQBN(fqbn *cores.FQBN) (
// LoadPackageIndex loads a package index by looking up the local cached file from the specified URL // LoadPackageIndex loads a package index by looking up the local cached file from the specified URL
func (pm *PackageManager) LoadPackageIndex(URL *url.URL) error { func (pm *PackageManager) LoadPackageIndex(URL *url.URL) error {
indexPath := pm.IndexDir.Join(path.Base(URL.Path)) _, err := pm.LoadPackageIndexFromFile(pm.IndexDir.Join(path.Base(URL.Path)))
return err
}
// LoadPackageIndexFromFile load a package index from the specified file
func (pm *PackageManager) LoadPackageIndexFromFile(indexPath *paths.Path) (*packageindex.Index, error) {
index, err := packageindex.LoadIndex(indexPath) index, err := packageindex.LoadIndex(indexPath)
if err != nil { if err != nil {
return fmt.Errorf("loading json index file %s: %s", indexPath, err) return nil, fmt.Errorf("loading json index file %s: %s", indexPath, err)
} }
index.MergeIntoPackages(pm.packages) index.MergeIntoPackages(pm.packages)
return nil return index, nil
} }
// Package looks for the Package with the given name, returning a structure // Package looks for the Package with the given name, returning a structure
......
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