diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2018-01-05 20:37:00 +0100 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2018-01-05 21:38:57 +0100 |
| commit | 5d693b2e66451aedfd694ffde4dba7d4b74afa46 (patch) | |
| tree | c35c01fe21902cf6c7814707ef9f200c5f0c5818 | |
| parent | 5e2103cf37181067cbdff1a16647edddf60441f0 (diff) | |
Don't write out 'option env' symbols to C header
Oversight. SYMBOL_AUTO (env_var) being set indirectly clears
SYMBOL_WRITE (_write_to_conf) in sym_calc_value(). The .config case was
already fine due to an explicit env_var check.
Even non-visible env. symbols ended up in the header, due to
'option env' internally adding a default.
Disallow user values altogether on 'option env' symbols, even if
specified manually. This matches the C implementation. Add a warning
too.
| -rw-r--r-- | kconfiglib.py | 14 | ||||
| -rw-r--r-- | tests/Kmisc | 10 | ||||
| -rw-r--r-- | testsuite.py | 18 |
3 files changed, 36 insertions, 6 deletions
diff --git a/kconfiglib.py b/kconfiglib.py index f31a71c..05cc172 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -2474,6 +2474,10 @@ class Symbol(object): val = val_expr.str_value break + # Corresponds to SYMBOL_AUTO in the C implementation + if self.env_var is not None: + self._write_to_conf = False + self._cached_str_val = val return val @@ -2572,10 +2576,6 @@ class Symbol(object): """ See the class documentation. """ - if self.env_var is not None: - # Corresponds to SYMBOL_AUTO being set in the C implementation - return None - # Note: _write_to_conf is determined when the value is calculated. This # is a hidden function call due to property magic. val = self.str_value @@ -2666,6 +2666,12 @@ class Symbol(object): return False + if self.env_var is not None: + self.kconfig._warn("ignored attempt to assign user value to " + "{}, which gets its value from the environment" + .format(self.name)) + return False + if self.choice and value == 2: # Remember this as a choice selection only. Makes switching back # and forth between choice modes work as expected, and makes the diff --git a/tests/Kmisc b/tests/Kmisc index 44fdfdc..9da57a4 100644 --- a/tests/Kmisc +++ b/tests/Kmisc @@ -61,12 +61,18 @@ menu "menu" endmenu config FROM_ENV - string + string "from env" option env="ENV_VAR" config FROM_ENV_MISSING - string + string "from env missing" option env="MISSING_ENV_VAR" + default "missing" + +config FROM_ENV_WEIRD + string + default "weird" + option env="ENV_VAR" config NOT_ALLNOCONFIG_Y bool "not allnoconfig_y" diff --git a/testsuite.py b/testsuite.py index e7168a6..932ee6a 100644 --- a/testsuite.py +++ b/testsuite.py @@ -1233,6 +1233,24 @@ g format(s.name)) + print("Testing 'option env' semantics") + + os.environ["ENV_VAR"] = "ENV_VAR value" + + # References undefined env. var. and tries to assign 'option env' variable, + # so disable warnings + c = Kconfig("Kconfiglib/tests/Kmisc", warn=False) + + # Verify that 'option env' symbols can't be assigned user values, and that + # 'option env' is treated like a default + assign_and_verify_user_value("FROM_ENV", "foo", None, False) + assign_and_verify_user_value("FROM_ENV_MISSING", "foo", None, False) + verify_value("FROM_ENV", "ENV_VAR value") + verify_value("FROM_ENV_MISSING", "missing") + + verify_value("FROM_ENV_WEIRD", "weird") + + print("Testing defined vs undefined symbols") for name in "A", "B", "C", "D", "BOOL", "TRISTATE", "STRING", "INT", "HEX": |
