Skip to content

Fix board search not returning boards if installed core is not latest version #1410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions commands/board/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,32 +59,35 @@ func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchR
for _, targetPackage := range pm.Packages {
for _, platform := range targetPackage.Platforms {
latestPlatformRelease := platform.GetLatestRelease()
if latestPlatformRelease == nil {
installedPlatformRelease := pm.GetInstalledPlatformRelease(platform)

if latestPlatformRelease == nil && installedPlatformRelease == nil {
continue
}
installedVersion := ""
if installedPlatformRelease := pm.GetInstalledPlatformRelease(platform); installedPlatformRelease != nil {
installedVersion = installedPlatformRelease.Version.String()
}

rpcPlatform := &rpc.Platform{
Id: platform.String(),
Installed: installedVersion,
Latest: latestPlatformRelease.Version.String(),
Name: platform.Name,
Maintainer: platform.Package.Maintainer,
Website: platform.Package.WebsiteURL,
Email: platform.Package.Email,
ManuallyInstalled: platform.ManuallyInstalled,
}

if latestPlatformRelease != nil {
rpcPlatform.Latest = latestPlatformRelease.Version.String()
}
if installedPlatformRelease != nil {
rpcPlatform.Installed = installedPlatformRelease.Version.String()
}

// Platforms that are not installed don't have a list of boards
// generated from their boards.txt file so we need two different
// ways of reading board data.
// The only boards information for platforms that are not installed
// is that found in the index, usually that's only a board name.
if len(latestPlatformRelease.Boards) != 0 {
for _, board := range latestPlatformRelease.Boards {
if installedPlatformRelease != nil {
for _, board := range installedPlatformRelease.Boards {
if !req.GetIncludeHiddenBoards() && board.IsHidden() {
continue
}
Expand All @@ -103,7 +106,7 @@ func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchR
Platform: rpcPlatform,
})
}
} else {
} else if latestPlatformRelease != nil {
for _, board := range latestPlatformRelease.BoardsManifest {
toTest := append(strings.Split(board.Name, " "), board.Name)
if ok, err := match(toTest); err != nil {
Expand Down
22 changes: 22 additions & 0 deletions test/test_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from pathlib import Path
from git import Repo
import simplejson as json
import semver


gold_board = """
Expand Down Expand Up @@ -657,3 +658,24 @@ def test_board_attach_without_sketch_json(run_command, data_dir):
assert run_command(f"sketch new {sketch_path}")

assert run_command(f"board attach {fqbn} {sketch_path}")


def test_board_search_with_outdated_core(run_command):
assert run_command("update")

# Install an old core version
assert run_command("core install arduino:[email protected]")

res = run_command("board search arduino:samd:mkrwifi1010 --format json")

data = json.loads(res.stdout)
assert len(data) == 1
board = data[0]
assert board["name"] == "Arduino MKR WiFi 1010"
assert board["fqbn"] == "arduino:samd:mkrwifi1010"
samd_core = board["platform"]
assert samd_core["id"] == "arduino:samd"
installed_version = semver.parse_version_info(samd_core["installed"])
latest_version = semver.parse_version_info(samd_core["latest"])
# Installed version must be older than latest
assert installed_version.compare(latest_version) == -1