Skip to content

Commit 679f014

Browse files
cr: remove latest_compatible_version from gRPC api.
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.
1 parent d3c7d95 commit 679f014

File tree

13 files changed

+177
-204
lines changed

13 files changed

+177
-204
lines changed

Diff for: arduino/cores/packagemanager/package_manager.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,20 @@ func (pme *Explorer) GetCustomGlobalProperties() *properties.Map {
229229
}
230230

231231
// FindPlatformReleaseProvidingBoardsWithVidPid FIXMEDOC
232-
func (pme *Explorer) FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid string) []*cores.Platform {
232+
func (pme *Explorer) FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid string, showAllRelease bool) []*cores.Platform {
233233
res := []*cores.Platform{}
234234
for _, targetPackage := range pme.packages {
235235
for _, targetPlatform := range targetPackage.Platforms {
236-
platformRelease := targetPlatform.GetLatestRelease()
236+
var platformRelease *cores.PlatformRelease
237+
if showAllRelease {
238+
platformRelease = targetPlatform.GetLatestRelease()
239+
} else {
240+
platformRelease = targetPlatform.GetLatestCompatibleRelease()
241+
}
237242
if platformRelease == nil {
238243
continue
239244
}
245+
240246
for _, boardManifest := range platformRelease.BoardsManifest {
241247
if boardManifest.HasUsbID(vid, pid) {
242248
res = append(res, targetPlatform)

Diff for: commands/core/search.go

+11-13
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
3939
res := []*cores.Platform{}
4040
if isUsb, _ := regexp.MatchString("[0-9a-f]{4}:[0-9a-f]{4}", req.SearchArgs); isUsb {
4141
vid, pid := req.SearchArgs[:4], req.SearchArgs[5:]
42-
res = pme.FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid)
42+
res = pme.FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid, req.AllVersions)
4343
} else {
4444
searchArgs := utils.SearchTermsFromQueryString(req.SearchArgs)
4545
for _, targetPackage := range pme.GetPackages() {
@@ -53,12 +53,15 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
5353
continue
5454
}
5555

56-
// Discard platforms with no releases
57-
latestRelease := platform.GetLatestRelease()
58-
if latestRelease == nil {
59-
continue
56+
// In case we ask for all versions we also show incompatible ones
57+
var latestRelease *cores.PlatformRelease
58+
if req.AllVersions {
59+
latestRelease = platform.GetLatestRelease()
60+
} else {
61+
latestRelease = platform.GetLatestCompatibleRelease()
6062
}
61-
if latestRelease.Name == "" {
63+
// Discard platforms with no releases
64+
if latestRelease == nil || latestRelease.Name == "" {
6265
continue
6366
}
6467

@@ -93,12 +96,8 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
9396
rpcPlatformSummary.InstalledVersion = installed.Version.String()
9497
rpcPlatformSummary.Releases[installed.Version.String()] = commands.PlatformReleaseToRPC(installed)
9598
}
96-
if latest := platform.GetLatestRelease(); latest != nil {
97-
rpcPlatformSummary.LatestVersion = latest.Version.String()
98-
rpcPlatformSummary.Releases[latest.Version.String()] = commands.PlatformReleaseToRPC(latest)
99-
}
10099
if latestCompatible := platform.GetLatestCompatibleRelease(); latestCompatible != nil {
101-
rpcPlatformSummary.LatestCompatibleVersion = latestCompatible.Version.String()
100+
rpcPlatformSummary.LatestVersion = latestCompatible.Version.String()
102101
rpcPlatformSummary.Releases[latestCompatible.Version.String()] = commands.PlatformReleaseToRPC(latestCompatible)
103102
}
104103
if req.AllVersions {
@@ -112,8 +111,7 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
112111

113112
// Sort result alphabetically and put deprecated platforms at the bottom
114113
sort.Slice(out, func(i, j int) bool {
115-
return strings.ToLower(out[i].GetLatestRelease().GetName()) <
116-
strings.ToLower(out[j].GetLatestRelease().GetName())
114+
return strings.ToLower(out[i].GetLatestRelease().GetName()) < strings.ToLower(out[j].GetLatestRelease().GetName())
117115
})
118116
sort.SliceStable(out, func(i, j int) bool {
119117
return !out[i].GetMetadata().Deprecated && out[j].GetMetadata().Deprecated

Diff for: commands/core/search_test.go

+5-32
Original file line numberDiff line numberDiff line change
@@ -80,41 +80,19 @@ func TestPlatformSearch(t *testing.T) {
8080
},
8181
},
8282
InstalledVersion: "",
83-
LatestVersion: "1.0.6",
8483
})
8584
})
8685

8786
t.Run("SearchNoAllVersions", func(t *testing.T) {
87+
// This platform doesn't contain any installable release
8888
res, stat := PlatformSearch(&rpc.PlatformSearchRequest{
8989
Instance: inst,
9090
SearchArgs: "retrokit",
9191
AllVersions: false,
9292
})
9393
require.Nil(t, stat)
9494
require.NotNil(t, res)
95-
require.Len(t, res.SearchOutput, 1)
96-
require.Contains(t, res.SearchOutput, &rpc.PlatformSummary{
97-
Metadata: &rpc.PlatformMetadata{
98-
Id: "Retrokits-RK002:arm",
99-
Maintainer: "Retrokits (www.retrokits.com)",
100-
Website: "https://www.retrokits.com",
101-
102-
Indexed: true,
103-
},
104-
Releases: map[string]*rpc.PlatformRelease{
105-
"1.0.6": {
106-
Name: "RK002",
107-
Type: []string{"Contributed"},
108-
Installed: false,
109-
Version: "1.0.6",
110-
Boards: []*rpc.Board{{Name: "RK002"}},
111-
Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"},
112-
Compatible: false,
113-
},
114-
},
115-
InstalledVersion: "",
116-
LatestVersion: "1.0.6",
117-
})
95+
require.Empty(t, res.SearchOutput)
11896
})
11997

12098
t.Run("SearchThePackageMaintainer", func(t *testing.T) {
@@ -155,7 +133,6 @@ func TestPlatformSearch(t *testing.T) {
155133
},
156134
},
157135
InstalledVersion: "",
158-
LatestVersion: "1.0.6",
159136
})
160137
})
161138

@@ -197,7 +174,6 @@ func TestPlatformSearch(t *testing.T) {
197174
},
198175
},
199176
InstalledVersion: "",
200-
LatestVersion: "1.0.6",
201177
})
202178
})
203179

@@ -239,7 +215,6 @@ func TestPlatformSearch(t *testing.T) {
239215
},
240216
},
241217
InstalledVersion: "",
242-
LatestVersion: "1.0.6",
243218
})
244219
})
245220

@@ -299,7 +274,6 @@ func TestPlatformSearch(t *testing.T) {
299274
},
300275
},
301276
InstalledVersion: "",
302-
LatestVersion: "1.8.3",
303277
})
304278
})
305279

@@ -359,7 +333,6 @@ func TestPlatformSearch(t *testing.T) {
359333
},
360334
},
361335
InstalledVersion: "",
362-
LatestVersion: "1.8.3",
363336
})
364337
})
365338
}
@@ -383,15 +356,15 @@ func TestPlatformSearchSorting(t *testing.T) {
383356
res, stat := PlatformSearch(&rpc.PlatformSearchRequest{
384357
Instance: inst,
385358
SearchArgs: "",
386-
AllVersions: false,
359+
AllVersions: true,
387360
})
388361
require.Nil(t, stat)
389362
require.NotNil(t, res)
390363

391364
require.Len(t, res.SearchOutput, 3)
392-
require.Equal(t, res.SearchOutput[0].GetLatestRelease().Name, "Arduino AVR Boards")
365+
require.Equal(t, res.SearchOutput[0].GetSortedReleases()[0].Name, "Arduino AVR Boards")
393366
require.Equal(t, res.SearchOutput[0].Metadata.Deprecated, false)
394-
require.Equal(t, res.SearchOutput[1].GetLatestRelease().Name, "RK002")
367+
require.Equal(t, res.SearchOutput[1].GetSortedReleases()[0].Name, "RK002")
395368
require.Equal(t, res.SearchOutput[1].Metadata.Deprecated, false)
396369
require.Equal(t, res.SearchOutput[2].GetLatestRelease().Name, "Platform")
397370
require.Equal(t, res.SearchOutput[2].Metadata.Deprecated, true)

Diff for: internal/cli/arguments/completion.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func GetInstallableCores() []string {
113113
var res []string
114114
// transform the data structure for the completion
115115
for _, i := range platforms.GetSearchOutput() {
116-
if latest := i.GetLatestCompatibleRelease(); latest != nil {
116+
if latest := i.GetLatestRelease(); latest != nil {
117117
res = append(res, i.GetMetadata().GetId()+"\t"+latest.GetName())
118118
}
119119
}

Diff for: internal/cli/core/list.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func GetList(inst *rpc.Instance, all bool, updatableOnly bool) []*rpc.PlatformSu
8080
if platform.InstalledVersion == "" && !platform.GetMetadata().ManuallyInstalled {
8181
continue
8282
}
83-
if updatableOnly && platform.InstalledVersion == platform.LatestCompatibleVersion {
83+
if updatableOnly && platform.InstalledVersion == platform.LatestVersion {
8484
continue
8585
}
8686
result = append(result, platform)
@@ -122,17 +122,15 @@ func (ir coreListResult) String() string {
122122
name = installed.Name
123123
}
124124
if name == "" {
125-
if latestCompatible := platform.GetLatestCompatibleRelease(); latestCompatible != nil {
126-
name = latestCompatible.Name
127-
} else if latest := platform.GetLatestRelease(); latest != nil && name == "" {
125+
if latest := platform.GetLatestRelease(); latest != nil {
128126
name = latest.Name
129127
}
130128
}
131129
if platform.Deprecated {
132130
name = fmt.Sprintf("[%s] %s", tr("DEPRECATED"), name)
133131
}
134132

135-
t.AddRow(platform.Id, platform.InstalledVersion, platform.LatestCompatibleVersion, name)
133+
t.AddRow(platform.Id, platform.InstalledVersion, platform.LatestVersion, name)
136134
}
137135

138136
return t.Render()

Diff for: internal/cli/core/search.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ func (sr searchResults) String() string {
125125
for _, platform := range sr.platforms {
126126
// When allVersions is not requested we only show the latest compatible version
127127
if !sr.allVersions {
128-
if latestCompatible := platform.GetLatestCompatibleRelease(); latestCompatible != nil {
129-
addRow(platform, latestCompatible)
128+
if latest := platform.GetLatestRelease(); latest != nil {
129+
addRow(platform, latest)
130130
}
131131
continue
132132
}

Diff for: internal/cli/core/upgrade.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ func Upgrade(inst *rpc.Instance, args []string, skipPostInstall bool, skipPreUni
7373
if platform.InstalledVersion == "" {
7474
continue
7575
}
76-
if platform.InstalledVersion == platform.LatestCompatibleVersion {
76+
if platform.InstalledVersion == platform.GetLatestVersion() {
7777
// if it's not updatable, skip it
7878
continue
7979
}
8080
targets = append(targets, &rpc.Platform{
8181
Metadata: platform.GetMetadata(),
82-
Release: platform.GetLatestCompatibleRelease(),
82+
Release: platform.GetLatestRelease(),
8383
})
8484
}
8585

Diff for: internal/cli/feedback/result/rpc.go

+12-19
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,16 @@ func NewPlatformSummary(in *rpc.PlatformSummary) *PlatformSummary {
3636
releases.SortKeys((*semver.Version).CompareTo)
3737

3838
return &PlatformSummary{
39-
Id: in.GetMetadata().GetId(),
40-
Maintainer: in.GetMetadata().GetMaintainer(),
41-
Website: in.GetMetadata().GetWebsite(),
42-
Email: in.GetMetadata().GetEmail(),
43-
ManuallyInstalled: in.GetMetadata().GetManuallyInstalled(),
44-
Deprecated: in.GetMetadata().GetDeprecated(),
45-
Indexed: in.GetMetadata().GetIndexed(),
46-
Releases: releases,
47-
InstalledVersion: semver.MustParse(in.GetInstalledVersion()),
48-
LatestVersion: semver.MustParse(in.GetLatestVersion()),
49-
LatestCompatibleVersion: semver.MustParse(in.LatestCompatibleVersion),
39+
Id: in.GetMetadata().GetId(),
40+
Maintainer: in.GetMetadata().GetMaintainer(),
41+
Website: in.GetMetadata().GetWebsite(),
42+
Email: in.GetMetadata().GetEmail(),
43+
ManuallyInstalled: in.GetMetadata().GetManuallyInstalled(),
44+
Deprecated: in.GetMetadata().GetDeprecated(),
45+
Indexed: in.GetMetadata().GetIndexed(),
46+
Releases: releases,
47+
InstalledVersion: semver.MustParse(in.GetInstalledVersion()),
48+
LatestVersion: semver.MustParse(in.GetLatestVersion()),
5049
}
5150
}
5251

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

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

65-
InstalledVersion *semver.Version `json:"installed_version,omitempty"`
66-
LatestVersion *semver.Version `json:"latest_version,omitempty"`
67-
LatestCompatibleVersion *semver.Version `json:"latest_compatible_version,omitempty"`
64+
InstalledVersion *semver.Version `json:"installed_version,omitempty"`
65+
LatestVersion *semver.Version `json:"latest_version,omitempty"`
6866
}
6967

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

75-
// GetLatestCompatibleRelease returns the latest relase of this platform or nil if none available.
76-
func (p *PlatformSummary) GetLatestCompatibleRelease() *PlatformRelease {
77-
return p.Releases.Get(p.LatestCompatibleVersion)
78-
}
79-
8073
// GetInstalledRelease returns the installed relase of this platform or nil if none available.
8174
func (p *PlatformSummary) GetInstalledRelease() *PlatformRelease {
8275
return p.Releases.Get(p.InstalledVersion)

Diff for: internal/cli/outdated/outdated.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ func (ir outdatedResult) String() string {
109109
// Based on internal/cli/core/list.go
110110
for _, p := range ir.Platforms {
111111
name := ""
112-
if latestCompatible := p.GetLatestCompatibleRelease(); latestCompatible != nil {
113-
name = latestCompatible.Name
112+
if latest := p.GetLatestRelease(); latest != nil {
113+
name = latest.Name
114114
}
115115
if p.Deprecated {
116116
name = fmt.Sprintf("[%s] %s", tr("DEPRECATED"), name)
117117
}
118-
t.AddRow(p.Id, name, p.InstalledVersion, p.LatestCompatibleVersion, "", "")
118+
t.AddRow(p.Id, name, p.InstalledVersion, p.LatestVersion, "", "")
119119
}
120120

121121
// Based on internal/cli/lib/list.go

0 commit comments

Comments
 (0)