[PATCH 02/11] scripts: kconfig-lint.py: extend for undefined symbol detection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Extend the script by some code from the official list_undefined.py example[1]
to further detect symbols we are using, but haven't defined anywhere.

[1]: https://github.com/ulfalizer/Kconfiglib/blob/35a60b7/examples/list_undefined.py

Signed-off-by: Ahmad Fatoum <ahmad@xxxxxx>
---
 scripts/kconfig-lint.py | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/scripts/kconfig-lint.py b/scripts/kconfig-lint.py
index 308c82dfd8de..a154e9cccacc 100755
--- a/scripts/kconfig-lint.py
+++ b/scripts/kconfig-lint.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 
 # Copyright (c) 2019 Nordic Semiconductor ASA
-# SPDX-License-Identifier: Apache-2.0
+# SPDX-License-Identifier: Apache-2.0 AND ISC
 
 """
 Linter for the Zephyr Kconfig files. Pass --help to see
@@ -35,6 +35,7 @@ def main():
         # Run all checks if no checks were specified
         checks = (check_always_n,
                   check_unused,
+                  check_undefined,
                   check_pointless_menuconfigs,
                   check_missing_config_prefix)
 
@@ -78,6 +79,13 @@ Heuristic:
 
 C preprocessor magic can trip up this check.""")
 
+    parser.add_argument(
+        "-U", "--check-undefined",
+        action="append_const", dest="checks", const=check_undefined,
+        help="""\
+List symbols that are used in a Kconfig file but are undefined
+""")
+
     parser.add_argument(
         "-m", "--check-pointless-menuconfigs",
         action="append_const", dest="checks", const=check_pointless_menuconfigs,
@@ -121,6 +129,21 @@ def check_unused():
            sym.name not in referenced:
             print(name_and_locs(sym))
 
+def check_undefined():
+    print_header("Symbols that are used, but undefined")
+    for name, sym in kconf.syms.items():
+        if not sym.nodes:
+            # Undefined symbol. We skip some of the uninteresting ones.
+
+            # Due to how Kconfig works, integer literals show up as symbols
+            # (from e.g. 'default 1'). Skip those.
+            try:
+                int(name, 0)
+                continue
+            except ValueError:
+                # Interesting undefined symbol
+                print(name)
+
 
 def check_pointless_menuconfigs():
     print_header("menuconfig symbols with empty menus")
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux