diff --git a/scripts/kconfig-lint.py b/scripts/kconfig-lint.py index 308c82d..a154e9c 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 @@ # 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 @@ 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 @@ 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")