Skip to content

Commit cfe9081

Browse files
committed
Add --all flag to core list command and gRPC interface
Setting that flags return all installed and installable platforms, including installed manually by the user in their Sketchbook hardware folder.
1 parent a9b0c9d commit cfe9081

File tree

12 files changed

+176
-66
lines changed

12 files changed

+176
-66
lines changed

arduino/cores/cores.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ import (
2828

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

3839
// PlatformReleaseHelp represents the help URL for this Platform release

arduino/cores/packagemanager/loader.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,15 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir
166166
return fmt.Errorf("looking for boards.txt in %s: %s", possibleBoardTxtPath, err)
167167

168168
} else if exist {
169-
170-
// case: ARCHITECTURE/boards.txt
171-
// this is the general case for unversioned Platform
172-
version := semver.MustParse("")
173-
174-
// FIXME: this check is duplicated, find a better way to handle this
175-
if exist, err := platformPath.Join("boards.txt").ExistCheck(); err != nil {
176-
return fmt.Errorf("opening boards.txt: %s", err)
177-
} else if !exist {
178-
continue
169+
platformTxtPath := platformPath.Join("platform.txt")
170+
platformProperties, err := properties.SafeLoad(platformTxtPath.String())
171+
if err != nil {
172+
return fmt.Errorf("loading platform.txt: %w", err)
179173
}
180174

175+
platformName := platformProperties.Get("name")
176+
version := semver.MustParse(platformProperties.Get("version"))
177+
181178
// check if package_bundled_index.json exists
182179
isIDEBundled := false
183180
packageBundledIndexPath := packageDir.Parent().Join("package_index_bundled.json")
@@ -210,6 +207,12 @@ func (pm *PackageManager) loadPlatforms(targetPackage *cores.Package, packageDir
210207
}
211208

212209
platform := targetPackage.GetOrCreatePlatform(architecture)
210+
if platform.Name == "" {
211+
platform.Name = platformName
212+
}
213+
if !isIDEBundled {
214+
platform.ManuallyInstalled = true
215+
}
213216
release := platform.GetOrCreateRelease(version)
214217
release.IsIDEBundled = isIDEBundled
215218
if isIDEBundled {

cli/core/list.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ func initListCommand() *cobra.Command {
3939
Run: runListCommand,
4040
}
4141
listCommand.Flags().BoolVar(&listFlags.updatableOnly, "updatable", false, "List updatable platforms.")
42+
listCommand.Flags().BoolVar(&listFlags.all, "all", false, "If set return all installable and installed cores, including manually installed.")
4243
return listCommand
4344
}
4445

4546
var listFlags struct {
4647
updatableOnly bool
48+
all bool
4749
}
4850

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

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

58-
platforms, err := core.GetPlatforms(inst.Id, listFlags.updatableOnly)
60+
platforms, err := core.GetPlatforms(inst.Id, listFlags.updatableOnly, listFlags.all)
5961
if err != nil {
6062
feedback.Errorf("Error listing platforms: %v", err)
6163
os.Exit(errorcodes.ErrGeneric)

cli/core/upgrade.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
5757

5858
// if no platform was passed, upgrade allthethings
5959
if len(args) == 0 {
60-
targets, err := core.GetPlatforms(inst.Id, true)
60+
targets, err := core.GetPlatforms(inst.Id, true, false)
6161
if err != nil {
6262
feedback.Errorf("Error retrieving core list: %v", err)
6363
os.Exit(errorcodes.ErrGeneric)

commands/core.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ func PlatformReleaseToRPC(platformRelease *cores.PlatformRelease) *rpc.Platform
5151
}
5252

5353
result := &rpc.Platform{
54-
ID: platformRelease.Platform.String(),
55-
Name: platformRelease.Platform.Name,
56-
Maintainer: platformRelease.Platform.Package.Maintainer,
57-
Website: platformRelease.Platform.Package.WebsiteURL,
58-
Email: platformRelease.Platform.Package.Email,
59-
Boards: boards,
60-
Latest: platformRelease.Version.String(),
54+
ID: platformRelease.Platform.String(),
55+
Name: platformRelease.Platform.Name,
56+
Maintainer: platformRelease.Platform.Package.Maintainer,
57+
Website: platformRelease.Platform.Package.WebsiteURL,
58+
Email: platformRelease.Platform.Package.Email,
59+
Boards: boards,
60+
Latest: platformRelease.Version.String(),
61+
ManuallyInstalled: platformRelease.Platform.ManuallyInstalled,
6162
}
6263

6364
return result

commands/core/list.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323

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

37+
if updatableOnly && all {
38+
return nil, errors.New("can't use both updatableOnly and all flags at the same time")
39+
}
40+
3741
res := []*cores.PlatformRelease{}
3842
for _, targetPackage := range packageManager.Packages {
3943
for _, platform := range targetPackage.Platforms {
40-
if platformRelease := packageManager.GetInstalledPlatformRelease(platform); platformRelease != nil {
44+
platformRelease := packageManager.GetInstalledPlatformRelease(platform)
45+
if all {
46+
res = append(res, platform.GetLatestRelease())
47+
continue
48+
}
49+
if platformRelease != nil {
4150
if updatableOnly {
4251
if latest := platform.GetLatestRelease(); latest == nil || latest == platformRelease {
4352
continue
4453
}
4554
}
46-
4755
res = append(res, platformRelease)
4856
}
4957
}

commands/core/search.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ func PlatformSearch(instanceID int32, searchArgs string, allVersions bool) (*rpc
4848
for _, targetPackage := range pm.Packages {
4949
for _, platform := range targetPackage.Platforms {
5050
// discard invalid platforms
51-
if platform == nil || platform.Name == "" {
51+
// Users can install platforms manually in the Sketchbook hardware folder,
52+
// the core search command must operate only on platforms installed through
53+
// the PlatformManager, thus we skip the manually installed ones.
54+
if platform == nil || platform.Name == "" || platform.ManuallyInstalled {
5255
continue
5356
}
5457

commands/daemon/daemon.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func (s *ArduinoCoreServerImpl) PlatformSearch(ctx context.Context, req *rpc.Pla
264264

265265
// PlatformList FIXMEDOC
266266
func (s *ArduinoCoreServerImpl) PlatformList(ctx context.Context, req *rpc.PlatformListReq) (*rpc.PlatformListResp, error) {
267-
platforms, err := core.GetPlatforms(req.Instance.Id, req.UpdatableOnly)
267+
platforms, err := core.GetPlatforms(req.Instance.Id, req.UpdatableOnly, req.All)
268268
if err != nil {
269269
return nil, err
270270
}

rpc/commands/core.pb.go

Lines changed: 60 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/commands/core.proto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ message PlatformListReq {
109109
// Set to true to only list platforms which have a newer version available
110110
// than the one currently installed.
111111
bool updatable_only = 2;
112+
// Set to true to list platforms installed manually in the user' sketchbook
113+
// hardware folder, installed with the PlatformManager through the CLI or IDE
114+
// and that are available to install
115+
bool all = 3;
112116
}
113117

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

142149
message Board {

rpc/settings/settings.pb.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)