Skip to content

Commit a86500d

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 fb30f2d commit a86500d

File tree

10 files changed

+305
-58
lines changed

10 files changed

+305
-58
lines changed

arduino/cores/cores.go

+6-5
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

+13-10
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

+3
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) {
@@ -58,6 +60,7 @@ func runListCommand(cmd *cobra.Command, args []string) {
5860
platforms, err := core.GetPlatforms(&rpc.PlatformListReq{
5961
Instance: inst,
6062
UpdatableOnly: listFlags.updatableOnly,
63+
All: listFlags.all,
6164
})
6265
if err != nil {
6366
feedback.Errorf("Error listing platforms: %v", err)

commands/core.go

+8-7
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

+15
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ func GetPlatforms(req *rpc.PlatformListReq) ([]*rpc.Platform, error) {
3939
for _, targetPackage := range packageManager.Packages {
4040
for _, platform := range targetPackage.Platforms {
4141
platformRelease := packageManager.GetInstalledPlatformRelease(platform)
42+
43+
// If both All and UpdatableOnly are set All takes precedence
44+
if req.All {
45+
installedVersion := ""
46+
if platformRelease == nil {
47+
platformRelease = platform.GetLatestRelease()
48+
} else {
49+
installedVersion = platformRelease.Version.String()
50+
}
51+
rpcPlatform := commands.PlatformReleaseToRPC(platform.GetLatestRelease())
52+
rpcPlatform.Installed = installedVersion
53+
res = append(res, rpcPlatform)
54+
continue
55+
}
56+
4257
if platformRelease != nil {
4358
if req.UpdatableOnly {
4459
if latest := platform.GetLatestRelease(); latest == nil || latest == platformRelease {

commands/core/search.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ func PlatformSearch(req *rpc.PlatformSearchReq) (*rpc.PlatformSearchResp, error)
5050
for _, targetPackage := range pm.Packages {
5151
for _, platform := range targetPackage.Platforms {
5252
// discard invalid platforms
53-
if platform == nil || platform.Name == "" {
53+
// Users can install platforms manually in the Sketchbook hardware folder,
54+
// the core search command must operate only on platforms installed through
55+
// the PlatformManager, thus we skip the manually installed ones.
56+
if platform == nil || platform.Name == "" || platform.ManuallyInstalled {
5457
continue
5558
}
5659

rpc/commands/core.pb.go

+60-35
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/commands/core.proto

+7
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 {

0 commit comments

Comments
 (0)