Skip to content
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

[breaking] Updated gRPC Platform API #2357

Merged
merged 33 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
28f1f71
Updated gRPC Pltform API, regenerated API
cmaglie Oct 6, 2023
86b171d
Adapted cores.Platform and PlatformRelease to the new gRPC API
cmaglie Oct 16, 2023
2031172
Fixed search_test.go
cmaglie Oct 16, 2023
28cc496
Removed gRPC PlatformList command
cmaglie Oct 16, 2023
24a1dd3
Other adaptation of platform structures
cmaglie Oct 16, 2023
9d2fd89
Adapt arguuments completion to use PlatformSearch instead of Platform…
cmaglie Oct 16, 2023
c80d0ff
Adapt 'core list' to use PlatformSearch instead of PlatformList
cmaglie Oct 16, 2023
175a6d2
Adapt 'core upgrade' command to use PlatformSearch instead of Platfor…
cmaglie Oct 16, 2023
3b41351
Adapted some integration tests
cmaglie Oct 16, 2023
3c7bc1a
Fix integreation test
cmaglie Oct 9, 2023
0a055a6
apply changes to search vidpid
alessio-perugini Oct 10, 2023
f11b45d
Better handling of 'core list' results
cmaglie Oct 10, 2023
abe05fa
Better handling of 'core search' results
cmaglie Oct 10, 2023
7f3a6cb
Better handling of 'core outdated' results
cmaglie Oct 10, 2023
aca91e6
add 'orderedmap' data structure
alessio-perugini Oct 10, 2023
b8ae4f3
Made orderedmap more generic
cmaglie Oct 11, 2023
8c98f74
fix regression on 'ParseReference'
alessio-perugini Oct 11, 2023
6a6897b
wip: fix 'core' integrationtests
alessio-perugini Oct 11, 2023
7ad2ca4
wip: fix 'core' sorting tests
alessio-perugini Oct 11, 2023
cccf397
fix regression which skipped mannually instaled core in core list
alessio-perugini Oct 12, 2023
8b8ce96
wip: add more 'core' integration tests
alessio-perugini Oct 12, 2023
3cee33b
regression: all flag takes precedence above updatable in core list
alessio-perugini Oct 12, 2023
064f57f
lint: ignore unexported-return (revive)
alessio-perugini Oct 12, 2023
ea0854e
license: regenerate and add missin headers
alessio-perugini Oct 12, 2023
64a2631
tests: fix 'board' integrations
alessio-perugini Oct 12, 2023
d010385
fix: regression not showing manually installed platform in 'core list'
alessio-perugini Oct 12, 2023
1d4b9e2
wip: add test to orderedmap
alessio-perugini Oct 12, 2023
87ea190
add more orderdmap tests
alessio-perugini Oct 13, 2023
655a5af
orderdmap: add json tests
alessio-perugini Oct 13, 2023
5fd313c
update DOCS
alessio-perugini Oct 13, 2023
d9dd825
apply CR suggestions
alessio-perugini Oct 16, 2023
494e923
fix proto numeration
alessio-perugini Oct 19, 2023
8528612
docs: update to release 0.36.0
alessio-perugini Oct 19, 2023
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
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ linters-settings:
- name: redefines-builtin-id
- name: superfluous-else
- name: time-naming
- name: unexported-return
- name: unreachable-code
- name: var-declaration
- name: defer
Expand Down
12 changes: 7 additions & 5 deletions arduino/cores/cores.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ import (

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

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

// PlatformRelease represents a release of a plaform package.
type PlatformRelease struct {
Name string
Category string
Resource *resources.DownloadResource
Version *semver.Version
BoardsManifest []*BoardManifest
ToolDependencies ToolDependencies
DiscoveryDependencies DiscoveryDependencies
MonitorDependencies MonitorDependencies
Deprecated bool
Help PlatformReleaseHelp `json:"-"`
Platform *Platform `json:"-"`
Properties *properties.Map `json:"-"`
Expand Down Expand Up @@ -407,7 +409,7 @@ func (release *PlatformRelease) MarshalJSON() ([]byte, error) {
ID: release.Platform.String(),
Installed: release.Version.String(),
Latest: latestStr,
Name: release.Platform.Name,
Name: release.Name,
})
}

Expand Down
20 changes: 9 additions & 11 deletions arduino/cores/packageindex/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ func IndexFromPlatformRelease(pr *cores.PlatformRelease) Index {
URL: pr.Platform.Package.URL,
Email: pr.Platform.Package.Email,
Platforms: []*indexPlatformRelease{{
Name: pr.Platform.Name,
Name: pr.Name,
Architecture: pr.Platform.Architecture,
Version: pr.Version,
Deprecated: pr.Platform.Deprecated,
Category: pr.Platform.Category,
Deprecated: pr.Deprecated,
Category: pr.Category,
URL: pr.Resource.URL,
ArchiveFileName: pr.Resource.ArchiveFileName,
Checksum: pr.Resource.Checksum,
Expand Down Expand Up @@ -263,18 +263,13 @@ func (inPackage indexPackage) extractPackageIn(outPackages cores.Packages, trust

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

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

Expand All @@ -283,6 +278,8 @@ func (inPlatformRelease indexPlatformRelease) extractPlatformIn(outPackage *core
return fmt.Errorf(tr("invalid platform archive size: %s"), err)
}
outPlatformRelease := outPlatform.GetOrCreateRelease(inPlatformRelease.Version)
outPlatformRelease.Name = inPlatformRelease.Name
outPlatformRelease.Category = inPlatformRelease.Category
outPlatformRelease.IsTrusted = trusted
outPlatformRelease.Resource = &resources.DownloadResource{
ArchiveFileName: inPlatformRelease.ArchiveFileName,
Expand All @@ -296,6 +293,7 @@ func (inPlatformRelease indexPlatformRelease) extractPlatformIn(outPackage *core
outPlatformRelease.ToolDependencies = inPlatformRelease.extractToolDependencies()
outPlatformRelease.DiscoveryDependencies = inPlatformRelease.extractDiscoveryDependencies()
outPlatformRelease.MonitorDependencies = inPlatformRelease.extractMonitorDependencies()
outPlatformRelease.Deprecated = inPlatformRelease.Deprecated
return nil
}

Expand Down
5 changes: 2 additions & 3 deletions arduino/cores/packageindex/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,10 @@ func TestIndexFromPlatformRelease(t *testing.T) {
Name: "serial-monitor",
},
},
Name: "Arduino AVR Boards",
Category: "Arduino",
Platform: &cores.Platform{
Name: "Arduino AVR Boards",
Architecture: "avr",
Category: "Arduino",

Package: &cores.Package{
Name: "arduino",
Maintainer: "Arduino",
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 @@ -323,14 +323,14 @@ func (pm *Builder) loadPlatformRelease(platform *cores.PlatformRelease, path *pa
platform.Properties.Set("pluggable_monitor.required.serial", "builtin:serial-monitor")
}

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

Expand Down
6 changes: 3 additions & 3 deletions arduino/cores/packagemanager/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ func (pme *Explorer) GetCustomGlobalProperties() *properties.Map {
}

// FindPlatformReleaseProvidingBoardsWithVidPid FIXMEDOC
func (pme *Explorer) FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid string) []*cores.PlatformRelease {
res := []*cores.PlatformRelease{}
func (pme *Explorer) FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid string) []*cores.Platform {
res := []*cores.Platform{}
for _, targetPackage := range pme.packages {
for _, targetPlatform := range targetPackage.Platforms {
platformRelease := targetPlatform.GetLatestRelease()
Expand All @@ -202,7 +202,7 @@ func (pme *Explorer) FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid strin
}
for _, boardManifest := range platformRelease.BoardsManifest {
if boardManifest.HasUsbID(vid, pid) {
res = append(res, platformRelease)
res = append(res, targetPlatform)
break
}
}
Expand Down
2 changes: 1 addition & 1 deletion arduino/cores/packagemanager/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (pmb *Builder) LoadHardwareForProfile(p *sketch.Profile, installMissing boo
logrus.WithField("platform", platformRef).WithError(err).Debugf("Error loading platform for profile")
} else {
platformReleases = append(platformReleases, platformRelease)
indexURLs[platformRelease.Platform.Name] = platformRef.PlatformIndexURL
indexURLs[platformRelease.Name] = platformRef.PlatformIndexURL
logrus.WithField("platform", platformRef).Debugf("Loaded platform for profile")
}
}
Expand Down
24 changes: 2 additions & 22 deletions client_example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ func main() {
log.Println("calling PlatformInstall(arduino:[email protected])")
callPlatformInstall(client, instance)

// Now list the installed platforms to double check previous installation
// went right.
log.Println("calling PlatformList()")
callPlatformList(client, instance)

// Upgrade the installed platform to the latest version.
log.Println("calling PlatformUpgrade(arduino:samd)")
callPlatformUpgrade(client, instance)
Expand Down Expand Up @@ -420,7 +415,7 @@ func callPlatformSearch(client rpc.ArduinoCoreServiceClient, instance *rpc.Insta
for _, plat := range platforms {
// We only print ID and version of the platforms found but you can look
// at the definition for the rpc.Platform struct for more fields.
log.Printf("Search result: %+v - %+v", plat.GetId(), plat.GetLatest())
log.Printf("Search result: %+v - %+v", plat.GetMetadata().GetId(), plat.GetLatestVersion())
}
}

Expand Down Expand Up @@ -464,21 +459,6 @@ func callPlatformInstall(client rpc.ArduinoCoreServiceClient, instance *rpc.Inst
}
}

func callPlatformList(client rpc.ArduinoCoreServiceClient, instance *rpc.Instance) {
listResp, err := client.PlatformList(context.Background(),
&rpc.PlatformListRequest{Instance: instance})

if err != nil {
log.Fatalf("List error: %s", err)
}

for _, plat := range listResp.GetInstalledPlatforms() {
// We only print ID and version of the installed platforms but you can look
// at the definition for the rpc.Platform struct for more fields.
log.Printf("Installed platform: %s - %s", plat.GetId(), plat.GetInstalled())
}
}

func callPlatformUpgrade(client rpc.ArduinoCoreServiceClient, instance *rpc.Instance) {
upgradeRespStream, err := client.PlatformUpgrade(context.Background(),
&rpc.PlatformUpgradeRequest{
Expand Down Expand Up @@ -546,7 +526,7 @@ func callBoardSearch(client rpc.ArduinoCoreServiceClient, instance *rpc.Instance
}

for _, board := range res.Boards {
log.Printf("Board Name: %s, Board Platform: %s\n", board.Name, board.Platform.Id)
log.Printf("Board Name: %s, Board Platform: %s\n", board.Name, board.Platform.Metadata.Id)
}
}

Expand Down
30 changes: 15 additions & 15 deletions commands/board/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai
return nil, &arduino.InvalidFQBNError{Cause: err}
}

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

details.DebuggingSupported = boardProperties.ContainsKey("debug.executable") ||
boardPlatform.Properties.ContainsKey("debug.executable") ||
boardPlatformRelease.Properties.ContainsKey("debug.executable") ||
(boardRefPlatform != nil && boardRefPlatform.Properties.ContainsKey("debug.executable")) ||
// HOTFIX: Remove me when the `arduino:samd` core is updated
boardPlatform.String() == "arduino:[email protected]" ||
boardPlatform.String() == "arduino:[email protected]"
boardPlatformRelease.String() == "arduino:[email protected]" ||
boardPlatformRelease.String() == "arduino:[email protected]"

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

details.Platform = &rpc.BoardPlatform{
Architecture: boardPlatform.Platform.Architecture,
Category: boardPlatform.Platform.Category,
Name: boardPlatform.Platform.Name,
Architecture: boardPlatformRelease.Platform.Architecture,
Category: boardPlatformRelease.Category,
Name: boardPlatformRelease.Name,
}

if boardPlatform.Resource != nil {
details.Platform.Url = boardPlatform.Resource.URL
details.Platform.ArchiveFilename = boardPlatform.Resource.ArchiveFileName
details.Platform.Checksum = boardPlatform.Resource.Checksum
details.Platform.Size = boardPlatform.Resource.Size
if boardPlatformRelease.Resource != nil {
details.Platform.Url = boardPlatformRelease.Resource.URL
details.Platform.ArchiveFilename = boardPlatformRelease.Resource.ArchiveFileName
details.Platform.Checksum = boardPlatformRelease.Resource.Checksum
details.Platform.Size = boardPlatformRelease.Resource.Size
}

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

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

details.Programmers = []*rpc.Programmer{}
for id, p := range boardPlatform.Programmers {
for id, p := range boardPlatformRelease.Programmers {
details.Programmers = append(details.Programmers, &rpc.Programmer{
Platform: boardPlatform.Platform.Name,
Platform: boardPlatformRelease.Name,
Id: id,
Name: p.Name,
})
Expand Down
6 changes: 4 additions & 2 deletions commands/board/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ func identify(pme *packagemanager.Explorer, port *discovery.Port) ([]*rpc.BoardL

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

// Put Arduino boards before others in case there are non Arduino boards with identical VID:PID combination
sort.SliceStable(boards, func(i, j int) bool {
if boards[i].Platform.Maintainer == "Arduino" && boards[j].Platform.Maintainer != "Arduino" {
if boards[i].Platform.Metadata.Maintainer == "Arduino" && boards[j].Platform.Metadata.Maintainer != "Arduino" {
return true
}
return false
Expand Down
22 changes: 4 additions & 18 deletions commands/board/listall.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/utils"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/internal/instances"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
)
Expand All @@ -46,29 +47,14 @@ func ListAll(ctx context.Context, req *rpc.BoardListAllRequest) (*rpc.BoardListA
continue
}

installedVersion := installedPlatformRelease.Version.String()

latestVersion := ""
if latestPlatformRelease := platform.GetLatestRelease(); latestPlatformRelease != nil {
latestVersion = latestPlatformRelease.Version.String()
}

rpcPlatform := &rpc.Platform{
Id: platform.String(),
Installed: installedVersion,
Latest: latestVersion,
Name: platform.Name,
Maintainer: platform.Package.Maintainer,
Website: platform.Package.WebsiteURL,
Email: platform.Package.Email,
ManuallyInstalled: platform.ManuallyInstalled,
Indexed: platform.Indexed,
MissingMetadata: !installedPlatformRelease.HasMetadata(),
Metadata: commands.PlatformToRPCPlatformMetadata(platform),
Release: commands.PlatformReleaseToRPC(installedPlatformRelease),
}

toTest := []string{
platform.String(),
platform.Name,
installedPlatformRelease.Name,
platform.Architecture,
targetPackage.Name,
targetPackage.Maintainer,
Expand Down
Loading