Skip to content

Commit 65b2ea6

Browse files
authored
Fix crash when loading boards (#1354)
1 parent df2d30e commit 65b2ea6

File tree

4 files changed

+99
-6
lines changed

4 files changed

+99
-6
lines changed

Diff for: arduino/cores/packagemanager/loader.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -384,19 +384,16 @@ func (pm *PackageManager) loadBoards(platform *cores.PlatformRelease) error {
384384
} else {
385385
platform.Menus = properties.NewMap()
386386
}
387+
// This is not a board id so we remove it to correctly
388+
// set all other boards properties
389+
delete(propertiesByBoard, "menu")
387390

388391
if !platform.PluggableDiscoveryAware {
389392
for _, boardProperties := range propertiesByBoard {
390393
convertVidPidIdentificationPropertiesToPluggableDiscovery(boardProperties)
391394
}
392395
}
393396

394-
platform.Menus = propertiesByBoard["menu"]
395-
396-
// This is not a board id so we remove it to correctly
397-
// set all other boards properties
398-
delete(propertiesByBoard, "menu")
399-
400397
skippedBoards := []string{}
401398
for boardID, boardProperties := range propertiesByBoard {
402399
var board *cores.Board

Diff for: test/test_core.py

+36
Original file line numberDiff line numberDiff line change
@@ -712,3 +712,39 @@ def test_core_with_wrong_custom_board_options_is_loaded(run_command, data_dir):
712712
+ "skipping loading of boards arduino-beta-dev:platform_with_wrong_custom_board_options:nessuno: "
713713
+ "malformed custom board options"
714714
) in res.stderr
715+
716+
717+
def test_core_with_missing_custom_board_options_is_loaded(run_command, data_dir):
718+
test_platform_name = "platform_with_missing_custom_board_options"
719+
platform_install_dir = Path(data_dir, "hardware", "arduino-beta-dev", test_platform_name)
720+
platform_install_dir.mkdir(parents=True)
721+
722+
# Install platform in Sketchbook hardware dir
723+
shutil.copytree(
724+
Path(__file__).parent / "testdata" / test_platform_name, platform_install_dir, dirs_exist_ok=True,
725+
)
726+
727+
assert run_command("update")
728+
729+
res = run_command("core list --format json")
730+
assert res.ok
731+
732+
cores = json.loads(res.stdout)
733+
mapped = {core["id"]: core for core in cores}
734+
assert len(mapped) == 1
735+
# Verifies platform is loaded except excluding board with missing options
736+
assert "arduino-beta-dev:platform_with_missing_custom_board_options" in mapped
737+
boards = {b["fqbn"]: b for b in mapped["arduino-beta-dev:platform_with_missing_custom_board_options"]["boards"]}
738+
assert len(boards) == 1
739+
# Verify board with malformed options is not loaded
740+
assert "arduino-beta-dev:platform_with_missing_custom_board_options:nessuno" not in boards
741+
# Verify other board is loaded
742+
assert "arduino-beta-dev:platform_with_missing_custom_board_options:altra" in boards
743+
# Verify warning is shown to user
744+
assert (
745+
"Error initializing instance: "
746+
+ "loading platform release arduino-beta-dev:[email protected]: "
747+
+ "loading boards: "
748+
+ "skipping loading of boards arduino-beta-dev:platform_with_missing_custom_board_options:nessuno: "
749+
+ "malformed custom board options"
750+
) in res.stderr
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
nessuno.name=Arduino Nessuno
2+
nessuno.vid.0=0x2341
3+
nessuno.pid.0=0x0043
4+
nessuno.vid.1=0x2341
5+
nessuno.pid.1=0x0001
6+
nessuno.vid.2=0x2A03
7+
nessuno.pid.2=0x0043
8+
nessuno.vid.3=0x2341
9+
nessuno.pid.3=0x0243
10+
nessuno.upload.tool=avrdude
11+
nessuno.upload.protocol=arduino
12+
nessuno.upload.maximum_size=32256
13+
nessuno.upload.maximum_data_size=2048
14+
nessuno.upload.speed=115200
15+
nessuno.bootloader.tool=avrdude
16+
nessuno.bootloader.low_fuses=0xFF
17+
nessuno.bootloader.high_fuses=0xDE
18+
nessuno.bootloader.extended_fuses=0xFD
19+
nessuno.bootloader.unlock_bits=0x3F
20+
nessuno.bootloader.lock_bits=0x0F
21+
nessuno.bootloader.file=optiboot/optiboot_atmega328.hex
22+
nessuno.build.mcu=atmega328p
23+
nessuno.build.f_cpu=16000000L
24+
nessuno.build.board=AVR_NESSUNO
25+
nessuno.build.core=arduino
26+
nessuno.build.variant=standard
27+
28+
nessuno.menu.cache.on=Enabled
29+
nessuno.menu.cache.on.build.cache_flags=-DENABLE_CACHE
30+
nessuno.menu.cache.off=Disabled
31+
nessuno.menu.cache.off.build.cache_flags=
32+
33+
altra.name=Arduino Altra
34+
altra.vid.0=0x2341
35+
altra.pid.0=0x0043
36+
altra.vid.1=0x2341
37+
altra.pid.1=0x0001
38+
altra.vid.2=0x2A03
39+
altra.pid.2=0x0043
40+
altra.vid.3=0x2341
41+
altra.pid.3=0x0243
42+
altra.upload.tool=avrdude
43+
altra.upload.protocol=arduino
44+
altra.upload.maximum_size=32256
45+
altra.upload.maximum_data_size=2048
46+
altra.upload.speed=115200
47+
altra.bootloader.tool=avrdude
48+
altra.bootloader.low_fuses=0xFF
49+
altra.bootloader.high_fuses=0xDE
50+
altra.bootloader.extended_fuses=0xFD
51+
altra.bootloader.unlock_bits=0x3F
52+
altra.bootloader.lock_bits=0x0F
53+
altra.bootloader.file=optiboot/optiboot_atmega328.hex
54+
altra.build.mcu=atmega328p
55+
altra.build.f_cpu=16000000L
56+
altra.build.board=AVR_ALTRA
57+
altra.build.core=arduino
58+
altra.build.variant=standard
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name=Arduino Test Boards
2+
version=4.2.0

0 commit comments

Comments
 (0)