Skip to content

Commit ad5dacc

Browse files
[breaking] Updated gRPC Platform API (arduino#2357)
* Updated gRPC Pltform API, regenerated API * Adapted cores.Platform and PlatformRelease to the new gRPC API * Fixed search_test.go * Removed gRPC PlatformList command * Other adaptation of platform structures * Adapt arguuments completion to use PlatformSearch instead of PlatformList * Adapt 'core list' to use PlatformSearch instead of PlatformList * Adapt 'core upgrade' command to use PlatformSearch instead of PlatformList * Adapted some integration tests * Fix integreation test * apply changes to search vidpid * Better handling of 'core list' results * Better handling of 'core search' results * Better handling of 'core outdated' results * add 'orderedmap' data structure * Made orderedmap more generic * fix regression on 'ParseReference' * wip: fix 'core' integrationtests * wip: fix 'core' sorting tests * fix regression which skipped mannually instaled core in core list * wip: add more 'core' integration tests * regression: all flag takes precedence above updatable in core list * lint: ignore unexported-return (revive) * license: regenerate and add missin headers * tests: fix 'board' integrations * fix: regression not showing manually installed platform in 'core list' * wip: add test to orderedmap * add more orderdmap tests * orderdmap: add json tests * update DOCS * apply CR suggestions * fix proto numeration * docs: update to release 0.36.0 --------- Co-authored-by: Alessio Perugini <alessioper.98@gmail.com>
1 parent eb8f2f2 commit ad5dacc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2329
-1315
lines changed

.golangci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ linters-settings:
6262
- name: redefines-builtin-id
6363
- name: superfluous-else
6464
- name: time-naming
65-
- name: unexported-return
6665
- name: unreachable-code
6766
- name: var-declaration
6867
- name: defer

arduino/cores/cores.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,13 @@ import (
3737

3838
// Platform represents a platform package.
3939
type Platform struct {
40-
Architecture string // The name of the architecture of this package.
41-
Name string
42-
Category string
40+
Architecture string // The name of the architecture of this package.
4341
Releases map[semver.NormalizedString]*PlatformRelease // The Releases of this platform, labeled by version.
4442
Package *Package `json:"-"`
4543
ManuallyInstalled bool // true if the Platform has been installed without the CLI
46-
Deprecated bool // true if the Platform has been deprecated
44+
Deprecated bool // true if the latest PlatformRelease of this Platform has been deprecated
4745
Indexed bool // true if the Platform has been indexed from additional-urls
46+
Latest *semver.Version `json:"-"`
4847
}
4948

5049
// PlatformReleaseHelp represents the help URL for this Platform release
@@ -54,12 +53,15 @@ type PlatformReleaseHelp struct {
5453

5554
// PlatformRelease represents a release of a plaform package.
5655
type PlatformRelease struct {
56+
Name string
57+
Category string
5758
Resource *resources.DownloadResource
5859
Version *semver.Version
5960
BoardsManifest []*BoardManifest
6061
ToolDependencies ToolDependencies
6162
DiscoveryDependencies DiscoveryDependencies
6263
MonitorDependencies MonitorDependencies
64+
Deprecated bool
6365
Help PlatformReleaseHelp `json:"-"`
6466
Platform *Platform `json:"-"`
6567
Properties *properties.Map `json:"-"`
@@ -407,7 +409,7 @@ func (release *PlatformRelease) MarshalJSON() ([]byte, error) {
407409
ID: release.Platform.String(),
408410
Installed: release.Version.String(),
409411
Latest: latestStr,
410-
Name: release.Platform.Name,
412+
Name: release.Name,
411413
})
412414
}
413415

arduino/cores/packageindex/index.go

+9-11
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,11 @@ func IndexFromPlatformRelease(pr *cores.PlatformRelease) Index {
222222
URL: pr.Platform.Package.URL,
223223
Email: pr.Platform.Package.Email,
224224
Platforms: []*indexPlatformRelease{{
225-
Name: pr.Platform.Name,
225+
Name: pr.Name,
226226
Architecture: pr.Platform.Architecture,
227227
Version: pr.Version,
228-
Deprecated: pr.Platform.Deprecated,
229-
Category: pr.Platform.Category,
228+
Deprecated: pr.Deprecated,
229+
Category: pr.Category,
230230
URL: pr.Resource.URL,
231231
ArchiveFileName: pr.Resource.ArchiveFileName,
232232
Checksum: pr.Resource.Checksum,
@@ -263,18 +263,13 @@ func (inPackage indexPackage) extractPackageIn(outPackages cores.Packages, trust
263263

264264
func (inPlatformRelease indexPlatformRelease) extractPlatformIn(outPackage *cores.Package, trusted bool, isInstallJSON bool) error {
265265
outPlatform := outPackage.GetOrCreatePlatform(inPlatformRelease.Architecture)
266-
// FIXME: shall we use the Name and Category of the latest release? or maybe move Name and Category in PlatformRelease?
267-
outPlatform.Name = inPlatformRelease.Name
268-
outPlatform.Category = inPlatformRelease.Category
269266
// If the variable `isInstallJSON` is false it means that the index we're reading is coming from the additional-urls.
270267
// Therefore, the `outPlatform.Indexed` will be set at `true`.
271268
outPlatform.Indexed = outPlatform.Indexed || !isInstallJSON
272269

273-
// If the Platform is installed before deprecation installed.json file does not include "deprecated" field.
274-
// The installed.json is read during loading phase of an installed Platform, if the deprecated field is not found
275-
// the package_index.json field would be overwritten and the deprecation info would be lost.
276-
// This check prevents that behaviour.
277-
if !outPlatform.Deprecated {
270+
// If the latest platform release is deprecated, then deprecate the whole platform.
271+
if outPlatform.Latest == nil || outPlatform.Latest.LessThan(inPlatformRelease.Version) {
272+
outPlatform.Latest = inPlatformRelease.Version
278273
outPlatform.Deprecated = inPlatformRelease.Deprecated
279274
}
280275

@@ -283,6 +278,8 @@ func (inPlatformRelease indexPlatformRelease) extractPlatformIn(outPackage *core
283278
return fmt.Errorf(tr("invalid platform archive size: %s"), err)
284279
}
285280
outPlatformRelease := outPlatform.GetOrCreateRelease(inPlatformRelease.Version)
281+
outPlatformRelease.Name = inPlatformRelease.Name
282+
outPlatformRelease.Category = inPlatformRelease.Category
286283
outPlatformRelease.IsTrusted = trusted
287284
outPlatformRelease.Resource = &resources.DownloadResource{
288285
ArchiveFileName: inPlatformRelease.ArchiveFileName,
@@ -296,6 +293,7 @@ func (inPlatformRelease indexPlatformRelease) extractPlatformIn(outPackage *core
296293
outPlatformRelease.ToolDependencies = inPlatformRelease.extractToolDependencies()
297294
outPlatformRelease.DiscoveryDependencies = inPlatformRelease.extractDiscoveryDependencies()
298295
outPlatformRelease.MonitorDependencies = inPlatformRelease.extractMonitorDependencies()
296+
outPlatformRelease.Deprecated = inPlatformRelease.Deprecated
299297
return nil
300298
}
301299

arduino/cores/packageindex/index_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,10 @@ func TestIndexFromPlatformRelease(t *testing.T) {
9191
Name: "serial-monitor",
9292
},
9393
},
94+
Name: "Arduino AVR Boards",
95+
Category: "Arduino",
9496
Platform: &cores.Platform{
95-
Name: "Arduino AVR Boards",
9697
Architecture: "avr",
97-
Category: "Arduino",
98-
9998
Package: &cores.Package{
10099
Name: "arduino",
101100
Maintainer: "Arduino",

arduino/cores/packagemanager/loader.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,14 @@ func (pm *Builder) loadPlatformRelease(platform *cores.PlatformRelease, path *pa
323323
platform.Properties.Set("pluggable_monitor.required.serial", "builtin:serial-monitor")
324324
}
325325

326-
if platform.Platform.Name == "" {
326+
if platform.Name == "" {
327327
if name, ok := platform.Properties.GetOk("name"); ok {
328-
platform.Platform.Name = name
328+
platform.Name = name
329329
} else {
330330
// If the platform.txt file doesn't exist for this platform and it's not in any
331331
// package index there is no way of retrieving its name, so we build one using
332332
// the available information, that is the packager name and the architecture.
333-
platform.Platform.Name = fmt.Sprintf("%s-%s", platform.Platform.Package.Name, platform.Platform.Architecture)
333+
platform.Name = fmt.Sprintf("%s-%s", platform.Platform.Package.Name, platform.Platform.Architecture)
334334
}
335335
}
336336

arduino/cores/packagemanager/package_manager.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ func (pme *Explorer) GetCustomGlobalProperties() *properties.Map {
192192
}
193193

194194
// FindPlatformReleaseProvidingBoardsWithVidPid FIXMEDOC
195-
func (pme *Explorer) FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid string) []*cores.PlatformRelease {
196-
res := []*cores.PlatformRelease{}
195+
func (pme *Explorer) FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid string) []*cores.Platform {
196+
res := []*cores.Platform{}
197197
for _, targetPackage := range pme.packages {
198198
for _, targetPlatform := range targetPackage.Platforms {
199199
platformRelease := targetPlatform.GetLatestRelease()
@@ -202,7 +202,7 @@ func (pme *Explorer) FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid strin
202202
}
203203
for _, boardManifest := range platformRelease.BoardsManifest {
204204
if boardManifest.HasUsbID(vid, pid) {
205-
res = append(res, platformRelease)
205+
res = append(res, targetPlatform)
206206
break
207207
}
208208
}

arduino/cores/packagemanager/profiles.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (pmb *Builder) LoadHardwareForProfile(p *sketch.Profile, installMissing boo
4545
logrus.WithField("platform", platformRef).WithError(err).Debugf("Error loading platform for profile")
4646
} else {
4747
platformReleases = append(platformReleases, platformRelease)
48-
indexURLs[platformRelease.Platform.Name] = platformRef.PlatformIndexURL
48+
indexURLs[platformRelease.Name] = platformRef.PlatformIndexURL
4949
logrus.WithField("platform", platformRef).Debugf("Loaded platform for profile")
5050
}
5151
}

client_example/main.go

+2-22
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,6 @@ func main() {
145145
log.Println("calling PlatformInstall(arduino:samd@1.6.19)")
146146
callPlatformInstall(client, instance)
147147

148-
// Now list the installed platforms to double check previous installation
149-
// went right.
150-
log.Println("calling PlatformList()")
151-
callPlatformList(client, instance)
152-
153148
// Upgrade the installed platform to the latest version.
154149
log.Println("calling PlatformUpgrade(arduino:samd)")
155150
callPlatformUpgrade(client, instance)
@@ -420,7 +415,7 @@ func callPlatformSearch(client rpc.ArduinoCoreServiceClient, instance *rpc.Insta
420415
for _, plat := range platforms {
421416
// We only print ID and version of the platforms found but you can look
422417
// at the definition for the rpc.Platform struct for more fields.
423-
log.Printf("Search result: %+v - %+v", plat.GetId(), plat.GetLatest())
418+
log.Printf("Search result: %+v - %+v", plat.GetMetadata().GetId(), plat.GetLatestVersion())
424419
}
425420
}
426421

@@ -464,21 +459,6 @@ func callPlatformInstall(client rpc.ArduinoCoreServiceClient, instance *rpc.Inst
464459
}
465460
}
466461

467-
func callPlatformList(client rpc.ArduinoCoreServiceClient, instance *rpc.Instance) {
468-
listResp, err := client.PlatformList(context.Background(),
469-
&rpc.PlatformListRequest{Instance: instance})
470-
471-
if err != nil {
472-
log.Fatalf("List error: %s", err)
473-
}
474-
475-
for _, plat := range listResp.GetInstalledPlatforms() {
476-
// We only print ID and version of the installed platforms but you can look
477-
// at the definition for the rpc.Platform struct for more fields.
478-
log.Printf("Installed platform: %s - %s", plat.GetId(), plat.GetInstalled())
479-
}
480-
}
481-
482462
func callPlatformUpgrade(client rpc.ArduinoCoreServiceClient, instance *rpc.Instance) {
483463
upgradeRespStream, err := client.PlatformUpgrade(context.Background(),
484464
&rpc.PlatformUpgradeRequest{
@@ -546,7 +526,7 @@ func callBoardSearch(client rpc.ArduinoCoreServiceClient, instance *rpc.Instance
546526
}
547527

548528
for _, board := range res.Boards {
549-
log.Printf("Board Name: %s, Board Platform: %s\n", board.Name, board.Platform.Id)
529+
log.Printf("Board Name: %s, Board Platform: %s\n", board.Name, board.Platform.Metadata.Id)
550530
}
551531
}
552532

commands/board/details.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai
3939
return nil, &arduino.InvalidFQBNError{Cause: err}
4040
}
4141

42-
boardPackage, boardPlatform, board, boardProperties, boardRefPlatform, err := pme.ResolveFQBN(fqbn)
42+
boardPackage, boardPlatformRelease, board, boardProperties, boardRefPlatform, err := pme.ResolveFQBN(fqbn)
4343
if err != nil {
4444
return nil, &arduino.UnknownFQBNError{Cause: err}
4545
}
@@ -65,11 +65,11 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai
6565
}
6666

6767
details.DebuggingSupported = boardProperties.ContainsKey("debug.executable") ||
68-
boardPlatform.Properties.ContainsKey("debug.executable") ||
68+
boardPlatformRelease.Properties.ContainsKey("debug.executable") ||
6969
(boardRefPlatform != nil && boardRefPlatform.Properties.ContainsKey("debug.executable")) ||
7070
// HOTFIX: Remove me when the `arduino:samd` core is updated
71-
boardPlatform.String() == "arduino:samd@1.8.9" ||
72-
boardPlatform.String() == "arduino:samd@1.8.8"
71+
boardPlatformRelease.String() == "arduino:samd@1.8.9" ||
72+
boardPlatformRelease.String() == "arduino:samd@1.8.8"
7373

7474
details.Package = &rpc.Package{
7575
Name: boardPackage.Name,
@@ -81,16 +81,16 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai
8181
}
8282

8383
details.Platform = &rpc.BoardPlatform{
84-
Architecture: boardPlatform.Platform.Architecture,
85-
Category: boardPlatform.Platform.Category,
86-
Name: boardPlatform.Platform.Name,
84+
Architecture: boardPlatformRelease.Platform.Architecture,
85+
Category: boardPlatformRelease.Category,
86+
Name: boardPlatformRelease.Name,
8787
}
8888

89-
if boardPlatform.Resource != nil {
90-
details.Platform.Url = boardPlatform.Resource.URL
91-
details.Platform.ArchiveFilename = boardPlatform.Resource.ArchiveFileName
92-
details.Platform.Checksum = boardPlatform.Resource.Checksum
93-
details.Platform.Size = boardPlatform.Resource.Size
89+
if boardPlatformRelease.Resource != nil {
90+
details.Platform.Url = boardPlatformRelease.Resource.URL
91+
details.Platform.ArchiveFilename = boardPlatformRelease.Resource.ArchiveFileName
92+
details.Platform.Checksum = boardPlatformRelease.Resource.Checksum
93+
details.Platform.Size = boardPlatformRelease.Resource.Size
9494
}
9595

9696
details.ConfigOptions = []*rpc.ConfigOption{}
@@ -118,7 +118,7 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai
118118
}
119119

120120
details.ToolsDependencies = []*rpc.ToolsDependencies{}
121-
for _, tool := range boardPlatform.ToolDependencies {
121+
for _, tool := range boardPlatformRelease.ToolDependencies {
122122
toolRelease := pme.FindToolDependency(tool)
123123
var systems []*rpc.Systems
124124
if toolRelease != nil {
@@ -141,9 +141,9 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai
141141
}
142142

143143
details.Programmers = []*rpc.Programmer{}
144-
for id, p := range boardPlatform.Programmers {
144+
for id, p := range boardPlatformRelease.Programmers {
145145
details.Programmers = append(details.Programmers, &rpc.Programmer{
146-
Platform: boardPlatform.Platform.Name,
146+
Platform: boardPlatformRelease.Name,
147147
Id: id,
148148
Name: p.Name,
149149
})

commands/board/list.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ func identify(pme *packagemanager.Explorer, port *discovery.Port) ([]*rpc.BoardL
157157

158158
// We need the Platform maintaner for sorting so we set it here
159159
platform := &rpc.Platform{
160-
Maintainer: board.PlatformRelease.Platform.Package.Maintainer,
160+
Metadata: &rpc.PlatformMetadata{
161+
Maintainer: board.PlatformRelease.Platform.Package.Maintainer,
162+
},
161163
}
162164
boards = append(boards, &rpc.BoardListItem{
163165
Name: board.Name(),
@@ -185,7 +187,7 @@ func identify(pme *packagemanager.Explorer, port *discovery.Port) ([]*rpc.BoardL
185187

186188
// Put Arduino boards before others in case there are non Arduino boards with identical VID:PID combination
187189
sort.SliceStable(boards, func(i, j int) bool {
188-
if boards[i].Platform.Maintainer == "Arduino" && boards[j].Platform.Maintainer != "Arduino" {
190+
if boards[i].Platform.Metadata.Maintainer == "Arduino" && boards[j].Platform.Metadata.Maintainer != "Arduino" {
189191
return true
190192
}
191193
return false

commands/board/listall.go

+4-18
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/arduino/arduino-cli/arduino"
2424
"github.com/arduino/arduino-cli/arduino/cores"
2525
"github.com/arduino/arduino-cli/arduino/utils"
26+
"github.com/arduino/arduino-cli/commands"
2627
"github.com/arduino/arduino-cli/commands/internal/instances"
2728
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2829
)
@@ -46,29 +47,14 @@ func ListAll(ctx context.Context, req *rpc.BoardListAllRequest) (*rpc.BoardListA
4647
continue
4748
}
4849

49-
installedVersion := installedPlatformRelease.Version.String()
50-
51-
latestVersion := ""
52-
if latestPlatformRelease := platform.GetLatestRelease(); latestPlatformRelease != nil {
53-
latestVersion = latestPlatformRelease.Version.String()
54-
}
55-
5650
rpcPlatform := &rpc.Platform{
57-
Id: platform.String(),
58-
Installed: installedVersion,
59-
Latest: latestVersion,
60-
Name: platform.Name,
61-
Maintainer: platform.Package.Maintainer,
62-
Website: platform.Package.WebsiteURL,
63-
Email: platform.Package.Email,
64-
ManuallyInstalled: platform.ManuallyInstalled,
65-
Indexed: platform.Indexed,
66-
MissingMetadata: !installedPlatformRelease.HasMetadata(),
51+
Metadata: commands.PlatformToRPCPlatformMetadata(platform),
52+
Release: commands.PlatformReleaseToRPC(installedPlatformRelease),
6753
}
6854

6955
toTest := []string{
7056
platform.String(),
71-
platform.Name,
57+
installedPlatformRelease.Name,
7258
platform.Architecture,
7359
targetPackage.Name,
7460
targetPackage.Maintainer,

0 commit comments

Comments
 (0)