diff --git a/arduino/cores/board.go b/arduino/cores/board.go index 13c84badf41..8a41a8fb198 100644 --- a/arduino/cores/board.go +++ b/arduino/cores/board.go @@ -79,14 +79,21 @@ 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)) + allConfigOptions := allConfigs.FirstLevelOf() + + // Used to show the config options in the same order as the menu, defined at the begging of boards.txt + if b.PlatformRelease.Menus != nil { + for _, menuOption := range b.PlatformRelease.Menus.FirstLevelKeys() { + if _, ok := allConfigOptions[menuOption]; ok { + b.configOptions.Set(menuOption, b.PlatformRelease.Menus.Get(menuOption)) + } + } } b.configOptionValues = map[string]*properties.Map{} b.configOptionProperties = map[string]*properties.Map{} b.defaultConfig = properties.NewMap() - for option, optionProps := range allConfigs.FirstLevelOf() { + for option, optionProps := range allConfigOptions { b.configOptionValues[option] = properties.NewMap() values := optionProps.FirstLevelKeys() b.defaultConfig.Set(option, values[0]) diff --git a/arduino/cores/board_test.go b/arduino/cores/board_test.go index 1dade30a3bd..577a9af09de 100644 --- a/arduino/cores/board_test.go +++ b/arduino/cores/board_test.go @@ -16,6 +16,7 @@ package cores import ( + "fmt" "testing" properties "github.com/arduino/go-properties-orderedmap" @@ -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")