Skip to content

Commit

Permalink
cr: remove latest_compatible_version from gRPC api.
Browse files Browse the repository at this point in the history
We leave only the `latest_compatible` field from the API. This field
will have the same meaning the the former `latest_compatible_version`.
Meaning that if the `latest_compatible` contains a version it is a
release that can be installed. However it might happen that we have
newer releases that cannot be installed. If the client is interested to
show newer-non-installable-releases, the `releases` field can be used to
infer that.
  • Loading branch information
alessio-perugini committed Nov 8, 2023
1 parent d3c7d95 commit 679f014
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 204 deletions.
10 changes: 8 additions & 2 deletions arduino/cores/packagemanager/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,20 @@ func (pme *Explorer) GetCustomGlobalProperties() *properties.Map {
}

// FindPlatformReleaseProvidingBoardsWithVidPid FIXMEDOC
func (pme *Explorer) FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid string) []*cores.Platform {
func (pme *Explorer) FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid string, showAllRelease bool) []*cores.Platform {
res := []*cores.Platform{}
for _, targetPackage := range pme.packages {
for _, targetPlatform := range targetPackage.Platforms {
platformRelease := targetPlatform.GetLatestRelease()
var platformRelease *cores.PlatformRelease
if showAllRelease {
platformRelease = targetPlatform.GetLatestRelease()
} else {
platformRelease = targetPlatform.GetLatestCompatibleRelease()
}
if platformRelease == nil {
continue
}

for _, boardManifest := range platformRelease.BoardsManifest {
if boardManifest.HasUsbID(vid, pid) {
res = append(res, targetPlatform)
Expand Down
24 changes: 11 additions & 13 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)
res = pme.FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid, req.AllVersions)
} else {
searchArgs := utils.SearchTermsFromQueryString(req.SearchArgs)
for _, targetPackage := range pme.GetPackages() {
Expand All @@ -53,12 +53,15 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
continue
}

// Discard platforms with no releases
latestRelease := platform.GetLatestRelease()
if latestRelease == nil {
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()
}
if latestRelease.Name == "" {
// Discard platforms with no releases
if latestRelease == nil || latestRelease.Name == "" {
continue
}

Expand Down Expand Up @@ -93,12 +96,8 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
rpcPlatformSummary.InstalledVersion = installed.Version.String()
rpcPlatformSummary.Releases[installed.Version.String()] = commands.PlatformReleaseToRPC(installed)
}
if latest := platform.GetLatestRelease(); latest != nil {
rpcPlatformSummary.LatestVersion = latest.Version.String()
rpcPlatformSummary.Releases[latest.Version.String()] = commands.PlatformReleaseToRPC(latest)
}
if latestCompatible := platform.GetLatestCompatibleRelease(); latestCompatible != nil {
rpcPlatformSummary.LatestCompatibleVersion = latestCompatible.Version.String()
rpcPlatformSummary.LatestVersion = latestCompatible.Version.String()
rpcPlatformSummary.Releases[latestCompatible.Version.String()] = commands.PlatformReleaseToRPC(latestCompatible)
}
if req.AllVersions {
Expand All @@ -112,8 +111,7 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse

// 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].GetLatestRelease().GetName()) < strings.ToLower(out[j].GetLatestRelease().GetName())
})
sort.SliceStable(out, func(i, j int) bool {
return !out[i].GetMetadata().Deprecated && out[j].GetMetadata().Deprecated
Expand Down
37 changes: 5 additions & 32 deletions commands/core/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,41 +80,19 @@ func TestPlatformSearch(t *testing.T) {
},
},
InstalledVersion: "",
LatestVersion: "1.0.6",
})
})

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.Len(t, res.SearchOutput, 1)
require.Contains(t, res.SearchOutput, &rpc.PlatformSummary{
Metadata: &rpc.PlatformMetadata{
Id: "Retrokits-RK002:arm",
Maintainer: "Retrokits (www.retrokits.com)",
Website: "https://www.retrokits.com",
Email: "[email protected]",
Indexed: true,
},
Releases: map[string]*rpc.PlatformRelease{
"1.0.6": {
Name: "RK002",
Type: []string{"Contributed"},
Installed: false,
Version: "1.0.6",
Boards: []*rpc.Board{{Name: "RK002"}},
Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"},
Compatible: false,
},
},
InstalledVersion: "",
LatestVersion: "1.0.6",
})
require.Empty(t, res.SearchOutput)
})

t.Run("SearchThePackageMaintainer", func(t *testing.T) {
Expand Down Expand Up @@ -155,7 +133,6 @@ func TestPlatformSearch(t *testing.T) {
},
},
InstalledVersion: "",
LatestVersion: "1.0.6",
})
})

Expand Down Expand Up @@ -197,7 +174,6 @@ func TestPlatformSearch(t *testing.T) {
},
},
InstalledVersion: "",
LatestVersion: "1.0.6",
})
})

Expand Down Expand Up @@ -239,7 +215,6 @@ func TestPlatformSearch(t *testing.T) {
},
},
InstalledVersion: "",
LatestVersion: "1.0.6",
})
})

Expand Down Expand Up @@ -299,7 +274,6 @@ func TestPlatformSearch(t *testing.T) {
},
},
InstalledVersion: "",
LatestVersion: "1.8.3",
})
})

Expand Down Expand Up @@ -359,7 +333,6 @@ func TestPlatformSearch(t *testing.T) {
},
},
InstalledVersion: "",
LatestVersion: "1.8.3",
})
})
}
Expand All @@ -383,15 +356,15 @@ func TestPlatformSearchSorting(t *testing.T) {
res, stat := PlatformSearch(&rpc.PlatformSearchRequest{
Instance: inst,
SearchArgs: "",
AllVersions: false,
AllVersions: true,
})
require.Nil(t, stat)
require.NotNil(t, res)

require.Len(t, res.SearchOutput, 3)
require.Equal(t, res.SearchOutput[0].GetLatestRelease().Name, "Arduino AVR Boards")
require.Equal(t, res.SearchOutput[0].GetSortedReleases()[0].Name, "Arduino AVR Boards")
require.Equal(t, res.SearchOutput[0].Metadata.Deprecated, false)
require.Equal(t, res.SearchOutput[1].GetLatestRelease().Name, "RK002")
require.Equal(t, res.SearchOutput[1].GetSortedReleases()[0].Name, "RK002")
require.Equal(t, res.SearchOutput[1].Metadata.Deprecated, false)
require.Equal(t, res.SearchOutput[2].GetLatestRelease().Name, "Platform")
require.Equal(t, res.SearchOutput[2].Metadata.Deprecated, true)
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/arguments/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func GetInstallableCores() []string {
var res []string
// transform the data structure for the completion
for _, i := range platforms.GetSearchOutput() {
if latest := i.GetLatestCompatibleRelease(); latest != nil {
if latest := i.GetLatestRelease(); latest != nil {
res = append(res, i.GetMetadata().GetId()+"\t"+latest.GetName())
}
}
Expand Down
8 changes: 3 additions & 5 deletions internal/cli/core/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func GetList(inst *rpc.Instance, all bool, updatableOnly bool) []*rpc.PlatformSu
if platform.InstalledVersion == "" && !platform.GetMetadata().ManuallyInstalled {
continue
}
if updatableOnly && platform.InstalledVersion == platform.LatestCompatibleVersion {
if updatableOnly && platform.InstalledVersion == platform.LatestVersion {
continue
}
result = append(result, platform)
Expand Down Expand Up @@ -122,17 +122,15 @@ func (ir coreListResult) String() string {
name = installed.Name
}
if name == "" {
if latestCompatible := platform.GetLatestCompatibleRelease(); latestCompatible != nil {
name = latestCompatible.Name
} else if latest := platform.GetLatestRelease(); latest != nil && 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.LatestCompatibleVersion, name)
t.AddRow(platform.Id, platform.InstalledVersion, platform.LatestVersion, name)
}

return t.Render()
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/core/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ func (sr searchResults) String() string {
for _, platform := range sr.platforms {
// When allVersions is not requested we only show the latest compatible version
if !sr.allVersions {
if latestCompatible := platform.GetLatestCompatibleRelease(); latestCompatible != nil {
addRow(platform, latestCompatible)
if latest := platform.GetLatestRelease(); latest != nil {
addRow(platform, latest)
}
continue
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/core/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ func Upgrade(inst *rpc.Instance, args []string, skipPostInstall bool, skipPreUni
if platform.InstalledVersion == "" {
continue
}
if platform.InstalledVersion == platform.LatestCompatibleVersion {
if platform.InstalledVersion == platform.GetLatestVersion() {
// if it's not updatable, skip it
continue
}
targets = append(targets, &rpc.Platform{
Metadata: platform.GetMetadata(),
Release: platform.GetLatestCompatibleRelease(),
Release: platform.GetLatestRelease(),
})
}

Expand Down
31 changes: 12 additions & 19 deletions internal/cli/feedback/result/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,16 @@ func NewPlatformSummary(in *rpc.PlatformSummary) *PlatformSummary {
releases.SortKeys((*semver.Version).CompareTo)

return &PlatformSummary{
Id: in.GetMetadata().GetId(),
Maintainer: in.GetMetadata().GetMaintainer(),
Website: in.GetMetadata().GetWebsite(),
Email: in.GetMetadata().GetEmail(),
ManuallyInstalled: in.GetMetadata().GetManuallyInstalled(),
Deprecated: in.GetMetadata().GetDeprecated(),
Indexed: in.GetMetadata().GetIndexed(),
Releases: releases,
InstalledVersion: semver.MustParse(in.GetInstalledVersion()),
LatestVersion: semver.MustParse(in.GetLatestVersion()),
LatestCompatibleVersion: semver.MustParse(in.LatestCompatibleVersion),
Id: in.GetMetadata().GetId(),
Maintainer: in.GetMetadata().GetMaintainer(),
Website: in.GetMetadata().GetWebsite(),
Email: in.GetMetadata().GetEmail(),
ManuallyInstalled: in.GetMetadata().GetManuallyInstalled(),
Deprecated: in.GetMetadata().GetDeprecated(),
Indexed: in.GetMetadata().GetIndexed(),
Releases: releases,
InstalledVersion: semver.MustParse(in.GetInstalledVersion()),
LatestVersion: semver.MustParse(in.GetLatestVersion()),
}
}

Expand All @@ -62,21 +61,15 @@ type PlatformSummary struct {

Releases orderedmap.Map[*semver.Version, *PlatformRelease] `json:"releases,omitempty"`

InstalledVersion *semver.Version `json:"installed_version,omitempty"`
LatestVersion *semver.Version `json:"latest_version,omitempty"`
LatestCompatibleVersion *semver.Version `json:"latest_compatible_version,omitempty"`
InstalledVersion *semver.Version `json:"installed_version,omitempty"`
LatestVersion *semver.Version `json:"latest_version,omitempty"`
}

// GetLatestRelease returns the latest relase of this platform or nil if none available.
func (p *PlatformSummary) GetLatestRelease() *PlatformRelease {
return p.Releases.Get(p.LatestVersion)
}

// GetLatestCompatibleRelease returns the latest relase of this platform or nil if none available.
func (p *PlatformSummary) GetLatestCompatibleRelease() *PlatformRelease {
return p.Releases.Get(p.LatestCompatibleVersion)
}

// GetInstalledRelease returns the installed relase of this platform or nil if none available.
func (p *PlatformSummary) GetInstalledRelease() *PlatformRelease {
return p.Releases.Get(p.InstalledVersion)
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/outdated/outdated.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ func (ir outdatedResult) String() string {
// Based on internal/cli/core/list.go
for _, p := range ir.Platforms {
name := ""
if latestCompatible := p.GetLatestCompatibleRelease(); latestCompatible != nil {
name = latestCompatible.Name
if latest := p.GetLatestRelease(); latest != nil {
name = latest.Name
}
if p.Deprecated {
name = fmt.Sprintf("[%s] %s", tr("DEPRECATED"), name)
}
t.AddRow(p.Id, name, p.InstalledVersion, p.LatestCompatibleVersion, "", "")
t.AddRow(p.Id, name, p.InstalledVersion, p.LatestVersion, "", "")
}

// Based on internal/cli/lib/list.go
Expand Down
Loading

0 comments on commit 679f014

Please sign in to comment.