@@ -62,30 +62,40 @@ func (b *Board) String() string {
62
62
63
63
// GetBuildProperties returns the build properties and the build
64
64
// platform for the Board with the configuration passed as parameter.
65
- func (b * Board ) GetBuildProperties (configs * properties.Map ) (* properties.Map , error ) {
65
+ func (b * Board ) GetBuildProperties (userConfigs * properties.Map ) (* properties.Map , error ) {
66
+ // Clone user configs because they are destroyed during iteration
67
+ userConfigs = userConfigs .Clone ()
68
+
66
69
// Start with board's base properties
67
70
buildProperties := b .Properties .Clone ()
68
71
69
- // Add all sub-configurations one by one
72
+ // Add all sub-configurations one by one (a config is: option=value)
70
73
menu := b .Properties .SubTree ("menu" )
71
- for _ , option := range configs .Keys () {
72
- if option == "" {
73
- return nil , fmt .Errorf ("invalid empty option found" )
74
- }
75
-
74
+ for _ , option := range menu .FirstLevelKeys () {
76
75
optionMenu := menu .SubTree (option )
77
- if optionMenu .Size () == 0 {
78
- return nil , fmt .Errorf ("invalid option '%s'" , option )
79
- }
80
- optionValue := configs .Get (option )
81
- if ! optionMenu .ContainsKey (optionValue ) {
82
- return nil , fmt .Errorf ("invalid value '%s' for option '%s'" , optionValue , option )
76
+ userValue , haveUserValue := userConfigs .GetOk (option )
77
+ if haveUserValue {
78
+ userConfigs .Remove (option )
79
+ if ! optionMenu .ContainsKey (userValue ) {
80
+ return nil , fmt .Errorf ("invalid value '%s' for option '%s'" , userValue , option )
81
+ }
82
+ } else {
83
+ // apply default
84
+ userValue = optionMenu .FirstLevelKeys ()[0 ]
83
85
}
84
86
85
- optionsConf := optionMenu .SubTree (optionValue )
87
+ optionsConf := optionMenu .SubTree (userValue )
86
88
buildProperties .Merge (optionsConf )
87
89
}
88
90
91
+ // Check for residual invalid options...
92
+ for _ , invalidOption := range userConfigs .Keys () {
93
+ if invalidOption == "" {
94
+ return nil , fmt .Errorf ("invalid empty option found" )
95
+ }
96
+ return nil , fmt .Errorf ("invalid option '%s'" , invalidOption )
97
+ }
98
+
89
99
return buildProperties , nil
90
100
}
91
101
0 commit comments