diff --git a/arduino/cores/cores.go b/arduino/cores/cores.go index 67f0c60ba3a..39002f16fef 100644 --- a/arduino/cores/cores.go +++ b/arduino/cores/cores.go @@ -34,6 +34,7 @@ type Platform struct { Releases map[string]*PlatformRelease // The Releases of this platform, labeled by version. Package *Package `json:"-"` ManuallyInstalled bool // true if the Platform has been installed without the CLI + Deprecated bool // true if the Platform has been deprecated } // PlatformReleaseHelp represents the help URL for this Platform release diff --git a/arduino/cores/packageindex/index.go b/arduino/cores/packageindex/index.go index 2ba2db08fd5..8297075ee5d 100644 --- a/arduino/cores/packageindex/index.go +++ b/arduino/cores/packageindex/index.go @@ -50,6 +50,7 @@ type indexPlatformRelease struct { Name string `json:"name,required"` Architecture string `json:"architecture"` Version *semver.Version `json:"version,required"` + Deprecated bool `json:"deprecated"` Category string `json:"category"` URL string `json:"url"` ArchiveFileName string `json:"archiveFileName,required"` @@ -167,6 +168,7 @@ func IndexFromPlatformRelease(pr *cores.PlatformRelease) Index { Name: pr.Platform.Name, Architecture: pr.Platform.Architecture, Version: pr.Version, + Deprecated: pr.Platform.Deprecated, Category: pr.Platform.Category, URL: pr.Resource.URL, ArchiveFileName: pr.Resource.ArchiveFileName, @@ -205,6 +207,13 @@ func (inPlatformRelease indexPlatformRelease) extractPlatformIn(outPackage *core // FIXME: shall we use the Name and Category of the latest release? or maybe move Name and Category in PlatformRelease? outPlatform.Name = inPlatformRelease.Name outPlatform.Category = inPlatformRelease.Category + // If the Platform is installed before deprecation installed.json file does not include "deprecated" field. + // The installed.json is read during loading phase of an installed Platform, if the deprecated field is not found + // the package_index.json field would be overwritten and the deprecation info would be lost. + // This check prevents that behaviour. + if !outPlatform.Deprecated { + outPlatform.Deprecated = inPlatformRelease.Deprecated + } size, err := inPlatformRelease.Size.Int64() if err != nil { diff --git a/cli/core/list.go b/cli/core/list.go index a3b09432bba..2d2d2b34465 100644 --- a/cli/core/list.go +++ b/cli/core/list.go @@ -16,8 +16,8 @@ package core import ( + "fmt" "os" - "sort" "github.com/arduino/arduino-cli/cli/errorcodes" "github.com/arduino/arduino-cli/cli/feedback" @@ -87,11 +87,12 @@ func (ir installedResult) String() string { t := table.New() t.SetHeader("ID", "Installed", "Latest", "Name") - sort.Slice(ir.platforms, func(i, j int) bool { - return ir.platforms[i].Id < ir.platforms[j].Id - }) for _, p := range ir.platforms { - t.AddRow(p.Id, p.Installed, p.Latest, p.Name) + name := p.Name + if p.Deprecated { + name = fmt.Sprintf("[DEPRECATED] %s", name) + } + t.AddRow(p.Id, p.Installed, p.Latest, name) } return t.Render() diff --git a/cli/core/search.go b/cli/core/search.go index 1ee2f9caeb0..0084bbfd9c6 100644 --- a/cli/core/search.go +++ b/cli/core/search.go @@ -17,9 +17,9 @@ package core import ( "context" + "fmt" "os" "path" - "sort" "strings" "time" @@ -108,11 +108,12 @@ func (sr searchResults) String() string { if len(sr.platforms) > 0 { t := table.New() t.SetHeader("ID", "Version", "Name") - sort.Slice(sr.platforms, func(i, j int) bool { - return sr.platforms[i].Id < sr.platforms[j].Id - }) for _, item := range sr.platforms { - t.AddRow(item.GetId(), item.GetLatest(), item.GetName()) + name := item.GetName() + if item.Deprecated { + name = fmt.Sprintf("[DEPRECATED] %s", name) + } + t.AddRow(item.GetId(), item.GetLatest(), name) } return t.Render() } diff --git a/commands/core.go b/commands/core.go index 558ddf7ca71..44b668ad9f8 100644 --- a/commands/core.go +++ b/commands/core.go @@ -59,6 +59,7 @@ func PlatformReleaseToRPC(platformRelease *cores.PlatformRelease) *rpc.Platform Boards: boards, Latest: platformRelease.Version.String(), ManuallyInstalled: platformRelease.Platform.ManuallyInstalled, + Deprecated: platformRelease.Platform.Deprecated, } return result diff --git a/commands/core/list.go b/commands/core/list.go index d4eb5515cde..2e69fa04c44 100644 --- a/commands/core/list.go +++ b/commands/core/list.go @@ -16,6 +16,8 @@ package core import ( + "sort" + "github.com/arduino/arduino-cli/commands" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" "github.com/pkg/errors" @@ -67,6 +69,15 @@ func GetPlatforms(req *rpc.PlatformListRequest) ([]*rpc.Platform, error) { } } } - + // Sort result alphabetically and put deprecated platforms at the bottom + sort.Slice(res, func(i, j int) bool { + return res[i].Name < res[j].Name + }) + sort.SliceStable(res, func(i, j int) bool { + if !res[i].Deprecated && res[j].Deprecated { + return true + } + return false + }) return res, nil } diff --git a/commands/core/search.go b/commands/core/search.go index 83f76c53597..b2d81cbe8d0 100644 --- a/commands/core/search.go +++ b/commands/core/search.go @@ -18,6 +18,7 @@ package core import ( "errors" "regexp" + "sort" "strings" "github.com/arduino/arduino-cli/arduino/cores" @@ -113,5 +114,17 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse for i, platformRelease := range res { out[i] = commands.PlatformReleaseToRPC(platformRelease) } + // Sort result alphabetically and put deprecated platforms at the bottom + sort.Slice( + out, func(i, j int) bool { + return out[i].Name < out[j].Name + }) + sort.SliceStable( + out, func(i, j int) bool { + if !out[i].Deprecated && out[j].Deprecated { + return true + } + return false + }) return &rpc.PlatformSearchResponse{SearchOutput: out}, nil } diff --git a/commands/core/search_test.go b/commands/core/search_test.go index 40dc405e47c..091c7d63017 100644 --- a/commands/core/search_test.go +++ b/commands/core/search_test.go @@ -277,3 +277,38 @@ func TestPlatformSearch(t *testing.T) { }, }) } + +func TestPlatformSearchSorting(t *testing.T) { + dataDir := paths.TempDir().Join("test", "data_dir") + downloadDir := paths.TempDir().Join("test", "staging") + os.Setenv("ARDUINO_DATA_DIR", dataDir.String()) + os.Setenv("ARDUINO_DOWNLOADS_DIR", downloadDir.String()) + dataDir.MkdirAll() + downloadDir.MkdirAll() + defer paths.TempDir().Join("test").RemoveAll() + err := paths.New("testdata").Join("package_index.json").CopyTo(dataDir.Join("package_index.json")) + require.Nil(t, err) + + configuration.Settings = configuration.Init(paths.TempDir().Join("test", "arduino-cli.yaml").String()) + + inst, err := instance.CreateInstance() + require.Nil(t, err) + require.NotNil(t, inst) + + res, err := PlatformSearch(&rpc.PlatformSearchRequest{ + Instance: inst, + SearchArgs: "", + AllVersions: false, + }) + require.Nil(t, err) + require.NotNil(t, res) + + require.Len(t, res.SearchOutput, 3) + require.Equal(t, res.SearchOutput[0].Name, "Arduino AVR Boards") + require.Equal(t, res.SearchOutput[0].Deprecated, false) + require.Equal(t, res.SearchOutput[1].Name, "RK002") + require.Equal(t, res.SearchOutput[1].Deprecated, false) + require.Equal(t, res.SearchOutput[2].Name, "Platform") + require.Equal(t, res.SearchOutput[2].Deprecated, true) + +} diff --git a/commands/core/testdata/package_index.json b/commands/core/testdata/package_index.json index e5a9aa10f94..270ef6c84b3 100644 --- a/commands/core/testdata/package_index.json +++ b/commands/core/testdata/package_index.json @@ -130,6 +130,38 @@ } ], "tools": [] - } + }, + { + "name": "Package", + "tools": [], + "email": "test@example.com", + "maintainer": "Arduino", + "help": { + "online": "https://github.com/Arduino/arduino-cli" + }, + "websiteURL": "https://github.com/Arduino/arduino-cli", + "platforms": [ + { + "category": "Test", + "help": { + "online": "https://github.com/Arduino/arduino-cli" + }, + "url": "https://raw.githubusercontent.com/arduino/arduino-cli/master/test/testdata/core.zip", + "checksum": "SHA-256:6a338cf4d6d501176a2d352c87a8d72ac7488b8c5b82cdf2a4e2cef630391092", + "name": "Platform", + "version": "1.2.3", + "deprecated": true, + "architecture": "x86", + "archiveFileName": "core.zip", + "size": "486", + "toolsDependencies": [], + "boards": [ + { + "name": "MyBoard" + } + ] + } + ] + } ] } diff --git a/rpc/cc/arduino/cli/commands/v1/board.pb.go b/rpc/cc/arduino/cli/commands/v1/board.pb.go index edc6aa13182..fdbd791707c 100644 --- a/rpc/cc/arduino/cli/commands/v1/board.pb.go +++ b/rpc/cc/arduino/cli/commands/v1/board.pb.go @@ -15,14 +15,13 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.25.0 -// protoc v3.15.7 +// protoc-gen-go v1.26.0 +// protoc v3.15.8 // source: cc/arduino/cli/commands/v1/board.proto package commands import ( - proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -36,10 +35,6 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - type BoardDetailsRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache diff --git a/rpc/cc/arduino/cli/commands/v1/commands.pb.go b/rpc/cc/arduino/cli/commands/v1/commands.pb.go index 73c2b099858..7228e525243 100644 --- a/rpc/cc/arduino/cli/commands/v1/commands.pb.go +++ b/rpc/cc/arduino/cli/commands/v1/commands.pb.go @@ -15,15 +15,14 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.25.0 -// protoc v3.15.7 +// protoc-gen-go v1.26.0 +// protoc v3.15.8 // source: cc/arduino/cli/commands/v1/commands.proto package commands import ( context "context" - proto "github.com/golang/protobuf/proto" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -40,10 +39,6 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - type InitRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache diff --git a/rpc/cc/arduino/cli/commands/v1/common.pb.go b/rpc/cc/arduino/cli/commands/v1/common.pb.go index 1d957e126b3..963d7575916 100644 --- a/rpc/cc/arduino/cli/commands/v1/common.pb.go +++ b/rpc/cc/arduino/cli/commands/v1/common.pb.go @@ -15,14 +15,13 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.25.0 -// protoc v3.15.7 +// protoc-gen-go v1.26.0 +// protoc v3.15.8 // source: cc/arduino/cli/commands/v1/common.proto package commands import ( - proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -36,10 +35,6 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - type Instance struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -329,6 +324,8 @@ type Platform struct { // If true this Platform has been installed manually in the user' sketchbook // hardware folder ManuallyInstalled bool `protobuf:"varint,9,opt,name=manually_installed,json=manuallyInstalled,proto3" json:"manually_installed,omitempty"` + // If true this Platform has been deprecated + Deprecated bool `protobuf:"varint,10,opt,name=deprecated,proto3" json:"deprecated,omitempty"` } func (x *Platform) Reset() { @@ -426,6 +423,13 @@ func (x *Platform) GetManuallyInstalled() bool { return false } +func (x *Platform) GetDeprecated() bool { + if x != nil { + return x.Deprecated + } + return false +} + type Board struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -513,7 +517,7 @@ var file_cc_arduino_cli_commands_v1_common_proto_rawDesc = []byte{ 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, - 0x61, 0x6d, 0x65, 0x22, 0x9e, 0x02, 0x0a, 0x08, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, + 0x61, 0x6d, 0x65, 0x22, 0xbe, 0x02, 0x0a, 0x08, 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x12, 0x16, @@ -531,7 +535,9 @@ var file_cc_arduino_cli_commands_v1_common_proto_rawDesc = []byte{ 0x6f, 0x61, 0x72, 0x64, 0x73, 0x12, 0x2d, 0x0a, 0x12, 0x6d, 0x61, 0x6e, 0x75, 0x61, 0x6c, 0x6c, 0x79, 0x5f, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x08, 0x52, 0x11, 0x6d, 0x61, 0x6e, 0x75, 0x61, 0x6c, 0x6c, 0x79, 0x49, 0x6e, 0x73, 0x74, 0x61, - 0x6c, 0x6c, 0x65, 0x64, 0x22, 0x2f, 0x0a, 0x05, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x12, 0x12, 0x0a, + 0x6c, 0x6c, 0x65, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, 0x61, 0x74, + 0x65, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x64, 0x65, 0x70, 0x72, 0x65, 0x63, + 0x61, 0x74, 0x65, 0x64, 0x22, 0x2f, 0x0a, 0x05, 0x42, 0x6f, 0x61, 0x72, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x71, 0x62, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x66, 0x71, 0x62, 0x6e, 0x42, 0x48, 0x5a, 0x46, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, diff --git a/rpc/cc/arduino/cli/commands/v1/common.proto b/rpc/cc/arduino/cli/commands/v1/common.proto index 01b509d197c..29e0b160cad 100644 --- a/rpc/cc/arduino/cli/commands/v1/common.proto +++ b/rpc/cc/arduino/cli/commands/v1/common.proto @@ -76,6 +76,8 @@ message Platform { // If true this Platform has been installed manually in the user' sketchbook // hardware folder bool manually_installed = 9; + // If true this Platform has been deprecated + bool deprecated = 10; } message Board { diff --git a/rpc/cc/arduino/cli/commands/v1/compile.pb.go b/rpc/cc/arduino/cli/commands/v1/compile.pb.go index 9d7c135af3c..0a0f0c69f91 100644 --- a/rpc/cc/arduino/cli/commands/v1/compile.pb.go +++ b/rpc/cc/arduino/cli/commands/v1/compile.pb.go @@ -15,14 +15,13 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.25.0 -// protoc v3.15.7 +// protoc-gen-go v1.26.0 +// protoc v3.15.8 // source: cc/arduino/cli/commands/v1/compile.proto package commands import ( - proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" wrapperspb "google.golang.org/protobuf/types/known/wrapperspb" @@ -37,10 +36,6 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - type CompileRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache diff --git a/rpc/cc/arduino/cli/commands/v1/core.pb.go b/rpc/cc/arduino/cli/commands/v1/core.pb.go index fa9b180a6fd..e1b6a221c71 100644 --- a/rpc/cc/arduino/cli/commands/v1/core.pb.go +++ b/rpc/cc/arduino/cli/commands/v1/core.pb.go @@ -15,14 +15,13 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.25.0 -// protoc v3.15.7 +// protoc-gen-go v1.26.0 +// protoc v3.15.8 // source: cc/arduino/cli/commands/v1/core.proto package commands import ( - proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -36,10 +35,6 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - type PlatformInstallRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache diff --git a/rpc/cc/arduino/cli/commands/v1/lib.pb.go b/rpc/cc/arduino/cli/commands/v1/lib.pb.go index 1da7ba93e00..a85641f4d11 100644 --- a/rpc/cc/arduino/cli/commands/v1/lib.pb.go +++ b/rpc/cc/arduino/cli/commands/v1/lib.pb.go @@ -15,14 +15,13 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.25.0 -// protoc v3.15.7 +// protoc-gen-go v1.26.0 +// protoc v3.15.8 // source: cc/arduino/cli/commands/v1/lib.proto package commands import ( - proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -36,10 +35,6 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - type LibrarySearchStatus int32 const ( diff --git a/rpc/cc/arduino/cli/commands/v1/upload.pb.go b/rpc/cc/arduino/cli/commands/v1/upload.pb.go index a0d2b869197..d36d861ad08 100644 --- a/rpc/cc/arduino/cli/commands/v1/upload.pb.go +++ b/rpc/cc/arduino/cli/commands/v1/upload.pb.go @@ -15,14 +15,13 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.25.0 -// protoc v3.15.7 +// protoc-gen-go v1.26.0 +// protoc v3.15.8 // source: cc/arduino/cli/commands/v1/upload.proto package commands import ( - proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -36,10 +35,6 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - type UploadRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache diff --git a/rpc/cc/arduino/cli/debug/v1/debug.pb.go b/rpc/cc/arduino/cli/debug/v1/debug.pb.go index 7a52ef95219..7c223a41a9d 100644 --- a/rpc/cc/arduino/cli/debug/v1/debug.pb.go +++ b/rpc/cc/arduino/cli/debug/v1/debug.pb.go @@ -15,8 +15,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.25.0 -// protoc v3.15.7 +// protoc-gen-go v1.26.0 +// protoc v3.15.8 // source: cc/arduino/cli/debug/v1/debug.proto package debug @@ -24,7 +24,6 @@ package debug import ( context "context" v1 "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" - proto "github.com/golang/protobuf/proto" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -41,10 +40,6 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - // The top-level message sent by the client for the `Debug` method. // Multiple `DebugReq` messages can be sent but the first message // must contain a `DebugConfigReq` message to initialize the debug session. diff --git a/rpc/cc/arduino/cli/monitor/v1/monitor.pb.go b/rpc/cc/arduino/cli/monitor/v1/monitor.pb.go index 3ea5652a546..5bc62ccc23b 100644 --- a/rpc/cc/arduino/cli/monitor/v1/monitor.pb.go +++ b/rpc/cc/arduino/cli/monitor/v1/monitor.pb.go @@ -15,15 +15,14 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.25.0 -// protoc v3.15.7 +// protoc-gen-go v1.26.0 +// protoc v3.15.8 // source: cc/arduino/cli/monitor/v1/monitor.proto package monitor import ( context "context" - proto "github.com/golang/protobuf/proto" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -41,10 +40,6 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - type MonitorConfig_TargetType int32 const ( diff --git a/rpc/cc/arduino/cli/settings/v1/settings.pb.go b/rpc/cc/arduino/cli/settings/v1/settings.pb.go index 25dff905961..5febd4fafaa 100644 --- a/rpc/cc/arduino/cli/settings/v1/settings.pb.go +++ b/rpc/cc/arduino/cli/settings/v1/settings.pb.go @@ -15,15 +15,14 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.25.0 -// protoc v3.15.7 +// protoc-gen-go v1.26.0 +// protoc v3.15.8 // source: cc/arduino/cli/settings/v1/settings.proto package settings import ( context "context" - proto "github.com/golang/protobuf/proto" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -40,10 +39,6 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) -// This is a compile-time assertion that a sufficiently up-to-date version -// of the legacy proto package is being used. -const _ = proto.ProtoPackageIsVersion4 - type GetAllResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache diff --git a/test/test_core.py b/test/test_core.py index 1104e795632..7bc5db64348 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -530,3 +530,116 @@ def test_core_search_update_index_delay(run_command, data_dir): res = run_command("core search") assert res.ok assert "Updating index" not in res.stdout + + +def test_core_search_sorted_results(run_command, httpserver): + # Set up the server to serve our custom index file + test_index = Path(__file__).parent / "testdata" / "test_index.json" + httpserver.expect_request("/test_index.json").respond_with_data(test_index.read_text()) + + # update custom index + url = httpserver.url_for("/test_index.json") + assert run_command(f"core update-index --additional-urls={url}") + + # list all with additional url specified + result = run_command(f"core search --additional-urls={url}") + assert result.ok + + lines = [l.strip().split(maxsplit=2) for l in result.stdout.strip().splitlines()][1:] + not_deprecated = [l for l in lines if not l[2].startswith("[DEPRECATED]")] + deprecated = [l for l in lines if l[2].startswith("[DEPRECATED]")] + + # verify that results are already sorted correctly + assert not_deprecated == sorted(not_deprecated, key=lambda tokens: tokens[2]) + assert deprecated == sorted(deprecated, key=lambda tokens: tokens[2]) + + # verify that deprecated platforms are the last ones + assert lines == not_deprecated + deprecated + + # test same behaviour with json output + result = run_command(f"core search --additional-urls={url} --format=json") + assert result.ok + + platforms = json.loads(result.stdout) + not_deprecated = [p for p in platforms if not p.get("deprecated")] + deprecated = [p for p in platforms if p.get("deprecated")] + + # verify that results are already sorted correctly + assert not_deprecated == sorted(not_deprecated, key=lambda keys: keys["name"]) + assert deprecated == sorted(deprecated, key=lambda keys: keys["name"]) + # verify that deprecated platforms are the last ones + assert platforms == not_deprecated + deprecated + + +def test_core_list_sorted_results(run_command, httpserver): + # Set up the server to serve our custom index file + test_index = Path(__file__).parent / "testdata" / "test_index.json" + httpserver.expect_request("/test_index.json").respond_with_data(test_index.read_text()) + + # update custom index + url = httpserver.url_for("/test_index.json") + assert run_command(f"core update-index --additional-urls={url}") + + # install some core for testing + assert run_command(f"core install test:x86 Retrokits-RK002:arm Package:x86 --additional-urls={url}") + + # list all with additional url specified + result = run_command(f"core list --additional-urls={url}") + assert result.ok + + lines = [l.strip().split(maxsplit=3) for l in result.stdout.strip().splitlines()][1:] + assert len(lines) == 3 + not_deprecated = [l for l in lines if not l[3].startswith("[DEPRECATED]")] + deprecated = [l for l in lines if l[3].startswith("[DEPRECATED]")] + + # verify that results are already sorted correctly + assert not_deprecated == sorted(not_deprecated, key=lambda tokens: tokens[3]) + assert deprecated == sorted(deprecated, key=lambda tokens: tokens[3]) + + # verify that deprecated platforms are the last ones + assert lines == not_deprecated + deprecated + + # test same behaviour with json output + result = run_command(f"core list --additional-urls={url} --format=json") + assert result.ok + + platforms = json.loads(result.stdout) + assert len(platforms) == 3 + not_deprecated = [p for p in platforms if not p.get("deprecated")] + deprecated = [p for p in platforms if p.get("deprecated")] + + # verify that results are already sorted correctly + assert not_deprecated == sorted(not_deprecated, key=lambda keys: keys["name"]) + assert deprecated == sorted(deprecated, key=lambda keys: keys["name"]) + # verify that deprecated platforms are the last ones + assert platforms == not_deprecated + deprecated + + +def test_core_list_deprecated_platform_with_installed_json(run_command, httpserver, data_dir): + # Set up the server to serve our custom index file + test_index = Path(__file__).parent / "testdata" / "test_index.json" + httpserver.expect_request("/test_index.json").respond_with_data(test_index.read_text()) + + # update custom index + url = httpserver.url_for("/test_index.json") + assert run_command(f"core update-index --additional-urls={url}") + + # install some core for testing + assert run_command(f"core install Package:x86 --additional-urls={url}") + + installed_json_file = Path(data_dir, "packages", "Package", "hardware", "x86", "1.2.3", "installed.json") + assert installed_json_file.exists() + installed_json = json.load(installed_json_file.open("r")) + platform = installed_json["packages"][0]["platforms"][0] + del platform["deprecated"] + installed_json["packages"][0]["platforms"][0] = platform + with open(installed_json_file, "w") as f: + json.dump(installed_json, f) + + # test same behaviour with json output + result = run_command(f"core list --additional-urls={url} --format=json") + assert result.ok + + platforms = json.loads(result.stdout) + assert len(platforms) == 1 + assert platforms[0]["deprecated"] diff --git a/test/testdata/test_index.json b/test/testdata/test_index.json index 9a1e7405334..66bf497e55e 100644 --- a/test/testdata/test_index.json +++ b/test/testdata/test_index.json @@ -193,6 +193,7 @@ "checksum": "SHA-256:6a338cf4d6d501176a2d352c87a8d72ac7488b8c5b82cdf2a4e2cef630391092", "name": "Platform", "version": "1.2.3", + "deprecated": true, "architecture": "x86", "archiveFileName": "core.zip", "size": "486",