summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-10-26 22:23:27 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2018-10-26 23:34:18 +0200
commit699fd81bf3a67606396035697357c5665dcd68af (patch)
tree4ce312054fc229ad6809e7266218085729cb02c5
parent94ef638d61476bda162c16462238687733a77d78 (diff)
Support enabling the assignment-to-undef. symbol warning via the environment
This makes it possible to enable it for the bundled tools, by setting KCONFIG_WARN_UNDEF_ASSIGN=y. Previously, the code had to be modified to call Kconfig.enable_undef_warnings(). Also rename KCONFIG_STRICT to KCONFIG_WARN_UNDEF, for consistency. Keep supporting KCONFIG_STRICT as an alias for backwards compatibility.
-rw-r--r--README.rst30
-rw-r--r--kconfiglib.py61
-rw-r--r--tests/Kundef (renamed from tests/Kstrict)0
-rw-r--r--testsuite.py20
4 files changed, 66 insertions, 45 deletions
diff --git a/README.rst b/README.rst
index ea453d6..4ba2748 100644
--- a/README.rst
+++ b/README.rst
@@ -325,14 +325,28 @@ The following Kconfig extensions are available:
caveat that they must have the same name as the environment variables they
reference. A warning is printed if the names differ.
-- Setting the environment variable ``KCONFIG_STRICT`` to "y" will cause warnings to be printed
- for all references to undefined Kconfig symbols within Kconfig files. The only gotcha is
- that all ``hex`` literals must be prefixed by "0x" or "0X", to make it possible to distuinguish
- them from symbol references.
-
- Some projects (e.g. the Linux kernel) use multiple Kconfig trees with many shared ``Kconfig``
- files, leading to some safe undefined symbol references. ``KCONFIG_STRICT`` is useful in
- projects that only have a single ``Kconfig`` tree though.
+- Two extra optional warnings can be enabled by setting environment variables,
+ covering cases that are easily missed when making changes to Kconfig files:
+
+ * ``KCONFIG_WARN_UNDEF``: If set to ``y``, warnings will be generated for all
+ references to undefined symbols within Kconfig files. The only gotcha is
+ that all hex literals must be prefixed with ``0x`` or ``0X``, to make it
+ possible to distinguish them from symbol references.
+
+ Some projects (e.g. the Linux kernel) use multiple Kconfig trees with many
+ shared Kconfig files, leading to some safe undefined symbol references.
+ ``KCONFIG_WARN_UNDEF`` is useful in projects that only have a single
+ Kconfig tree though.
+
+ ``KCONFIG_STRICT`` is an older alias for this environment variable,
+ supported for backwards compatibility.
+
+ * ``KCONFIG_WARN_UNDEF_ASSIGN``: If set to ``y``, warnings will be generated
+ for all assignments to undefined symbols within ``.config`` files. By
+ default, no such warnings are generated.
+
+ This warning can also be enabled/disabled via
+ ``Kconfig.enable/disable_undef_warnings()``.
Other features
--------------
diff --git a/kconfiglib.py b/kconfiglib.py
index e197de4..63822f1 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -415,18 +415,30 @@ def_tristate, allowing int, hex, and string symbols to be given a type and a
default at the same time.
-Warnings for undefined symbols
-------------------------------
+Extra optional warnings
+-----------------------
-Setting the environment variable KCONFIG_STRICT to "y" will cause warnings to
-be printed for all references to undefined Kconfig symbols within Kconfig
-files. The only gotcha is that all hex literals must be prefixed by "0x" or
-"0X", to make it possible to distuinguish them from symbol references.
+Some optional warnings can be controlled via environment variables:
-Some projects (e.g. the Linux kernel) use multiple Kconfig trees with many
-shared Kconfig files, leading to some safe undefined symbol references.
-KCONFIG_STRICT is useful in projects that only have a single Kconfig tree
-though.
+ - KCONFIG_WARN_UNDEF: If set to 'y', warnings will be generated for all
+ references to undefined symbols within Kconfig files. The only gotcha is
+ that all hex literals must be prefixed with "0x" or "0X", to make it
+ possible to distinguish them from symbol references.
+
+ Some projects (e.g. the Linux kernel) use multiple Kconfig trees with many
+ shared Kconfig files, leading to some safe undefined symbol references.
+ KCONFIG_WARN_UNDEF is useful in projects that only have a single Kconfig
+ tree though.
+
+ KCONFIG_STRICT is an older alias for this environment variable, supported
+ for backwards compatibility.
+
+ - KCONFIG_WARN_UNDEF_ASSIGN: If set to 'y', warnings will be generated for
+ all assignments to undefined symbols within .config files. By default, no
+ such warnings are generated.
+
+ This warning can also be enabled/disabled via
+ Kconfig.enable/disable_undef_warnings().
Preprocessor user functions defined in Python
@@ -770,19 +782,9 @@ class Kconfig(object):
KconfigError on syntax errors. Note that Kconfig files are not the same
as .config files (which store configuration symbol values).
- If the environment variable KCONFIG_STRICT is set to "y", warnings will
- be generated for all references to undefined symbols within Kconfig
- files. The reason this isn't the default is that some projects (e.g.
- the Linux kernel) use multiple Kconfig trees (one per architecture)
- with many shared Kconfig files, leading to some safe references to
- undefined symbols.
-
- KCONFIG_STRICT relies on literal hex values being prefixed with 0x/0X.
- They are indistinguishable from references to undefined symbols
- otherwise.
-
- KCONFIG_STRICT might enable other warnings that depend on there being
- just a single Kconfig tree in the future.
+ See the module docstring for some environment variables that influence
+ default warning settings (KCONFIG_WARN_UNDEF and
+ KCONFIG_WARN_UNDEF_ASSIGN).
filename (default: "Kconfig"):
The Kconfig file to load. For the Linux kernel, you'll want "Kconfig"
@@ -844,7 +846,8 @@ class Kconfig(object):
self._warnings_enabled = warn
self._warn_to_stderr = warn_to_stderr
- self._warn_for_undef_assign = False
+ self._warn_for_undef_assign = \
+ os.environ.get("KCONFIG_WARN_UNDEF_ASSIGN") == "y"
self._warn_for_redun_assign = True
@@ -978,7 +981,11 @@ class Kconfig(object):
self._check_sym_sanity()
self._check_choice_sanity()
- if os.environ.get("KCONFIG_STRICT") == "y":
+ # KCONFIG_STRICT is an older alias for KCONFIG_WARN_UNDEF, supported
+ # for backwards compatibility
+ if os.environ.get("KCONFIG_WARN_UNDEF") == "y" or \
+ os.environ.get("KCONFIG_STRICT") == "y":
+
self._check_undef_syms()
@@ -1621,8 +1628,8 @@ class Kconfig(object):
def enable_undef_warnings(self):
"""
Enables warnings for assignments to undefined symbols. Disabled by
- default since they tend to be spammy for Kernel configurations (and
- mostly suggests cleanups).
+ default unless the KCONFIG_WARN_UNDEF_ASSIGN environment variable was
+ set to 'y' when the Kconfig instance was created.
"""
self._warn_for_undef_assign = True
diff --git a/tests/Kstrict b/tests/Kundef
index fae521a..fae521a 100644
--- a/tests/Kstrict
+++ b/tests/Kundef
diff --git a/testsuite.py b/testsuite.py
index 644c151..cca5dad 100644
--- a/testsuite.py
+++ b/testsuite.py
@@ -2518,16 +2518,16 @@ config PRINT_ME_TOO
sys.path.pop(0)
- print("Testing KCONFIG_STRICT")
+ print("Testing KCONFIG_WARN_UNDEF")
- os.environ["KCONFIG_STRICT"] = "y"
- c = Kconfig("Kconfiglib/tests/Kstrict", warn_to_stderr=False)
+ os.environ["KCONFIG_WARN_UNDEF"] = "y"
+ c = Kconfig("Kconfiglib/tests/Kundef", warn_to_stderr=False)
verify_equal("\n".join(c.warnings), """
-warning: the int symbol INT (defined at Kconfiglib/tests/Kstrict:8) has a non-int range [UNDEF_2 (undefined), 8 (undefined)]
+warning: the int symbol INT (defined at Kconfiglib/tests/Kundef:8) has a non-int range [UNDEF_2 (undefined), 8 (undefined)]
warning: undefined symbol UNDEF_1:
-- Referenced at Kconfiglib/tests/Kstrict:4:
+- Referenced at Kconfiglib/tests/Kundef:4:
config BOOL
bool
@@ -2535,7 +2535,7 @@ config BOOL
default UNDEF_2
-- Referenced at Kconfiglib/tests/Kstrict:19:
+- Referenced at Kconfiglib/tests/Kundef:19:
menu "menu"
depends on UNDEF_1
@@ -2543,7 +2543,7 @@ menu "menu"
warning: undefined symbol UNDEF_2:
-- Referenced at Kconfiglib/tests/Kstrict:4:
+- Referenced at Kconfiglib/tests/Kundef:4:
config BOOL
bool
@@ -2551,7 +2551,7 @@ config BOOL
default UNDEF_2
-- Referenced at Kconfiglib/tests/Kstrict:8:
+- Referenced at Kconfiglib/tests/Kundef:8:
config INT
int
@@ -2561,14 +2561,14 @@ config INT
warning: undefined symbol UNDEF_3:
-- Referenced at Kconfiglib/tests/Kstrict:19:
+- Referenced at Kconfiglib/tests/Kundef:19:
menu "menu"
depends on UNDEF_1
visible if UNDEF_3
"""[1:])
- os.environ.pop("KCONFIG_STRICT")
+ os.environ.pop("KCONFIG_WARN_UNDEF")
print("\nAll selftests passed\n" if all_passed else