From cc1bbab0f14ceab6ac65cead0573127a341b8b12 Mon Sep 17 00:00:00 2001 From: Alessio Perugini Date: Thu, 21 Sep 2023 12:28:53 +0200 Subject: [PATCH] expose Incompatible properity in the API --- commands/board/listall.go | 1 + commands/board/search.go | 1 + commands/core.go | 1 + commands/core/search.go | 8 ++- commands/core/search_test.go | 12 +++- internal/integrationtest/core/core_test.go | 22 +++++++- rpc/cc/arduino/cli/commands/v1/common.pb.go | 61 ++++++++++++--------- rpc/cc/arduino/cli/commands/v1/common.proto | 2 + 8 files changed, 78 insertions(+), 30 deletions(-) diff --git a/commands/board/listall.go b/commands/board/listall.go index bab60ae63a3..6da56a88fca 100644 --- a/commands/board/listall.go +++ b/commands/board/listall.go @@ -68,6 +68,7 @@ func ListAll(ctx context.Context, req *rpc.BoardListAllRequest) (*rpc.BoardListA ManuallyInstalled: platform.ManuallyInstalled, Indexed: platform.Indexed, MissingMetadata: !installedPlatformRelease.HasMetadata(), + Incompatible: installedPlatformRelease.IsIncompatible(), } toTest := []string{ diff --git a/commands/board/search.go b/commands/board/search.go index 609b52095af..8e05b789b6a 100644 --- a/commands/board/search.go +++ b/commands/board/search.go @@ -66,6 +66,7 @@ func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchR if installedPlatformRelease != nil { rpcPlatform.Installed = installedPlatformRelease.Version.String() rpcPlatform.MissingMetadata = !installedPlatformRelease.HasMetadata() + rpcPlatform.Incompatible = installedPlatformRelease.IsIncompatible() } // Platforms that are not installed don't have a list of boards diff --git a/commands/core.go b/commands/core.go index f75fbce04f4..ed59d4d37b5 100644 --- a/commands/core.go +++ b/commands/core.go @@ -64,6 +64,7 @@ func PlatformReleaseToRPC(platformRelease *cores.PlatformRelease) *rpc.Platform Type: []string{platformRelease.Platform.Category}, Indexed: platformRelease.Platform.Indexed, MissingMetadata: !platformRelease.HasMetadata(), + Incompatible: platformRelease.IsIncompatible(), } return result diff --git a/commands/core/search.go b/commands/core/search.go index 69b81e3b369..0d5609a8f0e 100644 --- a/commands/core/search.go +++ b/commands/core/search.go @@ -75,9 +75,13 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse if allVersions { res = append(res, platform.GetAllReleases()...) - } else { - res = append(res, latestRelease) + continue + } + if latestCompatibleRelease := platform.GetLatestCompatibleRelease(); latestCompatibleRelease != nil { + res = append(res, platform.GetLatestCompatibleRelease()) + continue } + res = append(res, latestRelease) } } } diff --git a/commands/core/search_test.go b/commands/core/search_test.go index 2bbb027abf5..80e250e7544 100644 --- a/commands/core/search_test.go +++ b/commands/core/search_test.go @@ -27,7 +27,6 @@ import ( ) func TestPlatformSearch(t *testing.T) { - dataDir := paths.TempDir().Join("test", "data_dir") downloadDir := paths.TempDir().Join("test", "staging") os.Setenv("ARDUINO_DATA_DIR", dataDir.String()) @@ -65,6 +64,7 @@ func TestPlatformSearch(t *testing.T) { Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"}, Indexed: true, MissingMetadata: true, + Incompatible: true, }) require.Contains(t, res.SearchOutput, &rpc.Platform{ Id: "Retrokits-RK002:arm", @@ -79,6 +79,7 @@ func TestPlatformSearch(t *testing.T) { Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"}, Indexed: true, MissingMetadata: true, + Incompatible: true, }) res, stat = PlatformSearch(&rpc.PlatformSearchRequest{ @@ -102,6 +103,7 @@ func TestPlatformSearch(t *testing.T) { Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"}, Indexed: true, MissingMetadata: true, + Incompatible: true, }) // Search the Package Maintainer @@ -126,6 +128,7 @@ func TestPlatformSearch(t *testing.T) { Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"}, Indexed: true, MissingMetadata: true, + Incompatible: true, }) require.Contains(t, res.SearchOutput, &rpc.Platform{ Id: "Retrokits-RK002:arm", @@ -140,6 +143,7 @@ func TestPlatformSearch(t *testing.T) { Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"}, Indexed: true, MissingMetadata: true, + Incompatible: true, }) // Search using the Package name @@ -164,6 +168,7 @@ func TestPlatformSearch(t *testing.T) { Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"}, Indexed: true, MissingMetadata: true, + Incompatible: true, }) require.Contains(t, res.SearchOutput, &rpc.Platform{ Id: "Retrokits-RK002:arm", @@ -178,6 +183,7 @@ func TestPlatformSearch(t *testing.T) { Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"}, Indexed: true, MissingMetadata: true, + Incompatible: true, }) // Search using the Platform name @@ -202,6 +208,7 @@ func TestPlatformSearch(t *testing.T) { Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"}, Indexed: true, MissingMetadata: true, + Incompatible: true, }) require.Contains(t, res.SearchOutput, &rpc.Platform{ Id: "Retrokits-RK002:arm", @@ -216,6 +223,7 @@ func TestPlatformSearch(t *testing.T) { Help: &rpc.HelpResources{Online: "https://www.retrokits.com/rk002/arduino"}, Indexed: true, MissingMetadata: true, + Incompatible: true, }) // Search using a board name @@ -267,6 +275,7 @@ func TestPlatformSearch(t *testing.T) { Help: &rpc.HelpResources{Online: "http://www.arduino.cc/en/Reference/HomePage"}, Indexed: true, MissingMetadata: true, + Incompatible: true, }) res, stat = PlatformSearch(&rpc.PlatformSearchRequest{ @@ -317,6 +326,7 @@ func TestPlatformSearch(t *testing.T) { Help: &rpc.HelpResources{Online: "http://www.arduino.cc/en/Reference/HomePage"}, Indexed: true, MissingMetadata: true, + Incompatible: true, }) } diff --git a/internal/integrationtest/core/core_test.go b/internal/integrationtest/core/core_test.go index 4e405a7a1d3..1a4a0335b5c 100644 --- a/internal/integrationtest/core/core_test.go +++ b/internal/integrationtest/core/core_test.go @@ -181,8 +181,8 @@ func TestCoreSearchNoArgs(t *testing.T) { for _, v := range strings.Split(strings.TrimSpace(string(stdout)), "\n") { lines = append(lines, strings.Fields(strings.TrimSpace(v))) } - // Check the presence of test:x86@3.0.0 - require.Contains(t, lines, []string{"test:x86", "3.0.0", "test_core"}) + // Check the absence of test:x86@3.0.0 because it contains incompatible deps + require.NotContains(t, lines, []string{"test:x86", "3.0.0", "test_core"}) numPlatforms = len(lines) - 1 // same thing in JSON format, also check the number of platforms found is the same @@ -1143,4 +1143,22 @@ func TestCoreHavingIncompatibleDepTools(t *testing.T) { _, stderr, err = cli.Run("core", "install", "incompatible_vendor:avr", additionalURLs) require.Error(t, err) require.Contains(t, string(stderr), "has no available releases for your OS") + + // Core search --all shows incompatible field when a version is incompatible + stdout, _, err = cli.Run("core", "search", "--all", "--format", "json", additionalURLs) + require.NoError(t, err) + requirejson.Query(t, stdout, + `[.[] | select(.id == "foo_vendor:avr") | {latest: .latest, incompatible: .incompatible}] | sort_by(.latest)`, + `[ + {"incompatible":null,"latest":"1.0.0"}, + {"incompatible":null,"latest":"1.0.1"}, + {"incompatible":true,"latest":"1.0.2"} + ]`, + ) + + // Core search shows latest compatible version + stdout, _, err = cli.Run("core", "search", "--format", "json", additionalURLs) + require.NoError(t, err) + requirejson.Query(t, stdout, `.[] | select(.id == "foo_vendor:avr") | .latest`, `"1.0.1"`) + requirejson.Query(t, stdout, `.[] | select(.id == "incompatible_vendor:avr") | .incompatible`, `true`) } diff --git a/rpc/cc/arduino/cli/commands/v1/common.pb.go b/rpc/cc/arduino/cli/commands/v1/common.pb.go index 95b0954226d..221399e601e 100644 --- a/rpc/cc/arduino/cli/commands/v1/common.pb.go +++ b/rpc/cc/arduino/cli/commands/v1/common.pb.go @@ -532,6 +532,8 @@ type Platform struct { // Newest available version of the platform containing all compatible // dependencies. LatestCompatible string `protobuf:"bytes,15,opt,name=latest_compatible,json=latestCompatible,proto3" json:"latest_compatible,omitempty"` + // True if the platform contains an incompatible dependency. + Incompatible bool `protobuf:"varint,16,opt,name=incompatible,proto3" json:"incompatible,omitempty"` } func (x *Platform) Reset() { @@ -671,6 +673,13 @@ func (x *Platform) GetLatestCompatible() string { return "" } +func (x *Platform) GetIncompatible() bool { + if x != nil { + return x.Incompatible + } + return false +} + type InstalledPlatformReference struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -961,7 +970,7 @@ var file_cc_arduino_cli_commands_v1_common_proto_rawDesc = []byte{ 0x66, 0x6f, 0x72, 0x6d, 0x18, 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, 0x83, 0x04, 0x0a, 0x08, 0x50, 0x6c, 0x61, + 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0xa7, 0x04, 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, @@ -993,30 +1002,32 @@ var file_cc_arduino_cli_commands_v1_common_proto_rawDesc = []byte{ 0x52, 0x0f, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x2b, 0x0a, 0x11, 0x6c, 0x61, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x69, 0x62, 0x6c, 0x65, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x6c, 0x61, - 0x74, 0x65, 0x73, 0x74, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x69, 0x62, 0x6c, 0x65, 0x22, 0x88, - 0x01, 0x0a, 0x1a, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x65, 0x64, 0x50, 0x6c, 0x61, 0x74, - 0x66, 0x6f, 0x72, 0x6d, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x0e, 0x0a, - 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, - 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, - 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x69, 0x6e, 0x73, 0x74, 0x61, - 0x6c, 0x6c, 0x5f, 0x64, 0x69, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x69, 0x6e, - 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x44, 0x69, 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x70, 0x61, 0x63, 0x6b, - 0x61, 0x67, 0x65, 0x5f, 0x75, 0x72, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x70, - 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x55, 0x72, 0x6c, 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, 0x22, 0x31, 0x0a, 0x07, 0x50, 0x72, - 0x6f, 0x66, 0x69, 0x6c, 0x65, 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, 0x22, 0x27, 0x0a, - 0x0d, 0x48, 0x65, 0x6c, 0x70, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x12, 0x16, - 0x0a, 0x06, 0x6f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, - 0x6f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x42, 0x48, 0x5a, 0x46, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, - 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2f, 0x61, 0x72, 0x64, - 0x75, 0x69, 0x6e, 0x6f, 0x2d, 0x63, 0x6c, 0x69, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x63, 0x63, 0x2f, - 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2f, 0x63, 0x6c, 0x69, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, - 0x61, 0x6e, 0x64, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x74, 0x65, 0x73, 0x74, 0x43, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x69, 0x62, 0x6c, 0x65, 0x12, 0x22, + 0x0a, 0x0c, 0x69, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x69, 0x62, 0x6c, 0x65, 0x18, 0x10, + 0x20, 0x01, 0x28, 0x08, 0x52, 0x0c, 0x69, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74, 0x69, 0x62, + 0x6c, 0x65, 0x22, 0x88, 0x01, 0x0a, 0x1a, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x65, 0x64, + 0x50, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, + 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, + 0x64, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x69, + 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x5f, 0x64, 0x69, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x44, 0x69, 0x72, 0x12, 0x1f, 0x0a, 0x0b, + 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x5f, 0x75, 0x72, 0x6c, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0a, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x55, 0x72, 0x6c, 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, 0x22, 0x31, + 0x0a, 0x07, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 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, 0x22, 0x27, 0x0a, 0x0d, 0x48, 0x65, 0x6c, 0x70, 0x52, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, + 0x65, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x06, 0x6f, 0x6e, 0x6c, 0x69, 0x6e, 0x65, 0x42, 0x48, 0x5a, 0x46, 0x67, 0x69, + 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, + 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2d, 0x63, 0x6c, 0x69, 0x2f, 0x72, 0x70, 0x63, + 0x2f, 0x63, 0x63, 0x2f, 0x61, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x2f, 0x63, 0x6c, 0x69, 0x2f, + 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x73, 0x2f, 0x76, 0x31, 0x3b, 0x63, 0x6f, 0x6d, 0x6d, + 0x61, 0x6e, 0x64, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/rpc/cc/arduino/cli/commands/v1/common.proto b/rpc/cc/arduino/cli/commands/v1/common.proto index 0a20fb12b37..cf45212055e 100644 --- a/rpc/cc/arduino/cli/commands/v1/common.proto +++ b/rpc/cc/arduino/cli/commands/v1/common.proto @@ -111,6 +111,8 @@ message Platform { // Newest available version of the platform containing all compatible // dependencies. string latest_compatible = 15; + // True if the platform contains an incompatible dependency. + bool incompatible = 16; } message InstalledPlatformReference {