Skip to content

Commit 50d9ed5

Browse files
57300kartben
authored andcommitted
scripts: ci: check_compliance: Update KconfigCheck subclassing
So far, the behavior of different Kconfig checks has been parametrized using the `run()` method, and every new check has introduced with it a new argument to that method. It's possible to replace each `run()` argument by way of overriding different class methods and making better use of inheritance: free=False Stub check_no_undef_outside_kconfig() no_modules=True Stub get_modules() filename Introduce class member FILENAME hwm (unused) This should establish a more scalable and straightforward pattern for adding future Kconfig checks. It also favors composability, which will come in handy when implementing checks for sysbuild Kconfig. Additionally, avoid duplicating `doc` and `path_hint` in every subclass. Signed-off-by: Grzegorz Swiderski <[email protected]>
1 parent 17ba479 commit 50d9ed5

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

scripts/ci/check_compliance.py

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -371,19 +371,19 @@ class KconfigCheck(ComplianceTest):
371371
doc = "See https://docs.zephyrproject.org/latest/build/kconfig/tips.html for more details."
372372
path_hint = "<zephyr-base>"
373373

374-
def run(self, full=True, no_modules=False, filename="Kconfig", hwm=None):
375-
self.no_modules = no_modules
374+
# Top-level Kconfig file. The path can be relative to srctree (ZEPHYR_BASE).
375+
FILENAME = "Kconfig"
376376

377-
kconf = self.parse_kconfig(filename=filename, hwm=hwm)
377+
def run(self):
378+
kconf = self.parse_kconfig()
378379

379380
self.check_top_menu_not_too_long(kconf)
380381
self.check_no_pointless_menuconfigs(kconf)
381382
self.check_no_undef_within_kconfig(kconf)
382383
self.check_no_redefined_in_defconfig(kconf)
383384
self.check_no_enable_in_boolean_prompt(kconf)
384385
self.check_soc_name_sync(kconf)
385-
if full:
386-
self.check_no_undef_outside_kconfig(kconf)
386+
self.check_no_undef_outside_kconfig(kconf)
387387

388388
def get_modules(self, modules_file, settings_file):
389389
"""
@@ -393,11 +393,6 @@ def get_modules(self, modules_file, settings_file):
393393
This is needed to complete Kconfig sanity tests.
394394
395395
"""
396-
if self.no_modules:
397-
with open(modules_file, 'w') as fp_module_file:
398-
fp_module_file.write("# Empty\n")
399-
return
400-
401396
# Invoke the script directly using the Python executable since this is
402397
# not a module nor a pip-installed Python utility
403398
zephyr_module_path = os.path.join(ZEPHYR_BASE, "scripts",
@@ -578,7 +573,7 @@ def get_v2_model(self, kconfig_dir, settings_file):
578573
for arch in v2_archs['archs']:
579574
fp.write('source "' + (Path(arch['path']) / 'Kconfig').as_posix() + '"\n')
580575

581-
def parse_kconfig(self, filename="Kconfig", hwm=None):
576+
def parse_kconfig(self):
582577
"""
583578
Returns a kconfiglib.Kconfig object for the Kconfig files. We reuse
584579
this object for all tests to avoid having to reparse for each test.
@@ -638,7 +633,7 @@ def parse_kconfig(self, filename="Kconfig", hwm=None):
638633
# them: so some warnings might get printed
639634
# twice. "warn_to_stderr=False" could unfortunately cause
640635
# some (other) warnings to never be printed.
641-
return kconfiglib.Kconfig(filename=filename)
636+
return kconfiglib.Kconfig(filename=self.FILENAME)
642637
except kconfiglib.KconfigError as e:
643638
self.failure(str(e))
644639
raise EndTest
@@ -1053,40 +1048,36 @@ class KconfigBasicCheck(KconfigCheck):
10531048
references inside the Kconfig tree.
10541049
"""
10551050
name = "KconfigBasic"
1056-
doc = "See https://docs.zephyrproject.org/latest/build/kconfig/tips.html for more details."
1057-
path_hint = "<zephyr-base>"
10581051

1059-
def run(self):
1060-
super().run(full=False)
1052+
def check_no_undef_outside_kconfig(self, kconf):
1053+
pass
1054+
10611055

1062-
class KconfigBasicNoModulesCheck(KconfigCheck):
1056+
class KconfigBasicNoModulesCheck(KconfigBasicCheck):
10631057
"""
10641058
Checks if we are introducing any new warnings/errors with Kconfig when no
10651059
modules are available. Catches symbols used in the main repository but
10661060
defined only in a module.
10671061
"""
10681062
name = "KconfigBasicNoModules"
1069-
doc = "See https://docs.zephyrproject.org/latest/build/kconfig/tips.html for more details."
1070-
path_hint = "<zephyr-base>"
1071-
def run(self):
1072-
super().run(full=False, no_modules=True)
1063+
1064+
def get_modules(self, modules_file, settings_file):
1065+
with open(modules_file, 'w') as fp_module_file:
1066+
fp_module_file.write("# Empty\n")
10731067

10741068

1075-
class KconfigHWMv2Check(KconfigCheck, ComplianceTest):
1069+
class KconfigHWMv2Check(KconfigBasicCheck):
10761070
"""
10771071
This runs the Kconfig test for board and SoC v2 scheme.
10781072
This check ensures that all symbols inside the v2 scheme is also defined
10791073
within the same tree.
10801074
This ensures the board and SoC trees are fully self-contained and reusable.
10811075
"""
10821076
name = "KconfigHWMv2"
1083-
doc = "See https://docs.zephyrproject.org/latest/guides/kconfig/index.html for more details."
10841077

1085-
def run(self):
1086-
# Use dedicated Kconfig board / soc v2 scheme file.
1087-
# This file sources only v2 scheme tree.
1088-
kconfig_file = os.path.join(os.path.dirname(__file__), "Kconfig.board.v2")
1089-
super().run(full=False, hwm="v2", filename=kconfig_file)
1078+
# Use dedicated Kconfig board / soc v2 scheme file.
1079+
# This file sources only v2 scheme tree.
1080+
FILENAME = os.path.join(os.path.dirname(__file__), "Kconfig.board.v2")
10901081

10911082

10921083
class Nits(ComplianceTest):

0 commit comments

Comments
 (0)