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

Commit a2e0ba2

Browse files
ulfalizergalak
authored andcommitted
check_compliance.py: Flag pointless 'menuconfig' symbols in CI
Same check as in scripts/kconfig/lint.py in Zephyr. It's worth flagging it in CI too. 'menuconfig' symbols without children are pointless and make the menuconfig interface confusing. See the 'menuconfig symbols' section in https://docs.zephyrproject.org/latest/guides/kconfig/tips.html. Signed-off-by: Ulf Magnusson <[email protected]>
1 parent cbba32e commit a2e0ba2

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
@@ -235,6 +235,7 @@ def run(self):
235235
kconf = self.parse_kconfig()
236236

237237
self.check_top_menu_not_too_long(kconf)
238+
self.check_no_pointless_menuconfigs(kconf)
238239
self.check_no_undef_within_kconfig(kconf)
239240
self.check_no_undef_outside_kconfig(kconf)
240241

@@ -272,6 +273,9 @@ def parse_kconfig(self):
272273
self.error(kconfig_path + " not found")
273274

274275
sys.path.insert(0, kconfig_path)
276+
# Import globally so that e.g. kconfiglib.Symbol can be referenced in
277+
# tests
278+
global kconfiglib
275279
import kconfiglib
276280

277281
# Look up Kconfig files relative to ZEPHYR_BASE
@@ -330,6 +334,32 @@ def check_top_menu_not_too_long(self, kconf):
330334
entries, then bump the 'max_top_items' variable in {}.
331335
""".format(max_top_items, n_top_items, __file__))
332336

337+
def check_no_pointless_menuconfigs(self, kconf):
338+
# Checks that there are no pointless 'menuconfig' symbols without
339+
# children in the Kconfig files
340+
341+
bad_mconfs = []
342+
for node in kconf.node_iter():
343+
# 'kconfiglib' is global
344+
# pylint: disable=undefined-variable
345+
346+
# Avoid flagging empty regular menus and choices, in case people do
347+
# something with 'osource' (could happen for 'menuconfig' symbols
348+
# too, though it's less likely)
349+
if node.is_menuconfig and not node.list and \
350+
isinstance(node.item, kconfiglib.Symbol):
351+
352+
bad_mconfs.append(node)
353+
354+
if bad_mconfs:
355+
self.add_failure("""\
356+
Found pointless 'menuconfig' symbols without children. Use regular 'config'
357+
symbols instead. See
358+
https://docs.zephyrproject.org/latest/guides/kconfig/tips.html#menuconfig-symbols.
359+
360+
""" + "\n".join(f"{node.item.name:35} {node.filename}:{node.linenr}"
361+
for node in bad_mconfs))
362+
333363
def check_no_undef_within_kconfig(self, kconf):
334364
"""
335365
Checks that there are no references to undefined Kconfig symbols within

0 commit comments

Comments
 (0)