Skip to content
This repository was archived by the owner on Apr 6, 2022. It is now read-only.

Commit d5c6fec

Browse files
committed
check_compliance.py: Check for duplicated dependencies on Kconfig syms
Check for e.g. 'if FOO' within 'if FOO', or 'depends on FOO' within 'if FOO'. Such duplicated dependencies make it easier to mess up changes to Kconfig files (because it's not obvious that the same dependency is added twice), and make the autogenerated documentation uglier. Some of them might have been added due to Kconfig misunderstandings too. Signed-off-by: Ulf Magnusson <[email protected]>
1 parent e869d25 commit d5c6fec

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

scripts/check_compliance.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ def run(self):
237237

238238
self.check_top_menu_not_too_long(kconf)
239239
self.check_no_pointless_menuconfigs(kconf)
240+
self.check_no_duplicated_deps(kconf)
240241
self.check_no_undef_within_kconfig(kconf)
241242
self.check_no_undef_outside_kconfig(kconf)
242243

@@ -361,6 +362,35 @@ def check_no_pointless_menuconfigs(self, kconf):
361362
""" + "\n".join(f"{node.item.name:35} {node.filename}:{node.linenr}"
362363
for node in bad_mconfs))
363364

365+
def check_no_duplicated_deps(self, kconf):
366+
# Checks that there are no duplicated direct dependencies, e.g. a
367+
# 'depends on FOO' on a symbol defined within an 'if FOO'. Duplicated
368+
# dependencies make changes harder to get right, and make the generated
369+
# Kconfig documentation uglier.
370+
371+
# 'kconfiglib' is global
372+
# pylint: disable=undefined-variable
373+
374+
for node in kconf.node_iter():
375+
# Use the string representation of dependencies so that e.g. a
376+
# duplicated !FOO will be caught despite being a different
377+
# (NOT, <FOO>) tuple.
378+
deps = map(kconfiglib.expr_str,
379+
kconfiglib.split_expr(node.dep, kconfiglib.AND))
380+
381+
for dep, count in collections.Counter(deps).items():
382+
if count > 1:
383+
self.add_failure(f"""\
384+
Duplicated {dep} dependency on symbol/choice/menu/comment at
385+
{node.filename}:{node.linenr}:
386+
387+
{node}
388+
389+
Jump to the item in the menuconfig/guiconfig interface (with '/') and check the
390+
'included via ...' path to figure out where the redundant dependency is coming
391+
from. You might have an 'if FOO' within an 'if FOO', or a 'depends on FOO'
392+
within an 'if FOO'.""")
393+
364394
def check_no_undef_within_kconfig(self, kconf):
365395
"""
366396
Checks that there are no references to undefined Kconfig symbols within

0 commit comments

Comments
 (0)