diff options
author | Ahmad Fatoum <ahmad@a3f.at> | 2020-04-28 09:37:21 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-04-29 08:41:49 +0200 |
commit | 24b9cad042788cc974ad4345d59a5c875fdbcf00 (patch) | |
tree | 41784c5e7ead78c48bb75fecb7a3cd1b7f9c94ed /scripts | |
parent | e509d4a03d039729baea0c9e5862e0ecb5cbd65c (diff) | |
download | barebox-24b9cad042788cc974ad4345d59a5c875fdbcf00.tar.gz barebox-24b9cad042788cc974ad4345d59a5c875fdbcf00.tar.xz |
scripts: kconfig-lint.py: extend for undefined symbol detection
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>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/kconfig-lint.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/scripts/kconfig-lint.py b/scripts/kconfig-lint.py index 308c82dfd8..a154e9ccca 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) @@ -79,6 +80,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, help="""\ @@ -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") |