@@ -24,12 +24,14 @@ import (
2424
2525// Board represents a board loaded from an installed platform
2626type Board struct {
27- BoardID string
28- Properties * properties.Map `json:"-"`
29- PlatformRelease * PlatformRelease `json:"-"`
30- configOptions * properties.Map
31- configOptionValues map [string ]* properties.Map
32- identificationProperties []* properties.Map
27+ BoardID string
28+ Properties * properties.Map `json:"-"`
29+ PlatformRelease * PlatformRelease `json:"-"`
30+ configOptions * properties.Map
31+ configOptionValues map [string ]* properties.Map
32+ configOptionProperties map [string ]* properties.Map
33+ defaultConfig * properties.Map
34+ identificationProperties []* properties.Map
3335}
3436
3537// HasUsbID returns true if the board match the usb vid and pid parameters
@@ -78,11 +80,16 @@ func (b *Board) buildConfigOptionsStructures() {
7880 }
7981
8082 b .configOptionValues = map [string ]* properties.Map {}
81- for configName , options := range allConfigs .FirstLevelOf () {
82- b .configOptionValues [configName ] = properties .NewMap ()
83- for _ , value := range options .FirstLevelKeys () {
84- if label , ok := options .GetOk (value ); ok {
85- b .configOptionValues [configName ].Set (value , label )
83+ b .configOptionProperties = map [string ]* properties.Map {}
84+ b .defaultConfig = properties .NewMap ()
85+ for option , optionProps := range allConfigs .FirstLevelOf () {
86+ b .configOptionValues [option ] = properties .NewMap ()
87+ values := optionProps .FirstLevelKeys ()
88+ b .defaultConfig .Set (option , values [0 ])
89+ for _ , value := range values {
90+ if label , ok := optionProps .GetOk (value ); ok {
91+ b .configOptionValues [option ].Set (value , label )
92+ b .configOptionProperties [option + "=" + value ] = optionProps .SubTree (value )
8693 }
8794 }
8895 }
@@ -106,37 +113,28 @@ func (b *Board) GetConfigOptionValues(option string) *properties.Map {
106113// GetBuildProperties returns the build properties and the build
107114// platform for the Board with the configuration passed as parameter.
108115func (b * Board ) GetBuildProperties (userConfigs * properties.Map ) (* properties.Map , error ) {
109- // Clone user configs because they are destroyed during iteration
110- userConfigs = userConfigs .Clone ()
116+ b .buildConfigOptionsStructures ()
117+
118+ // Override default configs with user configs
119+ config := b .defaultConfig .Clone ()
120+ config .Merge (userConfigs )
111121
112122 // Start with board's base properties
113123 buildProperties := b .Properties .Clone ()
114124
115125 // Add all sub-configurations one by one (a config is: option=value)
116- menu := b .Properties .SubTree ("menu" )
117- for _ , option := range menu .FirstLevelKeys () {
118- optionMenu := menu .SubTree (option )
119- userValue , haveUserValue := userConfigs .GetOk (option )
120- if haveUserValue {
121- userConfigs .Remove (option )
122- if ! optionMenu .ContainsKey (userValue ) {
123- return nil , fmt .Errorf (tr ("invalid value '%[1]s' for option '%[2]s'" ), userValue , option )
124- }
125- } else {
126- // apply default
127- userValue = optionMenu .FirstLevelKeys ()[0 ]
128- }
129-
130- optionsConf := optionMenu .SubTree (userValue )
131- buildProperties .Merge (optionsConf )
132- }
133-
134- // Check for residual invalid options...
135- for _ , invalidOption := range userConfigs .Keys () {
136- if invalidOption == "" {
126+ for option , value := range config .AsMap () {
127+ if option == "" {
137128 return nil , fmt .Errorf (tr ("invalid empty option found" ))
138129 }
139- return nil , fmt .Errorf (tr ("invalid option '%s'" ), invalidOption )
130+ if _ , ok := b .configOptions .GetOk (option ); ! ok {
131+ return nil , fmt .Errorf (tr ("invalid option '%s'" ), option )
132+ }
133+ optionsConf , ok := b .configOptionProperties [option + "=" + value ]
134+ if ! ok {
135+ return nil , fmt .Errorf (tr ("invalid value '%[1]s' for option '%[2]s'" ), value , option )
136+ }
137+ buildProperties .Merge (optionsConf )
140138 }
141139
142140 return buildProperties , nil
0 commit comments