You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2022/03/14 18:02:21 UTC

[mynewt-newt] branch master updated: Add const syscfg values

This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-newt.git


The following commit(s) were added to refs/heads/master by this push:
     new d611573  Add const syscfg values
d611573 is described below

commit d611573239d257113d8954eda8a2cf83218fe01a
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Mon Mar 7 13:21:55 2022 +0100

    Add const syscfg values
    
    This allows to define syscfg value that shall be const. A const syscfg
    definition is simply a syscfg.vals setting placed in syscfg.defs
    section.
    
    An example of candicates for such vals are e.g. BLE_CONTROLLER, BLE_HOST
    or BSP_* values that are defined to be used as conditionals in other
    configuration files or in code. This change removes burden of adding a
    full definition and possibly also restricions for syscfg we do not want
    to be ever changed.
---
 newt/syscfg/syscfg.go | 66 ++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 55 insertions(+), 11 deletions(-)

diff --git a/newt/syscfg/syscfg.go b/newt/syscfg/syscfg.go
index f74527c..d73adcd 100644
--- a/newt/syscfg/syscfg.go
+++ b/newt/syscfg/syscfg.go
@@ -60,6 +60,7 @@ type CfgSettingState int
 
 const (
 	CFG_SETTING_STATE_GOOD CfgSettingState = iota
+	CFG_SETTING_STATE_CONST
 	CFG_SETTING_STATE_DEPRECATED
 	CFG_SETTING_STATE_DEFUNCT
 )
@@ -149,6 +150,9 @@ type Cfg struct {
 	// Use of defunct settings (error).
 	Defunct map[string]struct{}
 
+	// Use of const settings (error).
+	Consts map[string]struct{}
+
 	// Unresolved value references
 	UnresolvedValueRefs map[string]struct{}
 }
@@ -166,6 +170,7 @@ func NewCfg() Cfg {
 		Redefines:           map[string]map[*pkg.LocalPackage]struct{}{},
 		Deprecated:          map[string]struct{}{},
 		Defunct:             map[string]struct{}{},
+		Consts:              map[string]struct{}{},
 		UnresolvedValueRefs: map[string]struct{}{},
 	}
 }
@@ -570,21 +575,48 @@ func (cfg *Cfg) readDefsOnce(lpkg *pkg.LocalPackage,
 
 	if defs != nil {
 		for k, v := range defs {
-			vals, ok := v.(map[interface{}]interface{})
-			if !ok {
+			var entry CfgEntry
+			var err error
+
+			switch v.(type) {
+			case map[interface{}]interface{}:
+				vals := v.(map[interface{}]interface{})
+				entry, err = readSetting(k, lpkg, vals)
+				if err != nil {
+					return util.FmtNewtError("Config for package %s: %s",
+						lpkg.FullName(), err.Error())
+				}
+			case int:
+				val := v.(int)
+				entry = CfgEntry{
+					Name:       k,
+					PackageDef: lpkg,
+					State:      CFG_SETTING_STATE_CONST,
+					Value:      stringValue(val),
+					History: []CfgPoint{{
+						Value:  stringValue(val),
+						Source: lpkg,
+					}},
+				}
+			case string:
+				val := v.(string)
+				entry = CfgEntry{
+					Name:       k,
+					PackageDef: lpkg,
+					State:      CFG_SETTING_STATE_CONST,
+					Value:      val,
+					History: []CfgPoint{{
+						Value:  val,
+						Source: lpkg,
+					}},
+				}
+			default:
 				return util.FmtNewtError("Package \"%s\" contains invalid "+
-					"\"syscfg.defs\" map; expected full setting definition, "+
-					"but setting \"%s\" specifies a single value.  "+
-					"Did you mix up \"syscfg.defs\" and \"syscfg.vals\"?",
+					"\"syscfg.defs\" for \"%s\". It should be either full definition "+
+					"(configurable setting) or single value (const setting)",
 					lpkg.FullName(), k)
 			}
 
-			entry, err := readSetting(k, lpkg, vals)
-			if err != nil {
-				return util.FmtNewtError("Config for package %s: %s",
-					lpkg.FullName(), err.Error())
-			}
-
 			replace := true
 			if oldEntry, exists := cfg.Settings[k]; exists {
 				// Setting already defined.  This is allowed for injected
@@ -678,6 +710,8 @@ func (cfg *Cfg) readValsOnce(lpkg *pkg.LocalPackage,
 			cfg.Deprecated[k] = struct{}{}
 		case CFG_SETTING_STATE_DEFUNCT:
 			cfg.Defunct[k] = struct{}{}
+		case CFG_SETTING_STATE_CONST:
+			cfg.Consts[k] = struct{}{}
 		}
 	}
 
@@ -1012,6 +1046,16 @@ func (cfg *Cfg) ErrorText() string {
 		}
 	}
 
+	// Overrides of const settings.
+	if len(cfg.Consts) > 0 {
+		str += "Override of consts settings detected:\n"
+		for name, _ := range cfg.Consts {
+			entry := cfg.Settings[name]
+			str += "    " + fmt.Sprintf("%s\n", name)
+			historyMap[name] = entry.History
+		}
+	}
+
 	// Unresolved value references
 	if len(cfg.UnresolvedValueRefs) > 0 {
 		str += "Unresolved value references:\n"