Skip to content

Commit

Permalink
expose Incompatible properity in the API
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Sep 21, 2023
1 parent 2a9a291 commit cc1bbab
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 30 deletions.
1 change: 1 addition & 0 deletions commands/board/listall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 1 addition & 0 deletions commands/board/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions commands/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions commands/core/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion commands/core/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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",
Expand All @@ -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{
Expand All @@ -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
Expand All @@ -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",
Expand All @@ -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
Expand All @@ -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",
Expand All @@ -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
Expand All @@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
})
}

Expand Down
22 changes: 20 additions & 2 deletions internal/integrationtest/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]
require.Contains(t, lines, []string{"test:x86", "3.0.0", "test_core"})
// Check the absence of test:[email protected] 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
Expand Down Expand Up @@ -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`)
}
61 changes: 36 additions & 25 deletions rpc/cc/arduino/cli/commands/v1/common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions rpc/cc/arduino/cli/commands/v1/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit cc1bbab

Please sign in to comment.