Skip to content

Commit fefc306

Browse files
committed
Fix builtin discovery tools not being loaded if no platform is installed (arduino#1428)
* Fix integration tests detected_boards fixture * Fix builtin discoveries not loaded if no platform is installed * [skip changelog] Add missing breaking change to UPGRADING.md * [skip changelog] Fix board list test running on CI * [skip changelog] Fix UPGRADING.md
1 parent ca1b0ef commit fefc306

File tree

7 files changed

+120
-35
lines changed

7 files changed

+120
-35
lines changed

arduino/cores/packagemanager/loader.go

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,39 @@ func (pm *PackageManager) LoadDiscoveries() []*status.Status {
683683
for _, platform := range pm.InstalledPlatformReleases() {
684684
statuses = append(statuses, pm.loadDiscoveries(platform)...)
685685
}
686+
if st := pm.loadBuiltinDiscoveries(); len(st) > 0 {
687+
statuses = append(statuses, st...)
688+
}
689+
return statuses
690+
}
691+
692+
// loadDiscovery loads the discovery tool with id, if it cannot be found a non-nil status is returned
693+
func (pm *PackageManager) loadDiscovery(id string) *status.Status {
694+
tool := pm.GetTool(id)
695+
if tool == nil {
696+
return status.Newf(codes.FailedPrecondition, tr("discovery not found: %s"), id)
697+
}
698+
toolRelease := tool.GetLatestInstalled()
699+
if toolRelease == nil {
700+
return status.Newf(codes.FailedPrecondition, tr("discovery not installed: %s"), id)
701+
}
702+
discoveryPath := toolRelease.InstallDir.Join(tool.Name).String()
703+
d, err := discovery.New(id, discoveryPath)
704+
if err != nil {
705+
return status.Newf(codes.FailedPrecondition, tr("creating discovery: %s"), err)
706+
}
707+
pm.discoveryManager.Add(d)
708+
return nil
709+
}
710+
711+
// loadBuiltinDiscoveries loads the discovery tools that are part of the builtin package
712+
func (pm *PackageManager) loadBuiltinDiscoveries() []*status.Status {
713+
statuses := []*status.Status{}
714+
for _, id := range []string{"builtin:serial-discovery", "builtin:mdns-discovery"} {
715+
if st := pm.loadDiscovery(id); st != nil {
716+
statuses = append(statuses, st)
717+
}
718+
}
686719
return statuses
687720
}
688721

@@ -705,23 +738,9 @@ func (pm *PackageManager) loadDiscoveries(release *cores.PlatformRelease) []*sta
705738
//
706739
// If both indexed and unindexed properties are found the unindexed are ignored
707740
for _, id := range discoveryProperties.ExtractSubIndexLists("required") {
708-
tool := pm.GetTool(id)
709-
if tool == nil {
710-
statuses = append(statuses, status.Newf(codes.FailedPrecondition, tr("discovery not found: %s"), id))
711-
continue
712-
}
713-
toolRelease := tool.GetLatestInstalled()
714-
if toolRelease == nil {
715-
statuses = append(statuses, status.Newf(codes.FailedPrecondition, tr("discovery not installed: %s"), id))
716-
continue
717-
}
718-
discoveryPath := toolRelease.InstallDir.Join(tool.Name).String()
719-
d, err := discovery.New(id, discoveryPath)
720-
if err != nil {
721-
statuses = append(statuses, status.Newf(codes.FailedPrecondition, tr("creating discovery: %s"), err))
722-
continue
741+
if st := pm.loadDiscovery(id); st != nil {
742+
statuses = append(statuses, st)
723743
}
724-
pm.discoveryManager.Add(d)
725744
}
726745

727746
discoveryIDs := discoveryProperties.FirstLevelOf()

arduino/cores/packagemanager/loader_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ func TestLoadDiscoveries(t *testing.T) {
141141
})
142142

143143
errs := packageManager.LoadDiscoveries()
144-
require.Len(t, errs, 0)
144+
require.Len(t, errs, 2)
145+
require.Equal(t, errs[0].Message(), "discovery not found: builtin:serial-discovery")
146+
require.Equal(t, errs[1].Message(), "discovery not found: builtin:mdns-discovery")
145147
discoveries := packageManager.DiscoveryManager().IDs()
146148
require.Len(t, discoveries, 1)
147149
require.Contains(t, discoveries, "arduino:ble-discovery")
@@ -154,7 +156,9 @@ func TestLoadDiscoveries(t *testing.T) {
154156
})
155157

156158
errs = packageManager.LoadDiscoveries()
157-
require.Len(t, errs, 0)
159+
require.Len(t, errs, 2)
160+
require.Equal(t, errs[0].Message(), "discovery not found: builtin:serial-discovery")
161+
require.Equal(t, errs[1].Message(), "discovery not found: builtin:mdns-discovery")
158162
discoveries = packageManager.DiscoveryManager().IDs()
159163
require.Len(t, discoveries, 2)
160164
require.Contains(t, discoveries, "arduino:ble-discovery")
@@ -169,7 +173,9 @@ func TestLoadDiscoveries(t *testing.T) {
169173
})
170174

171175
errs = packageManager.LoadDiscoveries()
172-
require.Len(t, errs, 0)
176+
require.Len(t, errs, 2)
177+
require.Equal(t, errs[0].Message(), "discovery not found: builtin:serial-discovery")
178+
require.Equal(t, errs[1].Message(), "discovery not found: builtin:mdns-discovery")
173179
discoveries = packageManager.DiscoveryManager().IDs()
174180
require.Len(t, discoveries, 3)
175181
require.Contains(t, discoveries, "arduino:ble-discovery")
@@ -186,7 +192,9 @@ func TestLoadDiscoveries(t *testing.T) {
186192
})
187193

188194
errs = packageManager.LoadDiscoveries()
189-
require.Len(t, errs, 0)
195+
require.Len(t, errs, 2)
196+
require.Equal(t, errs[0].Message(), "discovery not found: builtin:serial-discovery")
197+
require.Equal(t, errs[1].Message(), "discovery not found: builtin:mdns-discovery")
190198
discoveries = packageManager.DiscoveryManager().IDs()
191199
require.Len(t, discoveries, 3)
192200
require.Contains(t, discoveries, "arduino:ble-discovery")

docs/UPGRADING.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,62 @@ Here you can find a list of migration guides to handle breaking changes between
44

55
## 0.19.0
66

7+
### `board list` command JSON output change
8+
9+
The `board list` command JSON output has been changed quite a bit, from:
10+
11+
```
12+
$ arduino-cli board list --format json
13+
[
14+
{
15+
"address": "/dev/ttyACM1",
16+
"protocol": "serial",
17+
"protocol_label": "Serial Port (USB)",
18+
"boards": [
19+
{
20+
"name": "Arduino Uno",
21+
"fqbn": "arduino:avr:uno",
22+
"vid": "0x2341",
23+
"pid": "0x0043"
24+
}
25+
],
26+
"serial_number": "954323132383515092E1"
27+
}
28+
]
29+
```
30+
31+
to:
32+
33+
```
34+
$ arduino-cli board list --format json
35+
[
36+
{
37+
"matching_boards": [
38+
{
39+
"name": "Arduino Uno",
40+
"fqbn": "arduino:avr:uno"
41+
}
42+
],
43+
"port": {
44+
"address": "/dev/ttyACM1",
45+
"label": "/dev/ttyACM1",
46+
"protocol": "serial",
47+
"protocol_label": "Serial Port (USB)",
48+
"properties": {
49+
"pid": "0x0043",
50+
"serialNumber": "954323132383515092E1",
51+
"vid": "0x2341"
52+
}
53+
}
54+
}
55+
]
56+
```
57+
58+
The `boards` array has been renamed `matching_boards`, each contained object will now contain only `name` and `fqbn`.
59+
Properties that can be used to identify a board are now moved to the new `properties` object, it can contain any key
60+
name. `pid` and `vid` have been moved to `properties`, `serial_number` has been renamed `serialNumber` and moved to
61+
`properties`. The new `label` field is the name of the `port` if it should be displayed in a GUI.
62+
763
### gRPC interface `DebugConfigRequest`, `UploadRequest`, `UploadUsingProgrammerRequest`, `BurnBootloaderRequest`, `DetectedPort` field changes
864

965
`DebugConfigRequest`, `UploadRequest`, `UploadUsingProgrammerRequest` and `BurnBootloaderRequest` had their `port` field

i18n/data/en.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,7 +2447,7 @@ msgstr "can't find latest release of %s"
24472447
msgid "can't find main Sketch file in %s"
24482448
msgstr "can't find main Sketch file in %s"
24492449

2450-
#: arduino/cores/packagemanager/loader.go:749
2450+
#: arduino/cores/packagemanager/loader.go:768
24512451
msgid "can't find pattern for discovery with id %s"
24522452
msgstr "can't find pattern for discovery with id %s"
24532453

@@ -2518,7 +2518,7 @@ msgstr "computing hash: %s"
25182518
msgid "could not find a valid build artifact"
25192519
msgstr "could not find a valid build artifact"
25202520

2521-
#: arduino/cores/packagemanager/loader.go:721
2521+
#: arduino/cores/packagemanager/loader.go:705
25222522
msgid "creating discovery: %s"
25232523
msgstr "creating discovery: %s"
25242524

@@ -2555,11 +2555,11 @@ msgstr "destination dir %s already exists, cannot install"
25552555
msgid "discovery %[1]s process not started: %[2]w"
25562556
msgstr "discovery %[1]s process not started: %[2]w"
25572557

2558-
#: arduino/cores/packagemanager/loader.go:710
2558+
#: arduino/cores/packagemanager/loader.go:696
25592559
msgid "discovery not found: %s"
25602560
msgstr "discovery not found: %s"
25612561

2562-
#: arduino/cores/packagemanager/loader.go:715
2562+
#: arduino/cores/packagemanager/loader.go:700
25632563
msgid "discovery not installed: %s"
25642564
msgstr "discovery not installed: %s"
25652565

i18n/rice-box.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/conftest.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,12 @@ def detected_boards(run_command):
203203

204204
detected_boards = []
205205
for port in json.loads(result.stdout):
206-
for board in port.get("boards", []):
207-
fqbn = board.get("FQBN")
208-
if not fqbn:
209-
continue
206+
for board in port.get("matching_boards", []):
207+
fqbn = board.get("fqbn")
210208
package, architecture, _id = fqbn.split(":")
211209
detected_boards.append(
212210
Board(
213-
address=port.get("address"),
211+
address=port["port"]["address"],
214212
fqbn=fqbn,
215213
package=package,
216214
architecture=architecture,

test/test_board.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
from git import Repo
1717
import simplejson as json
1818
import semver
19+
import pytest
20+
21+
from .common import running_on_ci
1922

2023

2124
gold_board = """
@@ -389,6 +392,7 @@
389392
""" # noqa: E501
390393

391394

395+
@pytest.mark.skipif(running_on_ci(), reason="VMs have no serial ports")
392396
def test_board_list(run_command):
393397
run_command("core update-index")
394398
result = run_command("board list --format json")
@@ -397,8 +401,8 @@ def test_board_list(run_command):
397401
ports = json.loads(result.stdout)
398402
assert isinstance(ports, list)
399403
for port in ports:
400-
assert "protocol" in port
401-
assert "protocol_label" in port
404+
assert "protocol" in port["port"]
405+
assert "protocol_label" in port["port"]
402406

403407

404408
def test_board_listall(run_command):

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