From 7a89db1ca7515f6aee86f7b6af8661c5701a6568 Mon Sep 17 00:00:00 2001 From: umbynos Date: Thu, 6 May 2021 11:45:57 +0200 Subject: [PATCH 1/7] updated tests --- test/test_core.py | 78 +++++++++++++++++++++++++++++++++++ test/testdata/test_index.json | 1 + 2 files changed, 79 insertions(+) diff --git a/test/test_core.py b/test/test_core.py index 1104e795632..8c8f8540dfa 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -530,3 +530,81 @@ 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 == deprecated + not_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 == deprecated + not_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}") + + # 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:] + 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 == deprecated + not_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) + 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 == deprecated + not_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", From 828cb2e97bae41bcc6dbf7c647bef07ca1223754 Mon Sep 17 00:00:00 2001 From: umbynos Date: Thu, 6 May 2021 12:36:55 +0200 Subject: [PATCH 2/7] add first draft of sorting --- arduino/cores/cores.go | 1 + arduino/cores/packageindex/index.go | 1 + commands/core.go | 1 + commands/core/list.go | 10 +++++- commands/core/search.go | 9 +++++ commands/core/search_test.go | 35 +++++++++++++++++++ commands/core/testdata/package_index.json | 34 +++++++++++++++++- rpc/cc/arduino/cli/commands/v1/board.pb.go | 9 ++--- rpc/cc/arduino/cli/commands/v1/commands.pb.go | 9 ++--- rpc/cc/arduino/cli/commands/v1/common.pb.go | 24 ++++++++----- rpc/cc/arduino/cli/commands/v1/common.proto | 2 ++ rpc/cc/arduino/cli/commands/v1/compile.pb.go | 9 ++--- rpc/cc/arduino/cli/commands/v1/core.pb.go | 9 ++--- rpc/cc/arduino/cli/commands/v1/lib.pb.go | 9 ++--- rpc/cc/arduino/cli/commands/v1/upload.pb.go | 9 ++--- rpc/cc/arduino/cli/debug/v1/debug.pb.go | 9 ++--- rpc/cc/arduino/cli/monitor/v1/monitor.pb.go | 9 ++--- rpc/cc/arduino/cli/settings/v1/settings.pb.go | 9 ++--- 18 files changed, 124 insertions(+), 74 deletions(-) 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..649200ca26c 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"` 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..cbb5206bdf3 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,12 @@ 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 { + return res[i].Deprecated && res[j].Deprecated + }) return res, nil } diff --git a/commands/core/search.go b/commands/core/search.go index 83f76c53597..4699dde90ec 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,13 @@ 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 { + return out[i].Deprecated && out[j].Deprecated + }) 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 From fca3ac0c166e0020c448798093e6073c920847b4 Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Thu, 6 May 2021 17:22:50 +0200 Subject: [PATCH 3/7] finished/fixed implementation of tests --- test/test_core.py | 50 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/test/test_core.py b/test/test_core.py index 8c8f8540dfa..55bed681311 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -546,15 +546,15 @@ def test_core_search_sorted_results(run_command, httpserver): 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]")] + 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 == deprecated + not_deprecated + assert lines == not_deprecated + deprecated # test same behaviour with json output result = run_command(f"core search --additional-urls={url} --format=json") @@ -568,7 +568,7 @@ def test_core_search_sorted_results(run_command, httpserver): 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 == deprecated + not_deprecated + assert platforms == not_deprecated + deprecated def test_core_list_sorted_results(run_command, httpserver): @@ -580,26 +580,31 @@ def test_core_list_sorted_results(run_command, httpserver): 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:] - not_deprecated = [l for l in lines if not l[3].startsWith("[DEPRECATED]")] - deprecated = [l for l in lines if l[3].startsWith("[DEPRECATED]")] + 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 == deprecated + not_deprecated + 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")] @@ -607,4 +612,33 @@ def test_core_list_sorted_results(run_command, httpserver): 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 == deprecated + not_deprecated + 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"] From 4288a6d86414685652784a680c93cb4395bec1c4 Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Thu, 6 May 2021 17:24:21 +0200 Subject: [PATCH 4/7] implementation of sorting function is now correct --- commands/core/list.go | 5 ++++- commands/core/search.go | 12 ++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/commands/core/list.go b/commands/core/list.go index cbb5206bdf3..2e69fa04c44 100644 --- a/commands/core/list.go +++ b/commands/core/list.go @@ -74,7 +74,10 @@ func GetPlatforms(req *rpc.PlatformListRequest) ([]*rpc.Platform, error) { return res[i].Name < res[j].Name }) sort.SliceStable(res, func(i, j int) bool { - return res[i].Deprecated && res[j].Deprecated + 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 4699dde90ec..b2d81cbe8d0 100644 --- a/commands/core/search.go +++ b/commands/core/search.go @@ -115,12 +115,16 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse 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.Slice( + out, func(i, j int) bool { + return out[i].Name < out[j].Name + }) sort.SliceStable( out, func(i, j int) bool { - return out[i].Deprecated && out[j].Deprecated + if !out[i].Deprecated && out[j].Deprecated { + return true + } + return false }) return &rpc.PlatformSearchResponse{SearchOutput: out}, nil } From 338ebe42ff0a337209415d023fe0e21c136e69a3 Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Thu, 6 May 2021 17:25:27 +0200 Subject: [PATCH 5/7] removed sorting from the cli (previously added in commands) and add [DEPRECATED] to the name --- cli/core/list.go | 11 ++++++----- cli/core/search.go | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) 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() } From e592a449b1bb8c4fa3921eda8d5e2e3e8b1c29c1 Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Thu, 6 May 2021 17:26:16 +0200 Subject: [PATCH 6/7] fixed deprecation notice not being printed if installed.json was already present --- arduino/cores/packageindex/index.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arduino/cores/packageindex/index.go b/arduino/cores/packageindex/index.go index 649200ca26c..8297075ee5d 100644 --- a/arduino/cores/packageindex/index.go +++ b/arduino/cores/packageindex/index.go @@ -168,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, @@ -206,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 { From 2f7a23d5c13dec147771766073fc2abee4cbdad1 Mon Sep 17 00:00:00 2001 From: Umberto Baldi Date: Thu, 6 May 2021 17:36:54 +0200 Subject: [PATCH 7/7] fix formatting --- test/test_core.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_core.py b/test/test_core.py index 55bed681311..7bc5db64348 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -614,6 +614,7 @@ def test_core_list_sorted_results(run_command, httpserver): # 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"