diff --git a/commands/board/search.go b/commands/board/search.go index 41c2b049371..75870b2173e 100644 --- a/commands/board/search.go +++ b/commands/board/search.go @@ -59,18 +59,14 @@ 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, @@ -78,13 +74,20 @@ func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchR 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 } @@ -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 { diff --git a/test/test_board.py b/test/test_board.py index 2f50de9b7b1..02efedc9ab1 100644 --- a/test/test_board.py +++ b/test/test_board.py @@ -15,6 +15,7 @@ from pathlib import Path from git import Repo import simplejson as json +import semver gold_board = """ @@ -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:samd@1.8.6") + + 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