Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Nov 9, 2023
1 parent 36a5b2b commit 36a4e89
Show file tree
Hide file tree
Showing 18 changed files with 200 additions and 245 deletions.
2 changes: 1 addition & 1 deletion arduino/cores/packagemanager/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}

Expand Down
10 changes: 2 additions & 8 deletions arduino/cores/packagemanager/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion commands/board/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 6 additions & 16 deletions commands/core/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
47 changes: 14 additions & 33 deletions commands/core/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions internal/cli/arguments/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func GetUninstallableCores() []string {

platforms, _ := core.PlatformSearch(&rpc.PlatformSearchRequest{
Instance: inst,
AllVersions: false,
ManuallyInstalled: true,
})

Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions internal/cli/arguments/reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 2 additions & 3 deletions internal/cli/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 4 additions & 15 deletions internal/cli/core/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package core

import (
"fmt"
"os"

"github.com/arduino/arduino-cli/commands/core"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
17 changes: 7 additions & 10 deletions internal/cli/core/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down
17 changes: 8 additions & 9 deletions internal/cli/core/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
Loading

0 comments on commit 36a4e89

Please sign in to comment.