Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ad9ddb8

Browse files
Respect the order of menu, when computing the config options (#2159)
* Respect the order of menu, when computing the config options * reduce cyclomatic complexity * fix the comment that was referring to the wrong filename
1 parent 475d987 commit ad9ddb8

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

‎arduino/cores/board.go‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,21 @@ func (b *Board) buildConfigOptionsStructures() {
7979

8080
b.configOptions = properties.NewMap()
8181
allConfigs := b.Properties.SubTree("menu")
82-
for _, option := range allConfigs.FirstLevelKeys() {
83-
b.configOptions.Set(option, b.PlatformRelease.Menus.Get(option))
82+
allConfigOptions := allConfigs.FirstLevelOf()
83+
84+
// Used to show the config options in the same order as the menu, defined at the begging of boards.txt
85+
if b.PlatformRelease.Menus != nil {
86+
for _, menuOption := range b.PlatformRelease.Menus.FirstLevelKeys() {
87+
if _, ok := allConfigOptions[menuOption]; ok {
88+
b.configOptions.Set(menuOption, b.PlatformRelease.Menus.Get(menuOption))
89+
}
90+
}
8491
}
8592

8693
b.configOptionValues = map[string]*properties.Map{}
8794
b.configOptionProperties = map[string]*properties.Map{}
8895
b.defaultConfig = properties.NewMap()
89-
for option, optionProps := range allConfigs.FirstLevelOf() {
96+
for option, optionProps := range allConfigOptions {
9097
b.configOptionValues[option] = properties.NewMap()
9198
values := optionProps.FirstLevelKeys()
9299
b.defaultConfig.Set(option, values[0])

‎arduino/cores/board_test.go‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package cores
1717

1818
import (
19+
"fmt"
1920
"testing"
2021

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

374+
func TestBoarConfigOptionSortingSameAsMenu(t *testing.T) {
375+
menus := properties.NewMap()
376+
menus.Set("BoardModel", "Model")
377+
menus.Set("xtal", "CPU Frequency")
378+
menus.Set("vt", "VTables")
379+
menus.Set("wipe", "Erase Flash")
380+
381+
props := properties.NewMap()
382+
props.Set("menu.xtal.80", "80 MHz")
383+
props.Set("menu.wipe.none", "Only Sketch")
384+
props.Set("menu.BoardModel.primo", "Primo")
385+
props.Set("menu.BoardModel.primo.build.board", "ESP8266_ARDUINO_PRIMO")
386+
props.Set("menu.vt.flash", "Flash")
387+
388+
esp8266 := &Board{
389+
BoardID: "arduino-esp8266",
390+
Properties: props,
391+
PlatformRelease: &PlatformRelease{
392+
Platform: &Platform{
393+
Architecture: "esp8266",
394+
Package: &Package{
395+
Name: "esp8266",
396+
},
397+
},
398+
Menus: menus,
399+
},
400+
}
401+
402+
config := `xtal=80,wipe=none,BoardModel=primo,vt=flash`
403+
404+
_, err := esp8266.GeneratePropertiesForConfiguration(config)
405+
require.NoError(t, err, fmt.Sprintf("generating %s configuration", config))
406+
require.True(t, esp8266.configOptions.EqualsWithOrder(menus))
407+
}
408+
373409
func TestOSSpecificBoardOptions(t *testing.T) {
374410
boardWihOSSpecificOptionProperties := properties.NewMap()
375411
boardWihOSSpecificOptionProperties.Set("menu.UploadSpeed.115200", "115200")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /