summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kconfiglib.py60
1 files changed, 28 insertions, 32 deletions
diff --git a/kconfiglib.py b/kconfiglib.py
index 430d182..7752f21 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -1213,7 +1213,7 @@ class Kconfig(object):
# Small optimizations
set_match = self._set_match
unset_match = self._unset_match
- syms = self.syms
+ get_sym = self.syms.get
for linenr, line in enumerate(f, 1):
# The C tools ignore trailing whitespace
@@ -1222,22 +1222,18 @@ class Kconfig(object):
match = set_match(line)
if match:
name, val = match.groups()
- if name not in syms:
- self._undef_assign(name, val, filename, linenr)
- continue
-
- sym = syms[name]
- if not sym.nodes:
+ sym = get_sym(name)
+ if not sym or not sym.nodes:
self._undef_assign(name, val, filename, linenr)
continue
if sym.orig_type in _BOOL_TRISTATE:
# The C implementation only checks the first character
# to the right of '=', for whatever reason
- if not ((sym.orig_type is BOOL and
- val.startswith(("y", "n"))) or
- (sym.orig_type is TRISTATE and
- val.startswith(("y", "m", "n")))):
+ if not (sym.orig_type is BOOL
+ and val.startswith(("y", "n")) or
+ sym.orig_type is TRISTATE
+ and val.startswith(("y", "m", "n"))):
self._warn("'{}' is not a valid value for the {} "
"symbol {}. Assignment ignored."
.format(val, TYPE_TO_STR[sym.orig_type],
@@ -1289,12 +1285,8 @@ class Kconfig(object):
continue
name = match.group(1)
- if name not in syms:
- self._undef_assign(name, "n", filename, linenr)
- continue
-
- sym = syms[name]
- if not sym.nodes:
+ sym = get_sym(name)
+ if not sym or not sym.nodes:
self._undef_assign(name, "n", filename, linenr)
continue
@@ -1306,21 +1298,7 @@ class Kconfig(object):
# Done parsing the assignment. Set the value.
if sym._was_set:
- # Use strings for bool/tristate user values in the warning
- if sym.orig_type in _BOOL_TRISTATE:
- display_user_val = TRI_TO_STR[sym.user_value]
- else:
- display_user_val = sym.user_value
-
- msg = '{} set more than once. Old value "{}", new value "{}".'.format(
- _name_and_loc(sym), display_user_val, val
- )
-
- if display_user_val == val:
- if self.warn_assign_redun:
- self._warn(msg, filename, linenr)
- elif self.warn_assign_override:
- self._warn(msg, filename, linenr)
+ self._assigned_twice(sym, val, filename, linenr)
sym.set_value(val)
@@ -1345,6 +1323,24 @@ class Kconfig(object):
"attempt to assign the value '{}' to the undefined symbol {}"
.format(val, name), filename, linenr)
+ def _assigned_twice(self, sym, new_val, filename, linenr):
+ # Called when a symbol is assigned more than once in a .config file
+
+ # Use strings for bool/tristate user values in the warning
+ if sym.orig_type in _BOOL_TRISTATE:
+ user_val = TRI_TO_STR[sym.user_value]
+ else:
+ user_val = sym.user_value
+
+ msg = '{} set more than once. Old value "{}", new value "{}".'.format(
+ _name_and_loc(sym), user_val, new_val)
+
+ if user_val == new_val:
+ if self.warn_assign_redun:
+ self._warn(msg, filename, linenr)
+ elif self.warn_assign_override:
+ self._warn(msg, filename, linenr)
+
def write_autoconf(self, filename,
header="/* Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib) */\n"):
r"""