Skip to content

Respect the order of menu, when computing the config options #2159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions arduino/cores/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,17 @@ func (b *Board) buildConfigOptionsStructures() {

b.configOptions = properties.NewMap()
allConfigs := b.Properties.SubTree("menu")
for _, option := range allConfigs.FirstLevelKeys() {
b.configOptions.Set(option, b.PlatformRelease.Menus.Get(option))

// Used to show the config options in the same order as the menu, defined at the begging of platform.txt
if b.PlatformRelease.Menus != nil {
for _, menuOption := range b.PlatformRelease.Menus.FirstLevelKeys() {
for _, option := range allConfigs.FirstLevelKeys() {
if menuOption == option {
b.configOptions.Set(option, b.PlatformRelease.Menus.Get(menuOption))
break
}
}
}
}

b.configOptionValues = map[string]*properties.Map{}
Expand Down
36 changes: 36 additions & 0 deletions arduino/cores/board_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package cores

import (
"fmt"
"testing"

properties "github.com/arduino/go-properties-orderedmap"
Expand Down Expand Up @@ -370,6 +371,41 @@ func TestBoardOptions(t *testing.T) {
// fmt.Print(string(data))
}

func TestBoarConfigOptionSortingSameAsMenu(t *testing.T) {
menus := properties.NewMap()
menus.Set("BoardModel", "Model")
menus.Set("xtal", "CPU Frequency")
menus.Set("vt", "VTables")
menus.Set("wipe", "Erase Flash")

props := properties.NewMap()
props.Set("menu.xtal.80", "80 MHz")
props.Set("menu.wipe.none", "Only Sketch")
props.Set("menu.BoardModel.primo", "Primo")
props.Set("menu.BoardModel.primo.build.board", "ESP8266_ARDUINO_PRIMO")
props.Set("menu.vt.flash", "Flash")

esp8266 := &Board{
BoardID: "arduino-esp8266",
Properties: props,
PlatformRelease: &PlatformRelease{
Platform: &Platform{
Architecture: "esp8266",
Package: &Package{
Name: "esp8266",
},
},
Menus: menus,
},
}

config := `xtal=80,wipe=none,BoardModel=primo,vt=flash`

_, err := esp8266.GeneratePropertiesForConfiguration(config)
require.NoError(t, err, fmt.Sprintf("generating %s configuration", config))
require.True(t, esp8266.configOptions.EqualsWithOrder(menus))
}

func TestOSSpecificBoardOptions(t *testing.T) {
boardWihOSSpecificOptionProperties := properties.NewMap()
boardWihOSSpecificOptionProperties.Set("menu.UploadSpeed.115200", "115200")
Expand Down