Skip to content

Fix core upgrade #291

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 7 commits into from
Jul 19, 2019
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
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ tasks:
test-legacy:
desc: Run tests for the `legacy` package
cmds:
- go test {{ default "-v" .GOFLAGS }} ./legacy/...
- go test {{ default "-v -failfast" .GOFLAGS }} ./legacy/...

test-unit-race:
desc: Run unit tests only with race condition detection
Expand Down
38 changes: 30 additions & 8 deletions arduino/cores/cores.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package cores

import (
"encoding/json"
"strings"

paths "github.com/arduino/go-paths-helper"
Expand All @@ -41,14 +42,13 @@ type PlatformRelease struct {
Resource *resources.DownloadResource
Version *semver.Version
BoardsManifest []*BoardManifest
Dependencies ToolDependencies // The Dependency entries to load tools.
Platform *Platform `json:"-"`

Properties *properties.Map `json:"-"`
Boards map[string]*Board `json:"-"`
Programmers map[string]*properties.Map `json:"-"`
Menus *properties.Map `json:"-"`
InstallDir *paths.Path `json:"-"`
Dependencies ToolDependencies // The Dependency entries to load tools.
Platform *Platform `json:"-"`
Properties *properties.Map `json:"-"`
Boards map[string]*Board `json:"-"`
Programmers map[string]*properties.Map `json:"-"`
Menus *properties.Map `json:"-"`
InstallDir *paths.Path `json:"-"`
}

// BoardManifest contains information about a board. These metadata are usually
Expand Down Expand Up @@ -226,3 +226,25 @@ func (release *PlatformRelease) String() string {
}
return release.Platform.String() + "@" + version
}

// MarshalJSON provides a more user friendly serialization for
// PlatformRelease objects.
func (release *PlatformRelease) MarshalJSON() ([]byte, error) {
latestStr := ""
latest := release.Platform.GetLatestRelease()
if latest != nil {
latestStr = latest.Version.String()
}

return json.Marshal(&struct {
ID string `json:"ID,omitempty"`
Installed string `json:"Installed,omitempty"`
Latest string `json:"Latest,omitempty"`
Name string `json:"Name,omitempty"`
}{
ID: release.Platform.String(),
Installed: release.Version.String(),
Latest: latestStr,
Name: release.Platform.Name,
})
}
6 changes: 3 additions & 3 deletions arduino/cores/packageindex/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/resources"
"github.com/arduino/go-paths-helper"
"go.bug.st/relaxed-semver"
semver "go.bug.st/relaxed-semver"
)

// Index represents Cores and Tools struct as seen from package_index.json file.
Expand Down Expand Up @@ -97,13 +97,13 @@ type indexHelp struct {

// MergeIntoPackages converts the Index data into a cores.Packages and merge them
// with the existing conents of the cores.Packages passed as parameter.
func (index Index) MergeIntoPackages(outPackages *cores.Packages) {
func (index Index) MergeIntoPackages(outPackages cores.Packages) {
for _, inPackage := range index.Packages {
inPackage.extractPackageIn(outPackages)
}
}

func (inPackage indexPackage) extractPackageIn(outPackages *cores.Packages) {
func (inPackage indexPackage) extractPackageIn(outPackages cores.Packages) {
outPackage := outPackages.GetOrCreatePackage(inPackage.Name)
outPackage.Maintainer = inPackage.Maintainer
outPackage.WebsiteURL = inPackage.WebsiteURL
Expand Down
8 changes: 4 additions & 4 deletions arduino/cores/packagemanager/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

"github.com/arduino/arduino-cli/arduino/cores"
"go.bug.st/downloader"
"go.bug.st/relaxed-semver"
semver "go.bug.st/relaxed-semver"
)

// PlatformReference represents a tuple to identify a Platform
Expand All @@ -44,7 +44,7 @@ func (platform *PlatformReference) String() string {
// FindPlatform returns the Platform matching the PlatformReference or nil if not found.
// The PlatformVersion field of the reference is ignored.
func (pm *PackageManager) FindPlatform(ref *PlatformReference) *cores.Platform {
targetPackage, ok := pm.GetPackages().Packages[ref.Package]
targetPackage, ok := pm.Packages[ref.Package]
if !ok {
return nil
}
Expand All @@ -71,7 +71,7 @@ func (pm *PackageManager) FindPlatformRelease(ref *PlatformReference) *cores.Pla
// FindPlatformReleaseDependencies takes a PlatformReference and returns a set of items to download and
// a set of outputs for non existing platforms.
func (pm *PackageManager) FindPlatformReleaseDependencies(item *PlatformReference) (*cores.PlatformRelease, []*cores.ToolRelease, error) {
targetPackage, exists := pm.packages.Packages[item.Package]
targetPackage, exists := pm.Packages[item.Package]
if !exists {
return nil, nil, fmt.Errorf("package %s not found", item.Package)
}
Expand All @@ -94,7 +94,7 @@ func (pm *PackageManager) FindPlatformReleaseDependencies(item *PlatformReferenc
}

// replaces "latest" with latest version too
toolDeps, err := pm.packages.GetDepsOfPlatformRelease(release)
toolDeps, err := pm.Packages.GetDepsOfPlatformRelease(release)
if err != nil {
return nil, nil, fmt.Errorf("getting tool dependencies for platform %s: %s", release.String(), err)
}
Expand Down
2 changes: 1 addition & 1 deletion arduino/cores/packagemanager/install_uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (pm *PackageManager) UninstallTool(toolRelease *cores.ToolRelease) error {
// passed as parameter
func (pm *PackageManager) IsToolRequired(toolRelease *cores.ToolRelease) bool {
// Search in all installed platforms
for _, targetPackage := range pm.packages.Packages {
for _, targetPackage := range pm.Packages {
for _, platform := range targetPackage.Platforms {
if platformRelease := pm.GetInstalledPlatformRelease(platform); platformRelease != nil {
if platformRelease.RequiresToolRelease(toolRelease) {
Expand Down
6 changes: 3 additions & 3 deletions arduino/cores/packagemanager/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (pm *PackageManager) LoadHardwareFromDirectory(path *paths.Path) error {
continue
}

targetPackage := pm.packages.GetOrCreatePackage(packager)
targetPackage := pm.Packages.GetOrCreatePackage(packager)
if err := pm.loadPlatforms(targetPackage, architectureParentPath); err != nil {
return fmt.Errorf("loading package %s: %s", packager, err)
}
Expand Down Expand Up @@ -419,7 +419,7 @@ func (pm *PackageManager) LoadToolsFromBundleDirectory(toolsPath *paths.Path) er
}

for packager, toolsData := range all.FirstLevelOf() {
targetPackage := pm.packages.GetOrCreatePackage(packager)
targetPackage := pm.Packages.GetOrCreatePackage(packager)

for toolName, toolVersion := range toolsData.AsMap() {
tool := targetPackage.GetOrCreateTool(toolName)
Expand All @@ -431,7 +431,7 @@ func (pm *PackageManager) LoadToolsFromBundleDirectory(toolsPath *paths.Path) er
}
} else {
// otherwise load the tools inside the unnamed package
unnamedPackage := pm.packages.GetOrCreatePackage("")
unnamedPackage := pm.Packages.GetOrCreatePackage("")
pm.loadToolsFromPackage(unnamedPackage, toolsPath)
}
return nil
Expand Down
39 changes: 14 additions & 25 deletions arduino/cores/packagemanager/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ import (
// The manager also keeps track of the status of the Packages (their Platform Releases, actually)
// installed in the system.
type PackageManager struct {
Log logrus.FieldLogger
packages *cores.Packages

Log logrus.FieldLogger
Packages cores.Packages
IndexDir *paths.Path
PackagesDir *paths.Path
DownloadDir *paths.Path
Expand All @@ -51,28 +50,18 @@ type PackageManager struct {
func NewPackageManager(indexDir, packagesDir, downloadDir, tempDir *paths.Path) *PackageManager {
return &PackageManager{
Log: logrus.StandardLogger(),
packages: cores.NewPackages(),
Packages: cores.NewPackages(),
IndexDir: indexDir,
PackagesDir: packagesDir,
DownloadDir: downloadDir,
TempDir: tempDir,
}
}

// Clear FIXMEDOC
func (pm *PackageManager) Clear() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this wasn't used anywhere

pm.packages = cores.NewPackages()
}

// GetPackages FIXMEDOC
func (pm *PackageManager) GetPackages() *cores.Packages {
return pm.packages
}

// FindPlatformReleaseProvidingBoardsWithVidPid FIXMEDOC
func (pm *PackageManager) FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid string) []*cores.PlatformRelease {
res := []*cores.PlatformRelease{}
for _, targetPackage := range pm.packages.Packages {
for _, targetPackage := range pm.Packages {
for _, targetPlatform := range targetPackage.Platforms {
platformRelease := targetPlatform.GetLatestRelease()
if platformRelease == nil {
Expand All @@ -92,7 +81,7 @@ func (pm *PackageManager) FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid
// FindBoardsWithVidPid FIXMEDOC
func (pm *PackageManager) FindBoardsWithVidPid(vid, pid string) []*cores.Board {
res := []*cores.Board{}
for _, targetPackage := range pm.packages.Packages {
for _, targetPackage := range pm.Packages {
for _, targetPlatform := range targetPackage.Platforms {
if platform := pm.GetInstalledPlatformRelease(targetPlatform); platform != nil {
for _, board := range platform.Boards {
Expand All @@ -109,7 +98,7 @@ func (pm *PackageManager) FindBoardsWithVidPid(vid, pid string) []*cores.Board {
// FindBoardsWithID FIXMEDOC
func (pm *PackageManager) FindBoardsWithID(id string) []*cores.Board {
res := []*cores.Board{}
for _, targetPackage := range pm.packages.Packages {
for _, targetPackage := range pm.Packages {
for _, targetPlatform := range targetPackage.Platforms {
if platform := pm.GetInstalledPlatformRelease(targetPlatform); platform != nil {
for _, board := range platform.Boards {
Expand Down Expand Up @@ -152,7 +141,7 @@ func (pm *PackageManager) ResolveFQBN(fqbn *cores.FQBN) (
*properties.Map, *cores.PlatformRelease, error) {

// Find package
targetPackage := pm.packages.Packages[fqbn.Package]
targetPackage := pm.Packages[fqbn.Package]
if targetPackage == nil {
return nil, nil, nil, nil, nil,
errors.New("unknown package " + fqbn.Package)
Expand Down Expand Up @@ -189,7 +178,7 @@ func (pm *PackageManager) ResolveFQBN(fqbn *cores.FQBN) (
coreParts := strings.Split(buildProperties.Get("build.core"), ":")
if len(coreParts) > 1 {
referredPackage := coreParts[1]
buildPackage := pm.packages.Packages[referredPackage]
buildPackage := pm.Packages[referredPackage]
if buildPackage == nil {
return targetPackage, platformRelease, board, buildProperties, nil,
fmt.Errorf("missing package %s:%s required for build", referredPackage, platform)
Expand All @@ -215,7 +204,7 @@ func (pm *PackageManager) LoadPackageIndexFromFile(indexPath *paths.Path) (*pack
return nil, fmt.Errorf("loading json index file %s: %s", indexPath, err)
}

index.MergeIntoPackages(pm.packages)
index.MergeIntoPackages(pm.Packages)
return index, nil
}

Expand All @@ -224,7 +213,7 @@ func (pm *PackageManager) LoadPackageIndexFromFile(indexPath *paths.Path) (*pack
func (pm *PackageManager) Package(name string) *PackageActions {
//TODO: perhaps these 2 structure should be merged? cores.Packages vs pkgmgr??
var err error
thePackage := pm.packages.Packages[name]
thePackage := pm.Packages[name]
if thePackage == nil {
err = fmt.Errorf("package '%s' not found", name)
}
Expand Down Expand Up @@ -350,7 +339,7 @@ func (pm *PackageManager) GetInstalledPlatformRelease(platform *cores.Platform)
// GetAllInstalledToolsReleases FIXMEDOC
func (pm *PackageManager) GetAllInstalledToolsReleases() []*cores.ToolRelease {
tools := []*cores.ToolRelease{}
for _, targetPackage := range pm.packages.Packages {
for _, targetPackage := range pm.Packages {
for _, tool := range targetPackage.Tools {
for _, release := range tool.Releases {
if release.IsInstalled() {
Expand All @@ -366,7 +355,7 @@ func (pm *PackageManager) GetAllInstalledToolsReleases() []*cores.ToolRelease {
// useful to range all PlatformReleases in for loops.
func (pm *PackageManager) InstalledPlatformReleases() []*cores.PlatformRelease {
platforms := []*cores.PlatformRelease{}
for _, targetPackage := range pm.packages.Packages {
for _, targetPackage := range pm.Packages {
for _, platform := range targetPackage.Platforms {
for _, release := range platform.GetAllInstalled() {
platforms = append(platforms, release)
Expand All @@ -380,7 +369,7 @@ func (pm *PackageManager) InstalledPlatformReleases() []*cores.PlatformRelease {
// all Boards in for loops.
func (pm *PackageManager) InstalledBoards() []*cores.Board {
boards := []*cores.Board{}
for _, targetPackage := range pm.packages.Packages {
for _, targetPackage := range pm.Packages {
for _, platform := range targetPackage.Platforms {
for _, release := range platform.GetAllInstalled() {
for _, board := range release.Boards {
Expand All @@ -404,7 +393,7 @@ func (pm *PackageManager) FindToolsRequiredForBoard(board *cores.Board) ([]*core

// a Platform may not specify required tools (because it's a platform that comes from a
// sketchbook/hardware dir without a package_index.json) then add all available tools
for _, targetPackage := range pm.packages.Packages {
for _, targetPackage := range pm.Packages {
for _, tool := range targetPackage.Tools {
rel := tool.GetLatestInstalled()
if rel != nil {
Expand Down
Loading