From d898eeac9556c7277f6d040493f1c1f729bbda83 Mon Sep 17 00:00:00 2001 From: Alessio Perugini Date: Thu, 9 Nov 2023 13:55:33 +0100 Subject: [PATCH] wip --- arduino/cores/packagemanager/download.go | 2 +- .../cores/packagemanager/package_manager.go | 10 +-- commands/board/search.go | 2 +- commands/core/search.go | 22 ++--- commands/core/search_test.go | 47 ++++------- internal/cli/arguments/completion.go | 6 +- internal/cli/arguments/reference.go | 3 +- internal/cli/compile/compile.go | 5 +- internal/cli/core/list.go | 19 +---- internal/cli/core/search.go | 17 ++-- internal/cli/core/upgrade.go | 17 ++-- internal/cli/feedback/result/rpc.go | 28 +++++++ internal/cli/upload/upload.go | 5 +- internal/integrationtest/arduino-cli.go | 5 +- internal/integrationtest/board/board_test.go | 82 ++++++++----------- internal/integrationtest/core/core_test.go | 74 ++++++++--------- rpc/cc/arduino/cli/commands/v1/core.pb.go | 48 ++++------- rpc/cc/arduino/cli/commands/v1/core.proto | 5 +- 18 files changed, 170 insertions(+), 227 deletions(-) diff --git a/arduino/cores/packagemanager/download.go b/arduino/cores/packagemanager/download.go index b7989b61729..43d13c11ea0 100644 --- a/arduino/cores/packagemanager/download.go +++ b/arduino/cores/packagemanager/download.go @@ -89,7 +89,7 @@ func (pme *Explorer) FindPlatformReleaseDependencies(item *PlatformReference) (* } else { release = platform.GetLatestCompatibleRelease() if release == nil { - return nil, nil, fmt.Errorf(tr("platform %s has no available releases for your OS"), platform.String()) + return nil, nil, fmt.Errorf(tr("platform is not available for your OS")) } } diff --git a/arduino/cores/packagemanager/package_manager.go b/arduino/cores/packagemanager/package_manager.go index 96251d93f4d..1f2b380e08a 100644 --- a/arduino/cores/packagemanager/package_manager.go +++ b/arduino/cores/packagemanager/package_manager.go @@ -229,20 +229,14 @@ func (pme *Explorer) GetCustomGlobalProperties() *properties.Map { } // FindPlatformReleaseProvidingBoardsWithVidPid FIXMEDOC -func (pme *Explorer) FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid string, showAllRelease bool) []*cores.Platform { +func (pme *Explorer) FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid string) []*cores.Platform { res := []*cores.Platform{} for _, targetPackage := range pme.packages { for _, targetPlatform := range targetPackage.Platforms { - var platformRelease *cores.PlatformRelease - if showAllRelease { - platformRelease = targetPlatform.GetLatestRelease() - } else { - platformRelease = targetPlatform.GetLatestCompatibleRelease() - } + platformRelease := targetPlatform.GetLatestRelease() if platformRelease == nil { continue } - for _, boardManifest := range platformRelease.BoardsManifest { if boardManifest.HasUsbID(vid, pid) { res = append(res, targetPlatform) diff --git a/commands/board/search.go b/commands/board/search.go index 007867775e3..bd8702504d7 100644 --- a/commands/board/search.go +++ b/commands/board/search.go @@ -41,7 +41,7 @@ func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchR foundBoards := []*rpc.BoardListItem{} for _, targetPackage := range pme.GetPackages() { for _, platform := range targetPackage.Platforms { - latestPlatformRelease := platform.GetLatestRelease() + latestPlatformRelease := platform.GetLatestCompatibleRelease() installedPlatformRelease := pme.GetInstalledPlatformRelease(platform) if latestPlatformRelease == nil && installedPlatformRelease == nil { diff --git a/commands/core/search.go b/commands/core/search.go index 0b42f1fa37f..c0341b40a91 100644 --- a/commands/core/search.go +++ b/commands/core/search.go @@ -39,7 +39,7 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse res := []*cores.Platform{} if isUsb, _ := regexp.MatchString("[0-9a-f]{4}:[0-9a-f]{4}", req.SearchArgs); isUsb { vid, pid := req.SearchArgs[:4], req.SearchArgs[5:] - res = pme.FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid, req.AllVersions) + res = pme.FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid) } else { searchArgs := utils.SearchTermsFromQueryString(req.SearchArgs) for _, targetPackage := range pme.GetPackages() { @@ -53,14 +53,8 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse continue } - // In case we ask for all versions we also show incompatible ones - var latestRelease *cores.PlatformRelease - if req.AllVersions { - latestRelease = platform.GetLatestRelease() - } else { - latestRelease = platform.GetLatestCompatibleRelease() - } // Discard platforms with no releases + latestRelease := platform.GetLatestRelease() if latestRelease == nil || latestRelease.Name == "" { continue } @@ -94,24 +88,20 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse } if installed := pme.GetInstalledPlatformRelease(platform); installed != nil { rpcPlatformSummary.InstalledVersion = installed.Version.String() - rpcPlatformSummary.Releases[installed.Version.String()] = commands.PlatformReleaseToRPC(installed) } if latestCompatible := platform.GetLatestCompatibleRelease(); latestCompatible != nil { rpcPlatformSummary.LatestVersion = latestCompatible.Version.String() - rpcPlatformSummary.Releases[latestCompatible.Version.String()] = commands.PlatformReleaseToRPC(latestCompatible) } - if req.AllVersions { - for _, platformRelease := range platform.GetAllReleases() { - rpcPlatformRelease := commands.PlatformReleaseToRPC(platformRelease) - rpcPlatformSummary.Releases[rpcPlatformRelease.Version] = rpcPlatformRelease - } + for _, platformRelease := range platform.GetAllReleases() { + rpcPlatformRelease := commands.PlatformReleaseToRPC(platformRelease) + rpcPlatformSummary.Releases[rpcPlatformRelease.Version] = rpcPlatformRelease } out = append(out, rpcPlatformSummary) } // Sort result alphabetically and put deprecated platforms at the bottom sort.Slice(out, func(i, j int) bool { - return strings.ToLower(out[i].GetLatestRelease().GetName()) < strings.ToLower(out[j].GetLatestRelease().GetName()) + return strings.ToLower(out[i].GetMetadata().GetId()) < strings.ToLower(out[j].GetMetadata().GetId()) }) sort.SliceStable(out, func(i, j int) bool { return !out[i].GetMetadata().Deprecated && out[j].GetMetadata().Deprecated diff --git a/commands/core/search_test.go b/commands/core/search_test.go index 60f3f91a72a..ea3fdc4ef9d 100644 --- a/commands/core/search_test.go +++ b/commands/core/search_test.go @@ -43,9 +43,8 @@ func TestPlatformSearch(t *testing.T) { t.Run("SearchAllVersions", func(t *testing.T) { res, stat := PlatformSearch(&rpc.PlatformSearchRequest{ - Instance: inst, - SearchArgs: "retrokit", - AllVersions: true, + Instance: inst, + SearchArgs: "retrokit", }) require.Nil(t, stat) require.NotNil(t, res) @@ -83,23 +82,10 @@ func TestPlatformSearch(t *testing.T) { }) }) - t.Run("SearchNoAllVersions", func(t *testing.T) { - // This platform doesn't contain any installable release - res, stat := PlatformSearch(&rpc.PlatformSearchRequest{ - Instance: inst, - SearchArgs: "retrokit", - AllVersions: false, - }) - require.Nil(t, stat) - require.NotNil(t, res) - require.Empty(t, res.SearchOutput) - }) - t.Run("SearchThePackageMaintainer", func(t *testing.T) { res, stat := PlatformSearch(&rpc.PlatformSearchRequest{ - Instance: inst, - SearchArgs: "Retrokits (www.retrokits.com)", - AllVersions: true, + Instance: inst, + SearchArgs: "Retrokits (www.retrokits.com)", }) require.Nil(t, stat) require.NotNil(t, res) @@ -138,9 +124,8 @@ func TestPlatformSearch(t *testing.T) { t.Run("SearchPackageName", func(t *testing.T) { res, stat := PlatformSearch(&rpc.PlatformSearchRequest{ - Instance: inst, - SearchArgs: "Retrokits-RK002", - AllVersions: true, + Instance: inst, + SearchArgs: "Retrokits-RK002", }) require.Nil(t, stat) require.NotNil(t, res) @@ -179,9 +164,8 @@ func TestPlatformSearch(t *testing.T) { t.Run("SearchPlatformName", func(t *testing.T) { res, stat := PlatformSearch(&rpc.PlatformSearchRequest{ - Instance: inst, - SearchArgs: "rk002", - AllVersions: true, + Instance: inst, + SearchArgs: "rk002", }) require.Nil(t, stat) require.NotNil(t, res) @@ -220,9 +204,8 @@ func TestPlatformSearch(t *testing.T) { t.Run("SearchBoardName", func(t *testing.T) { res, stat := PlatformSearch(&rpc.PlatformSearchRequest{ - Instance: inst, - SearchArgs: "Yún", - AllVersions: true, + Instance: inst, + SearchArgs: "Yún", }) require.Nil(t, stat) require.NotNil(t, res) @@ -279,9 +262,8 @@ func TestPlatformSearch(t *testing.T) { t.Run("SearchBoardName2", func(t *testing.T) { res, stat := PlatformSearch(&rpc.PlatformSearchRequest{ - Instance: inst, - SearchArgs: "yun", - AllVersions: true, + Instance: inst, + SearchArgs: "yun", }) require.Nil(t, stat) require.NotNil(t, res) @@ -354,9 +336,8 @@ func TestPlatformSearchSorting(t *testing.T) { require.NotNil(t, inst) res, stat := PlatformSearch(&rpc.PlatformSearchRequest{ - Instance: inst, - SearchArgs: "", - AllVersions: true, + Instance: inst, + SearchArgs: "", }) require.Nil(t, stat) require.NotNil(t, res) diff --git a/internal/cli/arguments/completion.go b/internal/cli/arguments/completion.go index b5c6d8f455f..89423edd1a7 100644 --- a/internal/cli/arguments/completion.go +++ b/internal/cli/arguments/completion.go @@ -85,7 +85,6 @@ func GetUninstallableCores() []string { platforms, _ := core.PlatformSearch(&rpc.PlatformSearchRequest{ Instance: inst, - AllVersions: false, ManuallyInstalled: true, }) @@ -106,9 +105,8 @@ func GetInstallableCores() []string { inst := instance.CreateAndInit() platforms, _ := core.PlatformSearch(&rpc.PlatformSearchRequest{ - Instance: inst, - SearchArgs: "", - AllVersions: false, + Instance: inst, + SearchArgs: "", }) var res []string // transform the data structure for the completion diff --git a/internal/cli/arguments/reference.go b/internal/cli/arguments/reference.go index f9d8737d415..ed6152af5b8 100644 --- a/internal/cli/arguments/reference.go +++ b/internal/cli/arguments/reference.go @@ -96,8 +96,7 @@ func ParseReference(arg string) (*Reference, error) { // try to use core.PlatformList to optimize what the user typed // (by replacing the PackageName and Architecture in ret with the content of core.GetPlatform()) platforms, _ := core.PlatformSearch(&rpc.PlatformSearchRequest{ - Instance: instance.CreateAndInit(), - AllVersions: false, + Instance: instance.CreateAndInit(), }) foundPlatforms := []string{} for _, platform := range platforms.GetSearchOutput() { diff --git a/internal/cli/compile/compile.go b/internal/cli/compile/compile.go index 1204b529f17..7cd66de7663 100644 --- a/internal/cli/compile/compile.go +++ b/internal/cli/compile/compile.go @@ -370,9 +370,8 @@ func runCompileCommand(cmd *cobra.Command, args []string) { res.Error += fmt.Sprintln() if platform, err := core.PlatformSearch(&rpc.PlatformSearchRequest{ - Instance: inst, - SearchArgs: platformErr.Platform, - AllVersions: false, + Instance: inst, + SearchArgs: platformErr.Platform, }); err != nil { res.Error += err.Error() } else if len(platform.GetSearchOutput()) > 0 { diff --git a/internal/cli/core/list.go b/internal/cli/core/list.go index 58f8d6f8c82..40ac933f027 100644 --- a/internal/cli/core/list.go +++ b/internal/cli/core/list.go @@ -16,7 +16,6 @@ package core import ( - "fmt" "os" "github.com/arduino/arduino-cli/commands/core" @@ -63,7 +62,6 @@ func List(inst *rpc.Instance, all bool, updatableOnly bool) { func GetList(inst *rpc.Instance, all bool, updatableOnly bool) []*rpc.PlatformSummary { platforms, err := core.PlatformSearch(&rpc.PlatformSearchRequest{ Instance: inst, - AllVersions: true, ManuallyInstalled: true, }) if err != nil { @@ -117,20 +115,11 @@ func (ir coreListResult) String() string { t := table.New() t.SetHeader(tr("ID"), tr("Installed"), tr("Latest"), tr("Name")) for _, platform := range ir.platforms { - var name string - if installed := platform.GetInstalledRelease(); installed != nil { - name = installed.Name + latestVersion := platform.LatestVersion.String() + if latestVersion == "" { + latestVersion = "n/a" } - if name == "" { - if latest := platform.GetLatestRelease(); latest != nil { - name = latest.Name - } - } - if platform.Deprecated { - name = fmt.Sprintf("[%s] %s", tr("DEPRECATED"), name) - } - - t.AddRow(platform.Id, platform.InstalledVersion, platform.LatestVersion, name) + t.AddRow(platform.Id, platform.InstalledVersion, latestVersion, platform.GetPlatformName()) } return t.Render() diff --git a/internal/cli/core/search.go b/internal/cli/core/search.go index e1f0cd67444..0fc2389cdd8 100644 --- a/internal/cli/core/search.go +++ b/internal/cli/core/search.go @@ -72,9 +72,8 @@ func runSearchCommand(cmd *cobra.Command, args []string, allVersions bool) { logrus.Infof("Executing `arduino-cli core search` with args: '%s'", arguments) resp, err := core.PlatformSearch(&rpc.PlatformSearchRequest{ - Instance: inst, - SearchArgs: arguments, - AllVersions: allVersions, + Instance: inst, + SearchArgs: arguments, }) if err != nil { feedback.Fatal(tr("Error searching for platforms: %v", err), feedback.ErrGeneric) @@ -115,19 +114,17 @@ func (sr searchResults) String() string { t.SetHeader(tr("ID"), tr("Version"), tr("Name")) addRow := func(platform *result.PlatformSummary, release *result.PlatformRelease) { - name := release.Name - if release.Deprecated { - name = fmt.Sprintf("[%s] %s", tr("DEPRECATED"), release.Name) + if release == nil { + t.AddRow(platform.Id, "n/a", platform.GetPlatformName()) + return } - t.AddRow(platform.Id, release.Version, name) + t.AddRow(platform.Id, release.Version, release.FormatName()) } for _, platform := range sr.platforms { // When allVersions is not requested we only show the latest compatible version if !sr.allVersions { - if latest := platform.GetLatestRelease(); latest != nil { - addRow(platform, latest) - } + addRow(platform, platform.GetLatestRelease()) continue } diff --git a/internal/cli/core/upgrade.go b/internal/cli/core/upgrade.go index b73769622bf..93bc6c0720f 100644 --- a/internal/cli/core/upgrade.go +++ b/internal/cli/core/upgrade.go @@ -61,8 +61,7 @@ func Upgrade(inst *rpc.Instance, args []string, skipPostInstall bool, skipPreUni // if no platform was passed, upgrade allthethings if len(args) == 0 { platforms, err := core.PlatformSearch(&rpc.PlatformSearchRequest{ - Instance: inst, - AllVersions: false, + Instance: inst, }) if err != nil { feedback.Fatal(tr("Error retrieving core list: %v", err), feedback.ErrGeneric) @@ -73,14 +72,14 @@ func Upgrade(inst *rpc.Instance, args []string, skipPostInstall bool, skipPreUni if platform.InstalledVersion == "" { continue } - if platform.InstalledVersion == platform.GetLatestVersion() { - // if it's not updatable, skip it - continue + // if it's not updatable, skip it + latestRelease := platform.GetLatestRelease() + if latestRelease != nil && platform.InstalledVersion != latestRelease.Version { + targets = append(targets, &rpc.Platform{ + Metadata: platform.GetMetadata(), + Release: latestRelease, + }) } - targets = append(targets, &rpc.Platform{ - Metadata: platform.GetMetadata(), - Release: platform.GetLatestRelease(), - }) } if len(targets) == 0 { diff --git a/internal/cli/feedback/result/rpc.go b/internal/cli/feedback/result/rpc.go index f60b8fee98f..63291754fe7 100644 --- a/internal/cli/feedback/result/rpc.go +++ b/internal/cli/feedback/result/rpc.go @@ -17,13 +17,17 @@ package result import ( "cmp" + "fmt" + "github.com/arduino/arduino-cli/i18n" f "github.com/arduino/arduino-cli/internal/algorithms" "github.com/arduino/arduino-cli/internal/orderedmap" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" semver "go.bug.st/relaxed-semver" ) +var tr = i18n.Tr + // NewPlatformSummary creates a new result.PlatformSummary from rpc.PlatformSummary func NewPlatformSummary(in *rpc.PlatformSummary) *PlatformSummary { if in == nil { @@ -76,6 +80,23 @@ func (p *PlatformSummary) GetInstalledRelease() *PlatformRelease { return p.Releases.Get(p.InstalledVersion) } +// GetPlatformName compute the name of the platform based on the installed/available releases. +func (p *PlatformSummary) GetPlatformName() string { + var name string + if installed := p.GetInstalledRelease(); installed != nil { + name = installed.FormatName() + } + if name == "" { + if latest := p.GetLatestRelease(); latest != nil { + name = latest.FormatName() + } else { + keys := p.Releases.Keys() + name = p.Releases.Get(keys[len(keys)-1]).FormatName() + } + } + return name +} + // NewPlatformRelease creates a new result.PlatformRelease from rpc.PlatformRelease func NewPlatformRelease(in *rpc.PlatformRelease) *PlatformRelease { if in == nil { @@ -121,6 +142,13 @@ type PlatformRelease struct { Compatible bool `json:"compatible"` } +func (p *PlatformRelease) FormatName() string { + if p.Deprecated { + return fmt.Sprintf("[%s] %s", tr("DEPRECATED"), p.Name) + } + return p.Name +} + // Board maps a rpc.Board type Board struct { Name string `json:"name,omitempty"` diff --git a/internal/cli/upload/upload.go b/internal/cli/upload/upload.go index 73e6166aaaa..7bbc868bf9b 100644 --- a/internal/cli/upload/upload.go +++ b/internal/cli/upload/upload.go @@ -138,9 +138,8 @@ func runUploadCommand(args []string, uploadFieldsArgs map[string]string) { msg += "\n" if platform, err := core.PlatformSearch(&rpc.PlatformSearchRequest{ - Instance: inst, - SearchArgs: platformErr.Platform, - AllVersions: false, + Instance: inst, + SearchArgs: platformErr.Platform, }); err != nil { msg += err.Error() } else if len(platform.GetSearchOutput()) > 0 { diff --git a/internal/integrationtest/arduino-cli.go b/internal/integrationtest/arduino-cli.go index 78ed4dbb3e9..c2b10f7e121 100644 --- a/internal/integrationtest/arduino-cli.go +++ b/internal/integrationtest/arduino-cli.go @@ -576,9 +576,8 @@ func (inst *ArduinoCLIInstance) PlatformUpgrade(ctx context.Context, packager, a // PlatformSearch calls the "PlatformSearch" gRPC method. func (inst *ArduinoCLIInstance) PlatformSearch(ctx context.Context, args string, all bool) (*commands.PlatformSearchResponse, error) { req := &commands.PlatformSearchRequest{ - Instance: inst.instance, - SearchArgs: args, - AllVersions: all, + Instance: inst.instance, + SearchArgs: args, } logCallf(">>> PlatformSearch(%+v)\n", req) resp, err := inst.cli.daemonClient.PlatformSearch(ctx, req) diff --git a/internal/integrationtest/board/board_test.go b/internal/integrationtest/board/board_test.go index 70c53de9039..2faadee644e 100644 --- a/internal/integrationtest/board/board_test.go +++ b/internal/integrationtest/board/board_test.go @@ -16,7 +16,6 @@ package board_test import ( - "encoding/json" "os" "strings" "testing" @@ -25,7 +24,6 @@ import ( "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" "github.com/stretchr/testify/require" - semver "go.bug.st/relaxed-semver" "go.bug.st/testifyjson/requirejson" ) @@ -182,26 +180,36 @@ func TestBoardListall(t *testing.T) { "name": "Arduino Yún", "fqbn": "arduino:avr:yun", "platform": { - "id": "arduino:avr", - "installed": "1.8.3", - "name": "Arduino AVR Boards" + "metadata": { + "id": "arduino:avr" + }, + "release": { + "name": "Arduino AVR Boards", + "version": "1.8.3", + "installed": true + } } }, { "name": "Arduino Uno", "fqbn": "arduino:avr:uno", "platform": { - "id": "arduino:avr", - "installed": "1.8.3", - "name": "Arduino AVR Boards" + "metadata": { + "id": "arduino:avr" + }, + "release": { + "name": "Arduino AVR Boards", + "version": "1.8.3", + "installed": true + } } } ] }`) - // Check if the boards' "latest" value is not empty + // Check if the boards' "version" value is not empty requirejson.Parse(t, stdout). - Query(`[ .boards | .[] | .platform | select(.latest == "") ]`). + Query(`[ .boards | .[] | .platform | select(.version == "") ]`). MustBeEmpty() } @@ -232,20 +240,28 @@ func TestBoardListallWithManuallyInstalledPlatform(t *testing.T) { "name": "Arduino MKR1000", "fqbn": "arduino-beta-development:samd:mkr1000", "platform": { - "id": "arduino-beta-development:samd", - "installed": "1.8.11", - "latest": "1.8.11", - "name": "Arduino SAMD (32-bits ARM Cortex-M0+) Boards", + "metadata": { + "id": "arduino-beta-development:samd", + }, + "release": { + "installed": true, + "version": "1.8.11", + "name": "Arduino SAMD (32-bits ARM Cortex-M0+) Boards" + }, } }, { "name": "Arduino NANO 33 IoT", "fqbn": "arduino-beta-development:samd:nano_33_iot", "platform": { - "id": "arduino-beta-development:samd", - "installed": "1.8.11", - "latest": "1.8.11", - "name": "Arduino SAMD (32-bits ARM Cortex-M0+) Boards" + "metadata": { + "id": "arduino-beta-development:samd", + }, + "release": { + "installed": true, + "version": "1.8.11", + "name": "Arduino SAMD (32-bits ARM Cortex-M0+) Boards" + }, } } ] @@ -575,36 +591,6 @@ func TestBoardAttach(t *testing.T) { } } -func TestBoardSearchWithOutdatedCore(t *testing.T) { - env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) - defer env.CleanUp() - - _, _, err := cli.Run("update") - require.NoError(t, err) - - // Install an old core version - _, _, err = cli.Run("core", "install", "arduino:samd@1.8.6") - require.NoError(t, err) - - stdout, _, err := cli.Run("board", "search", "arduino:samd:mkrwifi1010", "--format", "json") - require.NoError(t, err) - requirejson.Len(t, stdout, 1) - var data []map[string]interface{} - err = json.Unmarshal(stdout, &data) - require.NoError(t, err) - board := data[0] - require.Equal(t, board["name"], "Arduino MKR WiFi 1010") - require.Equal(t, board["fqbn"], "arduino:samd:mkrwifi1010") - samdCore := board["platform"].(map[string]interface{}) - require.Equal(t, samdCore["id"], "arduino:samd") - installedVersion, err := semver.Parse(samdCore["installed"].(string)) - require.NoError(t, err) - latestVersion, err := semver.Parse(samdCore["latest"].(string)) - require.NoError(t, err) - // Installed version must be older than latest - require.True(t, installedVersion.LessThan(latestVersion)) -} - func TestBoardListWithFailedBuiltinInstallation(t *testing.T) { env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) defer env.CleanUp() diff --git a/internal/integrationtest/core/core_test.go b/internal/integrationtest/core/core_test.go index 1763f87eb4f..2dc2beefe68 100644 --- a/internal/integrationtest/core/core_test.go +++ b/internal/integrationtest/core/core_test.go @@ -1111,12 +1111,6 @@ func TestCoreListWhenNoPlatformAreInstalled(t *testing.T) { } func TestCoreHavingIncompatibleDepTools(t *testing.T) { - /** - The `core list`, `core search`, and the combiation of `--all` have slightly different behaviour in how the - populate the `releases` field. - - `core list`, `core list --all`, and `core search --all` always shows every existent platform versions. - - `core search` shows upmost 2 versions: the currently installed and the newer installable one. - **/ env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) defer env.CleanUp() @@ -1126,7 +1120,7 @@ func TestCoreHavingIncompatibleDepTools(t *testing.T) { _, _, err := cli.Run("core", "update-index", additionalURLs) require.NoError(t, err) - // the `latest_version` must point to an installable release. In the releases field the latest entry points to an incompatible version. + // the `latest_version` must point to an installable release. In the releases field the latest entry, points to an incompatible version. stdout, _, err := cli.Run("core", "list", "--all", "--format", "json", additionalURLs) require.NoError(t, err) requirejson.Parse(t, stdout). @@ -1154,7 +1148,7 @@ func TestCoreHavingIncompatibleDepTools(t *testing.T) { "releases": {"1.0.1": {"compatible": true}} }`) - // install incompatible version + // install a specific incompatible version _, stderr, err := cli.Run("core", "install", "foo_vendor:avr@1.0.2", additionalURLs) require.Error(t, err) require.Contains(t, string(stderr), "no versions available for the current OS") @@ -1202,35 +1196,41 @@ func TestCoreHavingIncompatibleDepTools(t *testing.T) { // When trying to install a platform with no compatible version fails _, stderr, err = cli.Run("core", "install", "incompatible_vendor:avr", additionalURLs) require.Error(t, err) - //require.Contains(t, string(stderr), "has no available releases for your OS") - require.Contains(t, string(stderr), "Invalid argument passed: Platform 'incompatible_vendor:avr' not found") + require.Contains(t, string(stderr), "is not available for your OS") - // Core search --all shows all the releases even the incompatible ones - stdout, _, err = cli.Run("core", "search", "--all", "--format", "json", additionalURLs) - require.NoError(t, err) - requirejson.Parse(t, stdout). - Query(`.[] | select(.id == "foo_vendor:avr")`). - MustContain(`{"releases": { - "1.0.0": {"compatible": true}, - "1.0.1": {"compatible": true}, - "1.0.2": {"compatible": false} - }}`) - - // Core search shows only cores that contains at least 1 installable release - stdout, _, err = cli.Run("core", "search", "--format", "json", additionalURLs) - require.NoError(t, err) - requirejson.Parse(t, stdout).Query(`[.[] | select(.id == "incompatible_vendor:avr")]`).MustBeEmpty() - requirejson.Query(t, stdout, `.[] | select(.id == "foo_vendor:avr") | .releases | length`, `1`) - requirejson.Parse(t, stdout). - Query(`.[] | select(.id == "foo_vendor:avr") | .releases[.latest_version]`). - MustContain(`{"version":"1.0.1", "compatible":true}`) - - // In text mode, core search doesn't show any version if no compatible one are present - stdout, _, err = cli.Run("core", "search", additionalURLs) - require.NoError(t, err) - var lines [][]string - for _, v := range strings.Split(strings.TrimSpace(string(stdout)), "\n") { - lines = append(lines, strings.Fields(strings.TrimSpace(v))) + // Core search + { + // core search with and without --all produces the same results. + stdoutSearchAll, _, err := cli.Run("core", "search", "--all", "--format", "json", additionalURLs) + require.NoError(t, err) + stdoutSearch, _, err := cli.Run("core", "search", "--format", "json", additionalURLs) + require.NoError(t, err) + require.Equal(t, stdoutSearchAll, stdoutSearch) + for _, stdout := range [][]byte{stdoutSearchAll, stdoutSearch} { + requirejson.Parse(t, stdout). + Query(`.[] | select(.id == "foo_vendor:avr")`). + MustContain(`{ + "latest_version": "1.0.1", + "releases": { + "1.0.0": {"compatible": true}, + "1.0.1": {"compatible": true}, + "1.0.2": {"compatible": false} + } + }`) + requirejson.Parse(t, stdout). + Query(`.[] | select(.id == "incompatible_vendor:avr")`). + MustContain(`{"latest_version": "", "releases": { "1.0.0": {"compatible": false}}}`) + } + // In text mode, core search shows `n/a` for core that doesn't have any compatible version + stdout, _, err := cli.Run("core", "search", additionalURLs) + require.NoError(t, err) + var lines [][]string + for _, v := range strings.Split(strings.TrimSpace(string(stdout)), "\n") { + lines = append(lines, strings.Fields(strings.TrimSpace(v))) + if strings.Contains(v, "incompatible_vendor:avr") { + t.Log(strings.Fields(strings.TrimSpace(v))) + } + } + require.Contains(t, lines, []string{"incompatible_vendor:avr", "n/a", "Incompatible", "Boards"}) } - require.NotContains(t, lines, []string{"incompatible_vendor:avr"}) } diff --git a/rpc/cc/arduino/cli/commands/v1/core.pb.go b/rpc/cc/arduino/cli/commands/v1/core.pb.go index dca289c80fd..6c3bcb7c5ed 100644 --- a/rpc/cc/arduino/cli/commands/v1/core.pb.go +++ b/rpc/cc/arduino/cli/commands/v1/core.pb.go @@ -682,12 +682,9 @@ type PlatformSearchRequest struct { Instance *Instance `protobuf:"bytes,1,opt,name=instance,proto3" json:"instance,omitempty"` // Keywords for the search. SearchArgs string `protobuf:"bytes,2,opt,name=search_args,json=searchArgs,proto3" json:"search_args,omitempty"` - // Whether to show all available versions. `false` causes only the newest - // versions of the cores to be listed in the search results. - AllVersions bool `protobuf:"varint,3,opt,name=all_versions,json=allVersions,proto3" json:"all_versions,omitempty"` // Whether to show manually installed platforms. `false` causes to skip // manually installed platforms. - ManuallyInstalled bool `protobuf:"varint,4,opt,name=manually_installed,json=manuallyInstalled,proto3" json:"manually_installed,omitempty"` + ManuallyInstalled bool `protobuf:"varint,3,opt,name=manually_installed,json=manuallyInstalled,proto3" json:"manually_installed,omitempty"` } func (x *PlatformSearchRequest) Reset() { @@ -736,13 +733,6 @@ func (x *PlatformSearchRequest) GetSearchArgs() string { return "" } -func (x *PlatformSearchRequest) GetAllVersions() bool { - if x != nil { - return x.AllVersions - } - return false -} - func (x *PlatformSearchRequest) GetManuallyInstalled() bool { if x != nil { return x.ManuallyInstalled @@ -913,7 +903,7 @@ var file_cc_arduino_cli_commands_v1_core_proto_rawDesc = []byte{ 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x6c, 0x61, 0x74, 0x66, - 0x6f, 0x72, 0x6d, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x22, 0xcc, 0x01, + 0x6f, 0x72, 0x6d, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x22, 0xa9, 0x01, 0x0a, 0x15, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x40, 0x0a, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x63, 0x63, 0x2e, 0x61, @@ -921,24 +911,22 @@ var file_cc_arduino_cli_commands_v1_core_proto_rawDesc = []byte{ 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, 0x61, 0x72, 0x67, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, - 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x41, 0x72, 0x67, 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x6c, - 0x6c, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, - 0x52, 0x0b, 0x61, 0x6c, 0x6c, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x2d, 0x0a, - 0x12, 0x6d, 0x61, 0x6e, 0x75, 0x61, 0x6c, 0x6c, 0x79, 0x5f, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6c, - 0x6c, 0x65, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x11, 0x6d, 0x61, 0x6e, 0x75, 0x61, - 0x6c, 0x6c, 0x79, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x22, 0x6a, 0x0a, 0x16, - 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x50, 0x0a, 0x0d, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, - 0x5f, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2b, 0x2e, - 0x63, 0x63, 0x2e, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, - 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x6c, 0x61, 0x74, 0x66, - 0x6f, 0x72, 0x6d, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x52, 0x0c, 0x73, 0x65, 0x61, 0x72, - 0x63, 0x68, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x42, 0x48, 0x5a, 0x46, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2f, 0x61, - 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2d, 0x63, 0x6c, 0x69, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x63, - 0x63, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2f, 0x63, 0x6c, 0x69, 0x2f, 0x63, 0x6f, - 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, - 0x64, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x41, 0x72, 0x67, 0x73, 0x12, 0x2d, 0x0a, 0x12, 0x6d, 0x61, + 0x6e, 0x75, 0x61, 0x6c, 0x6c, 0x79, 0x5f, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x65, 0x64, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x11, 0x6d, 0x61, 0x6e, 0x75, 0x61, 0x6c, 0x6c, 0x79, + 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x22, 0x6a, 0x0a, 0x16, 0x50, 0x6c, 0x61, + 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x50, 0x0a, 0x0d, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x5f, 0x6f, 0x75, + 0x74, 0x70, 0x75, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2b, 0x2e, 0x63, 0x63, 0x2e, + 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2e, 0x63, 0x6c, 0x69, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, + 0x61, 0x6e, 0x64, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, + 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x52, 0x0c, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x4f, + 0x75, 0x74, 0x70, 0x75, 0x74, 0x42, 0x48, 0x5a, 0x46, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, + 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2f, 0x61, 0x72, 0x64, 0x75, + 0x69, 0x6e, 0x6f, 0x2d, 0x63, 0x6c, 0x69, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x63, 0x63, 0x2f, 0x61, + 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2f, 0x63, 0x6c, 0x69, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, + 0x6e, 0x64, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/rpc/cc/arduino/cli/commands/v1/core.proto b/rpc/cc/arduino/cli/commands/v1/core.proto index 67aa0b214c7..e44331dada8 100644 --- a/rpc/cc/arduino/cli/commands/v1/core.proto +++ b/rpc/cc/arduino/cli/commands/v1/core.proto @@ -115,12 +115,9 @@ message PlatformSearchRequest { Instance instance = 1; // Keywords for the search. string search_args = 2; - // Whether to show all available versions. `false` causes only the newest - // versions of the cores to be listed in the search results. - bool all_versions = 3; // Whether to show manually installed platforms. `false` causes to skip // manually installed platforms. - bool manually_installed = 4; + bool manually_installed = 3; } message PlatformSearchResponse {