Skip to content

Commit 01c07b6

Browse files
authored
Fix board search not returning boards if installed core is not latest version (arduino#1410)
1 parent f61c1bc commit 01c07b6

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

commands/board/search.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,32 +59,35 @@ func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchR
5959
for _, targetPackage := range pm.Packages {
6060
for _, platform := range targetPackage.Platforms {
6161
latestPlatformRelease := platform.GetLatestRelease()
62-
if latestPlatformRelease == nil {
62+
installedPlatformRelease := pm.GetInstalledPlatformRelease(platform)
63+
64+
if latestPlatformRelease == nil && installedPlatformRelease == nil {
6365
continue
6466
}
65-
installedVersion := ""
66-
if installedPlatformRelease := pm.GetInstalledPlatformRelease(platform); installedPlatformRelease != nil {
67-
installedVersion = installedPlatformRelease.Version.String()
68-
}
6967

7068
rpcPlatform := &rpc.Platform{
7169
Id: platform.String(),
72-
Installed: installedVersion,
73-
Latest: latestPlatformRelease.Version.String(),
7470
Name: platform.Name,
7571
Maintainer: platform.Package.Maintainer,
7672
Website: platform.Package.WebsiteURL,
7773
Email: platform.Package.Email,
7874
ManuallyInstalled: platform.ManuallyInstalled,
7975
}
8076

77+
if latestPlatformRelease != nil {
78+
rpcPlatform.Latest = latestPlatformRelease.Version.String()
79+
}
80+
if installedPlatformRelease != nil {
81+
rpcPlatform.Installed = installedPlatformRelease.Version.String()
82+
}
83+
8184
// Platforms that are not installed don't have a list of boards
8285
// generated from their boards.txt file so we need two different
8386
// ways of reading board data.
8487
// The only boards information for platforms that are not installed
8588
// is that found in the index, usually that's only a board name.
86-
if len(latestPlatformRelease.Boards) != 0 {
87-
for _, board := range latestPlatformRelease.Boards {
89+
if installedPlatformRelease != nil {
90+
for _, board := range installedPlatformRelease.Boards {
8891
if !req.GetIncludeHiddenBoards() && board.IsHidden() {
8992
continue
9093
}
@@ -103,7 +106,7 @@ func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchR
103106
Platform: rpcPlatform,
104107
})
105108
}
106-
} else {
109+
} else if latestPlatformRelease != nil {
107110
for _, board := range latestPlatformRelease.BoardsManifest {
108111
toTest := append(strings.Split(board.Name, " "), board.Name)
109112
if ok, err := match(toTest); err != nil {

test/test_board.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from pathlib import Path
1616
from git import Repo
1717
import simplejson as json
18+
import semver
1819

1920

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

659660
assert run_command(f"board attach {fqbn} {sketch_path}")
661+
662+
663+
def test_board_search_with_outdated_core(run_command):
664+
assert run_command("update")
665+
666+
# Install an old core version
667+
assert run_command("core install arduino:samd@1.8.6")
668+
669+
res = run_command("board search arduino:samd:mkrwifi1010 --format json")
670+
671+
data = json.loads(res.stdout)
672+
assert len(data) == 1
673+
board = data[0]
674+
assert board["name"] == "Arduino MKR WiFi 1010"
675+
assert board["fqbn"] == "arduino:samd:mkrwifi1010"
676+
samd_core = board["platform"]
677+
assert samd_core["id"] == "arduino:samd"
678+
installed_version = semver.parse_version_info(samd_core["installed"])
679+
latest_version = semver.parse_version_info(samd_core["latest"])
680+
# Installed version must be older than latest
681+
assert installed_version.compare(latest_version) == -1

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy