Skip to content

Commit

Permalink
Add --all flag to core list command and gRPC interface
Browse files Browse the repository at this point in the history
Setting that flags return all installed and installable platforms,
including installed manually by the user in their Sketchbook hardware
folder.
  • Loading branch information
silvanocerza committed Feb 3, 2021
1 parent fa478dd commit b4e232c
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 66 deletions.
11 changes: 6 additions & 5 deletions arduino/cores/cores.go
Expand Up @@ -28,11 +28,12 @@ import (

// Platform represents a platform package.
type Platform struct {
Architecture string // The name of the architecture of this package.
Name string
Category string
Releases map[string]*PlatformRelease // The Releases of this platform, labeled by version.
Package *Package `json:"-"`
Architecture string // The name of the architecture of this package.
Name string
Category string
Releases map[string]*PlatformRelease // The Releases of this platform, labeled by version.
Package *Package `json:"-"`
ManuallyInstalled bool // true if the Platform has been installed without the CLI
}

// PlatformReleaseHelp represents the help URL for this Platform release
Expand Down
23 changes: 13 additions & 10 deletions arduino/cores/packagemanager/loader.go
Expand Up @@ -166,18 +166,15 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir
return fmt.Errorf("looking for boards.txt in %s: %s", possibleBoardTxtPath, err)

} else if exist {

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

// FIXME: this check is duplicated, find a better way to handle this
if exist, err := platformPath.Join("boards.txt").ExistCheck(); err != nil {
return fmt.Errorf("opening boards.txt: %s", err)
} else if !exist {
continue
platformTxtPath := platformPath.Join("platform.txt")
platformProperties, err := properties.SafeLoad(platformTxtPath.String())
if err != nil {
return fmt.Errorf("loading platform.txt: %w", err)
}

platformName := platformProperties.Get("name")
version := semver.MustParse(platformProperties.Get("version"))

// check if package_bundled_index.json exists
isIDEBundled := false
packageBundledIndexPath := packageDir.Parent().Join("package_index_bundled.json")
Expand Down Expand Up @@ -210,6 +207,12 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir
}

platform := targetPackage.GetOrCreatePlatform(architecture)
if platform.Name == "" {
platform.Name = platformName
}
if !isIDEBundled {
platform.ManuallyInstalled = true
}
release := platform.GetOrCreateRelease(version)
release.IsIDEBundled = isIDEBundled
if isIDEBundled {
Expand Down
4 changes: 3 additions & 1 deletion cli/core/list.go
Expand Up @@ -39,11 +39,13 @@ func initListCommand() *cobra.Command {
Run: runListCommand,
}
listCommand.Flags().BoolVar(&listFlags.updatableOnly, "updatable", false, "List updatable platforms.")
listCommand.Flags().BoolVar(&listFlags.all, "all", false, "If set return all installable and installed cores, including manually installed.")
return listCommand
}

var listFlags struct {
updatableOnly bool
all bool
}

func runListCommand(cmd *cobra.Command, args []string) {
Expand All @@ -55,7 +57,7 @@ func runListCommand(cmd *cobra.Command, args []string) {

logrus.Info("Executing `arduino core list`")

platforms, err := core.GetPlatforms(inst.Id, listFlags.updatableOnly)
platforms, err := core.GetPlatforms(inst.Id, listFlags.updatableOnly, listFlags.all)
if err != nil {
feedback.Errorf("Error listing platforms: %v", err)
os.Exit(errorcodes.ErrGeneric)
Expand Down
2 changes: 1 addition & 1 deletion cli/core/upgrade.go
Expand Up @@ -57,7 +57,7 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {

// if no platform was passed, upgrade allthethings
if len(args) == 0 {
targets, err := core.GetPlatforms(inst.Id, true)
targets, err := core.GetPlatforms(inst.Id, true, false)
if err != nil {
feedback.Errorf("Error retrieving core list: %v", err)
os.Exit(errorcodes.ErrGeneric)
Expand Down
15 changes: 8 additions & 7 deletions commands/core.go
Expand Up @@ -51,13 +51,14 @@ func PlatformReleaseToRPC(platformRelease *cores.PlatformRelease) *rpc.Platform
}

result := &rpc.Platform{
ID: platformRelease.Platform.String(),
Name: platformRelease.Platform.Name,
Maintainer: platformRelease.Platform.Package.Maintainer,
Website: platformRelease.Platform.Package.WebsiteURL,
Email: platformRelease.Platform.Package.Email,
Boards: boards,
Latest: platformRelease.Version.String(),
ID: platformRelease.Platform.String(),
Name: platformRelease.Platform.Name,
Maintainer: platformRelease.Platform.Package.Maintainer,
Website: platformRelease.Platform.Package.WebsiteURL,
Email: platformRelease.Platform.Package.Email,
Boards: boards,
Latest: platformRelease.Version.String(),
ManuallyInstalled: platformRelease.Platform.ManuallyInstalled,
}

return result
Expand Down
14 changes: 11 additions & 3 deletions commands/core/list.go
Expand Up @@ -23,7 +23,7 @@ import (

// GetPlatforms returns a list of installed platforms, optionally filtered by
// those requiring an update.
func GetPlatforms(instanceID int32, updatableOnly bool) ([]*cores.PlatformRelease, error) {
func GetPlatforms(instanceID int32, updatableOnly, all bool) ([]*cores.PlatformRelease, error) {
i := commands.GetInstance(instanceID)
if i == nil {
return nil, errors.Errorf("unable to find an instance with ID: %d", instanceID)
Expand All @@ -34,16 +34,24 @@ func GetPlatforms(instanceID int32, updatableOnly bool) ([]*cores.PlatformReleas
return nil, errors.New("invalid instance")
}

if updatableOnly && all {
return nil, errors.New("can't use both updatableOnly and all flags at the same time")
}

res := []*cores.PlatformRelease{}
for _, targetPackage := range packageManager.Packages {
for _, platform := range targetPackage.Platforms {
if platformRelease := packageManager.GetInstalledPlatformRelease(platform); platformRelease != nil {
platformRelease := packageManager.GetInstalledPlatformRelease(platform)
if all {
res = append(res, platform.GetLatestRelease())
continue
}
if platformRelease != nil {
if updatableOnly {
if latest := platform.GetLatestRelease(); latest == nil || latest == platformRelease {
continue
}
}

res = append(res, platformRelease)
}
}
Expand Down
5 changes: 4 additions & 1 deletion commands/core/search.go
Expand Up @@ -48,7 +48,10 @@ func PlatformSearch(instanceID int32, searchArgs string, allVersions bool) (*rpc
for _, targetPackage := range pm.Packages {
for _, platform := range targetPackage.Platforms {
// discard invalid platforms
if platform == nil || platform.Name == "" {
// Users can install platforms manually in the Sketchbook hardware folder,
// the core search command must operate only on platforms installed through
// the PlatformManager, thus we skip the manually installed ones.
if platform == nil || platform.Name == "" || platform.ManuallyInstalled {
continue
}

Expand Down
2 changes: 1 addition & 1 deletion commands/daemon/daemon.go
Expand Up @@ -264,7 +264,7 @@ func (s *ArduinoCoreServerImpl) PlatformSearch(ctx context.Context, req *rpc.Pla

// PlatformList FIXMEDOC
func (s *ArduinoCoreServerImpl) PlatformList(ctx context.Context, req *rpc.PlatformListReq) (*rpc.PlatformListResp, error) {
platforms, err := core.GetPlatforms(req.Instance.Id, req.UpdatableOnly)
platforms, err := core.GetPlatforms(req.Instance.Id, req.UpdatableOnly, req.All)
if err != nil {
return nil, err
}
Expand Down
95 changes: 60 additions & 35 deletions rpc/commands/core.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions rpc/commands/core.proto
Expand Up @@ -109,6 +109,10 @@ message PlatformListReq {
// Set to true to only list platforms which have a newer version available
// than the one currently installed.
bool updatable_only = 2;
// Set to true to list platforms installed manually in the user' sketchbook
// hardware folder, installed with the PlatformManager through the CLI or IDE
// and that are available to install
bool all = 3;
}

message PlatformListResp {
Expand Down Expand Up @@ -137,6 +141,9 @@ message Platform {
// not installed, this is an arbitrary list of board names provided by the
// platform author for display and may not match boards.txt.
repeated Board Boards = 8;
// If true this Platform has been installed manually in the user' sketchbook
// hardware folder
bool ManuallyInstalled = 9;
}

message Board {
Expand Down
4 changes: 2 additions & 2 deletions rpc/settings/settings.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b4e232c

Please sign in to comment.