Skip to content

Commit

Permalink
Do not treat custom menu options without label as 'malformed' (#1882)
Browse files Browse the repository at this point in the history
* Do not treat custom menu items without label as 'malformed'

* Fixed tests
  • Loading branch information
cmaglie authored Sep 21, 2022
1 parent b9599e1 commit 5730e2e
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 135 deletions.
22 changes: 0 additions & 22 deletions arduino/cores/packagemanager/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,25 +481,8 @@ func (pm *Builder) loadBoards(platform *cores.PlatformRelease) error {
// set all other boards properties
delete(propertiesByBoard, "menu")

skippedBoards := []string{}
for boardID, boardProperties := range propertiesByBoard {
var board *cores.Board
for key := range boardProperties.AsMap() {
if !strings.HasPrefix(key, "menu.") {
continue
}
// Menu keys are formed like this:
// menu.cache.off=false
// menu.cache.on=true
// so we assume that the a second element in the slice exists
menuName := strings.Split(key, ".")[1]
if !platform.Menus.ContainsKey(menuName) {
fqbn := fmt.Sprintf("%s:%s:%s", platform.Platform.Package.Name, platform.Platform.Architecture, boardID)
skippedBoards = append(skippedBoards, fqbn)
goto next_board
}
}

if !platform.PluggableDiscoveryAware {
convertVidPidIdentificationPropertiesToPluggableDiscovery(boardProperties)
convertUploadToolsToPluggableDiscovery(boardProperties)
Expand All @@ -514,11 +497,6 @@ func (pm *Builder) loadBoards(platform *cores.PlatformRelease) error {
boardProperties.Set("_id", boardID)
board = platform.GetOrCreateBoard(boardID)
board.Properties.Merge(boardProperties)
next_board:
}

if len(skippedBoards) > 0 {
return fmt.Errorf(tr("skipping loading of boards %s: malformed custom board options"), strings.Join(skippedBoards, ", "))
}

return nil
Expand Down
50 changes: 2 additions & 48 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,44 +654,6 @@ def test_core_download_multiple_platforms(run_command, data_dir):
assert "Invalid argument passed: Found 2 platform for reference" in res.stderr


def test_core_with_wrong_custom_board_options_is_loaded(run_command, data_dir):
test_platform_name = "platform_with_wrong_custom_board_options"
platform_install_dir = Path(data_dir, "hardware", "arduino-beta-dev", test_platform_name)
platform_install_dir.mkdir(parents=True)

# Install platform in Sketchbook hardware dir
shutil.copytree(
Path(__file__).parent / "testdata" / test_platform_name,
platform_install_dir,
dirs_exist_ok=True,
)

assert run_command(["update"])

res = run_command(["core", "list", "--format", "json"])
assert res.ok

cores = json.loads(res.stdout)
mapped = {core["id"]: core for core in cores}
assert len(mapped) == 1
# Verifies platform is loaded except excluding board with wrong options
assert "arduino-beta-dev:platform_with_wrong_custom_board_options" in mapped
boards = {b["fqbn"]: b for b in mapped["arduino-beta-dev:platform_with_wrong_custom_board_options"]["boards"]}
assert len(boards) == 1
# Verify board with malformed options is not loaded
assert "arduino-beta-dev:platform_with_wrong_custom_board_options:nessuno" not in boards
# Verify other board is loaded
assert "arduino-beta-dev:platform_with_wrong_custom_board_options:altra" in boards
# Verify warning is shown to user
assert (
"Error initializing instance: Error loading hardware platform: "
+ "loading platform release arduino-beta-dev:platform_with_wrong_custom_board_options@4.2.0: "
+ "loading boards: "
+ "skipping loading of boards arduino-beta-dev:platform_with_wrong_custom_board_options:nessuno: "
+ "malformed custom board options"
) in res.stderr


def test_core_with_missing_custom_board_options_is_loaded(run_command, data_dir):
test_platform_name = "platform_with_missing_custom_board_options"
platform_install_dir = Path(data_dir, "hardware", "arduino-beta-dev", test_platform_name)
Expand All @@ -715,19 +677,11 @@ def test_core_with_missing_custom_board_options_is_loaded(run_command, data_dir)
# Verifies platform is loaded except excluding board with missing options
assert "arduino-beta-dev:platform_with_missing_custom_board_options" in mapped
boards = {b["fqbn"]: b for b in mapped["arduino-beta-dev:platform_with_missing_custom_board_options"]["boards"]}
assert len(boards) == 1
assert len(boards) == 2
# Verify board with malformed options is not loaded
assert "arduino-beta-dev:platform_with_missing_custom_board_options:nessuno" not in boards
assert "arduino-beta-dev:platform_with_missing_custom_board_options:nessuno" in boards
# Verify other board is loaded
assert "arduino-beta-dev:platform_with_missing_custom_board_options:altra" in boards
# Verify warning is shown to user
assert (
"Error initializing instance: Error loading hardware platform: "
+ "loading platform release arduino-beta-dev:platform_with_missing_custom_board_options@4.2.0: "
+ "loading boards: "
+ "skipping loading of boards arduino-beta-dev:platform_with_missing_custom_board_options:nessuno: "
+ "malformed custom board options"
) in res.stderr


def test_core_list_outdated_core(run_command):
Expand Down
63 changes: 0 additions & 63 deletions test/testdata/platform_with_wrong_custom_board_options/boards.txt

This file was deleted.

This file was deleted.

0 comments on commit 5730e2e

Please sign in to comment.