Skip to content

Commit ffbd9a8

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 55401e9 commit ffbd9a8

File tree

21 files changed

+324
-396
lines changed

21 files changed

+324
-396
lines changed

arduino/cores/packagemanager/download.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (pme *Explorer) FindPlatformReleaseDependencies(item *PlatformReference) (*
8989
} else {
9090
release = platform.GetLatestCompatibleRelease()
9191
if release == nil {
92-
return nil, nil, fmt.Errorf(tr("platform %s has no available releases for your OS"), platform.String())
92+
return nil, nil, fmt.Errorf(tr("platform is not available for your OS"))
9393
}
9494
}
9595

commands/board/search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchR
4141
foundBoards := []*rpc.BoardListItem{}
4242
for _, targetPackage := range pme.GetPackages() {
4343
for _, platform := range targetPackage.Platforms {
44-
latestPlatformRelease := platform.GetLatestRelease()
44+
latestPlatformRelease := platform.GetLatestCompatibleRelease()
4545
installedPlatformRelease := pme.GetInstalledPlatformRelease(platform)
4646

4747
if latestPlatformRelease == nil && installedPlatformRelease == nil {

commands/core/search.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
5555

5656
// Discard platforms with no releases
5757
latestRelease := platform.GetLatestRelease()
58-
if latestRelease == nil {
59-
continue
60-
}
61-
if latestRelease.Name == "" {
58+
if latestRelease == nil || latestRelease.Name == "" {
6259
continue
6360
}
6461

@@ -91,29 +88,20 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse
9188
}
9289
if installed := pme.GetInstalledPlatformRelease(platform); installed != nil {
9390
rpcPlatformSummary.InstalledVersion = installed.Version.String()
94-
rpcPlatformSummary.Releases[installed.Version.String()] = commands.PlatformReleaseToRPC(installed)
95-
}
96-
if latest := platform.GetLatestRelease(); latest != nil {
97-
rpcPlatformSummary.LatestVersion = latest.Version.String()
98-
rpcPlatformSummary.Releases[latest.Version.String()] = commands.PlatformReleaseToRPC(latest)
9991
}
10092
if latestCompatible := platform.GetLatestCompatibleRelease(); latestCompatible != nil {
101-
rpcPlatformSummary.LatestCompatibleVersion = latestCompatible.Version.String()
102-
rpcPlatformSummary.Releases[latestCompatible.Version.String()] = commands.PlatformReleaseToRPC(latestCompatible)
93+
rpcPlatformSummary.LatestVersion = latestCompatible.Version.String()
10394
}
104-
if req.AllVersions {
105-
for _, platformRelease := range platform.GetAllReleases() {
106-
rpcPlatformRelease := commands.PlatformReleaseToRPC(platformRelease)
107-
rpcPlatformSummary.Releases[rpcPlatformRelease.Version] = rpcPlatformRelease
108-
}
95+
for _, platformRelease := range platform.GetAllReleases() {
96+
rpcPlatformRelease := commands.PlatformReleaseToRPC(platformRelease)
97+
rpcPlatformSummary.Releases[rpcPlatformRelease.Version] = rpcPlatformRelease
10998
}
11099
out = append(out, rpcPlatformSummary)
111100
}
112101

113102
// Sort result alphabetically and put deprecated platforms at the bottom
114103
sort.Slice(out, func(i, j int) bool {
115-
return strings.ToLower(out[i].GetLatestRelease().GetName()) <
116-
strings.ToLower(out[j].GetLatestRelease().GetName())
104+
return strings.ToLower(out[i].GetMetadata().GetId()) < strings.ToLower(out[j].GetMetadata().GetId())
117105
})
118106
sort.SliceStable(out, func(i, j int) bool {
119107
return !out[i].GetMetadata().Deprecated && out[j].GetMetadata().Deprecated

commands/core/search_test.go

Lines changed: 16 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ func TestPlatformSearch(t *testing.T) {
4343

4444
t.Run("SearchAllVersions", func(t *testing.T) {
4545
res, stat := PlatformSearch(&rpc.PlatformSearchRequest{
46-
Instance: inst,
47-
SearchArgs: "retrokit",
48-
AllVersions: true,
46+
Instance: inst,
47+
SearchArgs: "retrokit",
4948
})
5049
require.Nil(t, stat)
5150
require.NotNil(t, res)
@@ -80,48 +79,13 @@ func TestPlatformSearch(t *testing.T) {
8079
},
8180
},
8281
InstalledVersion: "",
83-
LatestVersion: "1.0.6",
84-
})
85-
})
86-
87-
t.Run("SearchNoAllVersions", func(t *testing.T) {
88-
res, stat := PlatformSearch(&rpc.PlatformSearchRequest{
89-
Instance: inst,
90-
SearchArgs: "retrokit",
91-
AllVersions: false,
92-
})
93-
require.Nil(t, stat)
94-
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",
11782
})
11883
})
11984

12085
t.Run("SearchThePackageMaintainer", func(t *testing.T) {
12186
res, stat := PlatformSearch(&rpc.PlatformSearchRequest{
122-
Instance: inst,
123-
SearchArgs: "Retrokits (www.retrokits.com)",
124-
AllVersions: true,
87+
Instance: inst,
88+
SearchArgs: "Retrokits (www.retrokits.com)",
12589
})
12690
require.Nil(t, stat)
12791
require.NotNil(t, res)
@@ -155,15 +119,13 @@ func TestPlatformSearch(t *testing.T) {
155119
},
156120
},
157121
InstalledVersion: "",
158-
LatestVersion: "1.0.6",
159122
})
160123
})
161124

162125
t.Run("SearchPackageName", func(t *testing.T) {
163126
res, stat := PlatformSearch(&rpc.PlatformSearchRequest{
164-
Instance: inst,
165-
SearchArgs: "Retrokits-RK002",
166-
AllVersions: true,
127+
Instance: inst,
128+
SearchArgs: "Retrokits-RK002",
167129
})
168130
require.Nil(t, stat)
169131
require.NotNil(t, res)
@@ -197,15 +159,13 @@ func TestPlatformSearch(t *testing.T) {
197159
},
198160
},
199161
InstalledVersion: "",
200-
LatestVersion: "1.0.6",
201162
})
202163
})
203164

204165
t.Run("SearchPlatformName", func(t *testing.T) {
205166
res, stat := PlatformSearch(&rpc.PlatformSearchRequest{
206-
Instance: inst,
207-
SearchArgs: "rk002",
208-
AllVersions: true,
167+
Instance: inst,
168+
SearchArgs: "rk002",
209169
})
210170
require.Nil(t, stat)
211171
require.NotNil(t, res)
@@ -239,15 +199,13 @@ func TestPlatformSearch(t *testing.T) {
239199
},
240200
},
241201
InstalledVersion: "",
242-
LatestVersion: "1.0.6",
243202
})
244203
})
245204

246205
t.Run("SearchBoardName", func(t *testing.T) {
247206
res, stat := PlatformSearch(&rpc.PlatformSearchRequest{
248-
Instance: inst,
249-
SearchArgs: "Yún",
250-
AllVersions: true,
207+
Instance: inst,
208+
SearchArgs: "Yún",
251209
})
252210
require.Nil(t, stat)
253211
require.NotNil(t, res)
@@ -299,15 +257,13 @@ func TestPlatformSearch(t *testing.T) {
299257
},
300258
},
301259
InstalledVersion: "",
302-
LatestVersion: "1.8.3",
303260
})
304261
})
305262

306263
t.Run("SearchBoardName2", func(t *testing.T) {
307264
res, stat := PlatformSearch(&rpc.PlatformSearchRequest{
308-
Instance: inst,
309-
SearchArgs: "yun",
310-
AllVersions: true,
265+
Instance: inst,
266+
SearchArgs: "yun",
311267
})
312268
require.Nil(t, stat)
313269
require.NotNil(t, res)
@@ -359,7 +315,6 @@ func TestPlatformSearch(t *testing.T) {
359315
},
360316
},
361317
InstalledVersion: "",
362-
LatestVersion: "1.8.3",
363318
})
364319
})
365320
}
@@ -381,17 +336,16 @@ func TestPlatformSearchSorting(t *testing.T) {
381336
require.NotNil(t, inst)
382337

383338
res, stat := PlatformSearch(&rpc.PlatformSearchRequest{
384-
Instance: inst,
385-
SearchArgs: "",
386-
AllVersions: false,
339+
Instance: inst,
340+
SearchArgs: "",
387341
})
388342
require.Nil(t, stat)
389343
require.NotNil(t, res)
390344

391345
require.Len(t, res.SearchOutput, 3)
392-
require.Equal(t, res.SearchOutput[0].GetLatestRelease().Name, "Arduino AVR Boards")
346+
require.Equal(t, res.SearchOutput[0].GetSortedReleases()[0].Name, "Arduino AVR Boards")
393347
require.Equal(t, res.SearchOutput[0].Metadata.Deprecated, false)
394-
require.Equal(t, res.SearchOutput[1].GetLatestRelease().Name, "RK002")
348+
require.Equal(t, res.SearchOutput[1].GetSortedReleases()[0].Name, "RK002")
395349
require.Equal(t, res.SearchOutput[1].Metadata.Deprecated, false)
396350
require.Equal(t, res.SearchOutput[2].GetLatestRelease().Name, "Platform")
397351
require.Equal(t, res.SearchOutput[2].Metadata.Deprecated, true)

internal/cli/arguments/completion.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ func GetUninstallableCores() []string {
8585

8686
platforms, _ := core.PlatformSearch(&rpc.PlatformSearchRequest{
8787
Instance: inst,
88-
AllVersions: false,
8988
ManuallyInstalled: true,
9089
})
9190

@@ -106,14 +105,13 @@ func GetInstallableCores() []string {
106105
inst := instance.CreateAndInit()
107106

108107
platforms, _ := core.PlatformSearch(&rpc.PlatformSearchRequest{
109-
Instance: inst,
110-
SearchArgs: "",
111-
AllVersions: false,
108+
Instance: inst,
109+
SearchArgs: "",
112110
})
113111
var res []string
114112
// transform the data structure for the completion
115113
for _, i := range platforms.GetSearchOutput() {
116-
if latest := i.GetLatestCompatibleRelease(); latest != nil {
114+
if latest := i.GetLatestRelease(); latest != nil {
117115
res = append(res, i.GetMetadata().GetId()+"\t"+latest.GetName())
118116
}
119117
}

internal/cli/arguments/reference.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ func ParseReference(arg string) (*Reference, error) {
9696
// try to use core.PlatformList to optimize what the user typed
9797
// (by replacing the PackageName and Architecture in ret with the content of core.GetPlatform())
9898
platforms, _ := core.PlatformSearch(&rpc.PlatformSearchRequest{
99-
Instance: instance.CreateAndInit(),
100-
AllVersions: false,
99+
Instance: instance.CreateAndInit(),
101100
})
102101
foundPlatforms := []string{}
103102
for _, platform := range platforms.GetSearchOutput() {

internal/cli/compile/compile.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,8 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
370370
res.Error += fmt.Sprintln()
371371

372372
if platform, err := core.PlatformSearch(&rpc.PlatformSearchRequest{
373-
Instance: inst,
374-
SearchArgs: platformErr.Platform,
375-
AllVersions: false,
373+
Instance: inst,
374+
SearchArgs: platformErr.Platform,
376375
}); err != nil {
377376
res.Error += err.Error()
378377
} else if len(platform.GetSearchOutput()) > 0 {

internal/cli/core/list.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package core
1717

1818
import (
19-
"fmt"
2019
"os"
2120

2221
"github.com/arduino/arduino-cli/commands/core"
@@ -63,7 +62,6 @@ func List(inst *rpc.Instance, all bool, updatableOnly bool) {
6362
func GetList(inst *rpc.Instance, all bool, updatableOnly bool) []*rpc.PlatformSummary {
6463
platforms, err := core.PlatformSearch(&rpc.PlatformSearchRequest{
6564
Instance: inst,
66-
AllVersions: true,
6765
ManuallyInstalled: true,
6866
})
6967
if err != nil {
@@ -80,7 +78,7 @@ func GetList(inst *rpc.Instance, all bool, updatableOnly bool) []*rpc.PlatformSu
8078
if platform.InstalledVersion == "" && !platform.GetMetadata().ManuallyInstalled {
8179
continue
8280
}
83-
if updatableOnly && platform.InstalledVersion == platform.LatestCompatibleVersion {
81+
if updatableOnly && platform.InstalledVersion == platform.LatestVersion {
8482
continue
8583
}
8684
result = append(result, platform)
@@ -117,22 +115,11 @@ func (ir coreListResult) String() string {
117115
t := table.New()
118116
t.SetHeader(tr("ID"), tr("Installed"), tr("Latest"), tr("Name"))
119117
for _, platform := range ir.platforms {
120-
var name string
121-
if installed := platform.GetInstalledRelease(); installed != nil {
122-
name = installed.Name
118+
latestVersion := platform.LatestVersion.String()
119+
if latestVersion == "" {
120+
latestVersion = "n/a"
123121
}
124-
if name == "" {
125-
if latestCompatible := platform.GetLatestCompatibleRelease(); latestCompatible != nil {
126-
name = latestCompatible.Name
127-
} else if latest := platform.GetLatestRelease(); latest != nil && name == "" {
128-
name = latest.Name
129-
}
130-
}
131-
if platform.Deprecated {
132-
name = fmt.Sprintf("[%s] %s", tr("DEPRECATED"), name)
133-
}
134-
135-
t.AddRow(platform.Id, platform.InstalledVersion, platform.LatestCompatibleVersion, name)
122+
t.AddRow(platform.Id, platform.InstalledVersion, latestVersion, platform.GetPlatformName())
136123
}
137124

138125
return t.Render()

internal/cli/core/search.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ func runSearchCommand(cmd *cobra.Command, args []string, allVersions bool) {
7272
logrus.Infof("Executing `arduino-cli core search` with args: '%s'", arguments)
7373

7474
resp, err := core.PlatformSearch(&rpc.PlatformSearchRequest{
75-
Instance: inst,
76-
SearchArgs: arguments,
77-
AllVersions: allVersions,
75+
Instance: inst,
76+
SearchArgs: arguments,
7877
})
7978
if err != nil {
8079
feedback.Fatal(tr("Error searching for platforms: %v", err), feedback.ErrGeneric)
@@ -115,19 +114,17 @@ func (sr searchResults) String() string {
115114
t.SetHeader(tr("ID"), tr("Version"), tr("Name"))
116115

117116
addRow := func(platform *result.PlatformSummary, release *result.PlatformRelease) {
118-
name := release.Name
119-
if release.Deprecated {
120-
name = fmt.Sprintf("[%s] %s", tr("DEPRECATED"), release.Name)
117+
if release == nil {
118+
t.AddRow(platform.Id, "n/a", platform.GetPlatformName())
119+
return
121120
}
122-
t.AddRow(platform.Id, release.Version, name)
121+
t.AddRow(platform.Id, release.Version, release.FormatName())
123122
}
124123

125124
for _, platform := range sr.platforms {
126125
// When allVersions is not requested we only show the latest compatible version
127126
if !sr.allVersions {
128-
if latestCompatible := platform.GetLatestCompatibleRelease(); latestCompatible != nil {
129-
addRow(platform, latestCompatible)
130-
}
127+
addRow(platform, platform.GetLatestRelease())
131128
continue
132129
}
133130

internal/cli/core/upgrade.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ func Upgrade(inst *rpc.Instance, args []string, skipPostInstall bool, skipPreUni
6161
// if no platform was passed, upgrade allthethings
6262
if len(args) == 0 {
6363
platforms, err := core.PlatformSearch(&rpc.PlatformSearchRequest{
64-
Instance: inst,
65-
AllVersions: false,
64+
Instance: inst,
6665
})
6766
if err != nil {
6867
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
7372
if platform.InstalledVersion == "" {
7473
continue
7574
}
76-
if platform.InstalledVersion == platform.LatestCompatibleVersion {
77-
// if it's not updatable, skip it
78-
continue
75+
// if it's not updatable, skip it
76+
latestRelease := platform.GetLatestRelease()
77+
if latestRelease != nil && platform.InstalledVersion != latestRelease.Version {
78+
targets = append(targets, &rpc.Platform{
79+
Metadata: platform.GetMetadata(),
80+
Release: latestRelease,
81+
})
7982
}
80-
targets = append(targets, &rpc.Platform{
81-
Metadata: platform.GetMetadata(),
82-
Release: platform.GetLatestCompatibleRelease(),
83-
})
8483
}
8584

8685
if len(targets) == 0 {

0 commit comments

Comments
 (0)