From 7ba79cafa8e03af90dea0c4378e024d24a7d64b7 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Fri, 23 Mar 2018 03:37:49 +0100 Subject: Warn if user (.config) value is outside of 'range' Example warning: warning: user value 0x100 on the hex symbol HEX (defined at Kconfig:18) ignored due to being outside the active range ([0x13, 0x73]) -- falling back on defaults This is a Kconfiglib-exclusive warning. It might be tricky to implement in the C tools, due to weird two-phase handling of int/hex symbols. There is unfortunately no easy way to map the warning back to a .config line, as the active 'range' can't be known in general until the entire configuration has been read (consider 'range 0 10 if FOO' for example). Instead, the warning is generated when the symbol value is calculated. --- kconfiglib.py | 29 +++++++++++++++++++++-------- testsuite.py | 5 +++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/kconfiglib.py b/kconfiglib.py index e9d9303..e002cc0 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -2806,16 +2806,29 @@ class Symbol(object): else: has_active_range = False - if vis and self.user_value is not None and \ - (not has_active_range or - low <= int(self.user_value, base) <= high): + # Defaults are used if the symbol is invisible, lacks a user value, + # or has an out-of-range user value. + use_defaults = True - # If the user value is well-formed and satisfies range - # contraints, it is stored in exactly the same form as - # specified in the assignment (with or without "0x", etc.) - val = self.user_value + if vis and self.user_value is not None: + user_val = int(self.user_value, base) + if has_active_range and not low <= user_val <= high: + num2str = str if base == 10 else hex + self.kconfig._warn( + "user value {} on the {} symbol {} ignored due to " + "being outside the active range ([{}, {}]) -- falling " + "back on defaults" + .format(num2str(user_val), TYPE_TO_STR[self.orig_type], + _name_and_loc_str(self), + num2str(low), num2str(high))) + else: + # If the user value is well-formed and satisfies range + # contraints, it is stored in exactly the same form as + # specified in the assignment (with or without "0x", etc.) + val = self.user_value + use_defaults = False - else: + if use_defaults: # No user value or invalid user value. Look at defaults. for val_expr, cond in self.defaults: diff --git a/testsuite.py b/testsuite.py index c66f42c..110e6ec 100644 --- a/testsuite.py +++ b/testsuite.py @@ -1131,6 +1131,9 @@ g # User values and dependent ranges + # Avoid warnings for assigning values outside the active range + c.disable_warnings() + def verify_range(sym_name, low, high, default): """ Tests that the values in the range 'low'-'high' can be assigned, and @@ -1200,6 +1203,8 @@ g verify_value("INACTIVE_RANGE", "2") verify_value("ACTIVE_RANGE", "1") + c.enable_warnings() + print("Testing defconfig_filename") -- cgit v1.2.3