mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <ahmad@a3f.at>
To: barebox@lists.infradead.org
Subject: [PATCH 02/11] scripts: kconfig-lint.py: extend for undefined symbol detection
Date: Tue, 28 Apr 2020 09:37:21 +0200	[thread overview]
Message-ID: <20200428073730.34579-2-ahmad@a3f.at> (raw)
In-Reply-To: <20200428073730.34579-1-ahmad@a3f.at>

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@a3f.at>
---
 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@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2020-04-28  7:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-28  7:37 [PATCH 01/11] scripts: import Zephyr scripts/kconfig/lint.py into barebox Ahmad Fatoum
2020-04-28  7:37 ` Ahmad Fatoum [this message]
2020-04-28  7:37 ` [PATCH 03/11] commands: fix misindented help text Ahmad Fatoum
2020-04-28  7:37 ` [PATCH 04/11] ARM: at91: remove undefined Kconfig symbol Ahmad Fatoum
2020-04-28  7:37 ` [PATCH 05/11] ARM: socfpga: remove duplicate ARCH_TEXT_BASE Ahmad Fatoum
2020-04-28  7:37 ` [PATCH 06/11] crypto: drop select on non-existing Kconfig options Ahmad Fatoum
2020-04-28  7:37 ` [PATCH 07/11] lib: bch: define referenced but undefined Kconfig option Ahmad Fatoum
2020-04-28  7:37 ` [PATCH 08/11] MIPS: ath79: define used, but undefined, " Ahmad Fatoum
2020-04-28  7:37 ` [PATCH 09/11] phy: freescale: fix typo in Kconfig default Ahmad Fatoum
2020-04-28  7:37 ` [PATCH 10/11] reset: " Ahmad Fatoum
2020-04-28  7:37 ` [PATCH 11/11] treewide: Kconfig: remove some unused symbols Ahmad Fatoum
2020-04-29  6:43 ` [PATCH 01/11] scripts: import Zephyr scripts/kconfig/lint.py into barebox Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200428073730.34579-2-ahmad@a3f.at \
    --to=ahmad@a3f.at \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox