@@ -24,12 +24,14 @@ import (
24
24
25
25
// Board represents a board loaded from an installed platform
26
26
type 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
33
35
}
34
36
35
37
// HasUsbID returns true if the board match the usb vid and pid parameters
@@ -78,11 +80,16 @@ func (b *Board) buildConfigOptionsStructures() {
78
80
}
79
81
80
82
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 )
86
93
}
87
94
}
88
95
}
@@ -106,38 +113,29 @@ func (b *Board) GetConfigOptionValues(option string) *properties.Map {
106
113
// GetBuildProperties returns the build properties and the build
107
114
// platform for the Board with the configuration passed as parameter.
108
115
func (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 )
111
121
112
122
// Start with board's base properties
113
123
buildProperties := b .Properties .Clone ()
114
124
115
125
// 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
126
// Check for residual invalid options...
135
- if invalidKeys := userConfigs .Keys (); len (invalidKeys ) > 0 {
136
- invalidOption := invalidKeys [0 ]
137
- if invalidOption == "" {
127
+ for option , value := range config .AsMap () {
128
+ if option == "" {
138
129
return nil , fmt .Errorf (tr ("invalid empty option found" ))
139
130
}
140
- return nil , fmt .Errorf (tr ("invalid option '%s'" ), invalidOption )
131
+ if _ , ok := b .configOptions .GetOk (option ); ! ok {
132
+ return nil , fmt .Errorf (tr ("invalid option '%s'" ), option )
133
+ }
134
+ optionsConf , ok := b .configOptionProperties [option + "=" + value ]
135
+ if ! ok {
136
+ return nil , fmt .Errorf (tr ("invalid value '%[1]s' for option '%[2]s'" ), value , option )
137
+ }
138
+ buildProperties .Merge (optionsConf )
141
139
}
142
140
143
141
return buildProperties , nil
0 commit comments