From df9a4223fe3cf1a350ccd6d0840c88152475523b Mon Sep 17 00:00:00 2001 From: Torsten Rasmussen Date: Wed, 21 Feb 2024 22:50:57 +0100 Subject: [PATCH] scripts: ci: introduce soc name check in check_compliance soc.yml files define SoC names which are used in board.yml. All SoC names and directories are exported to the build system and can be referenced using the SoC name as identifier. Kconfig defines a CONFIG_SOC setting with the same name which can be used in build system and is selected by the board. Thus the CONFIG_SOC value can be used to lookup the details of the SoC. This commit introduces a new compliance check which ensures the SoC name and the CONFIG_SOC name value are in sync. Signed-off-by: Torsten Rasmussen --- scripts/ci/check_compliance.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/scripts/ci/check_compliance.py b/scripts/ci/check_compliance.py index d60bff4e76e..ac106c9266e 100755 --- a/scripts/ci/check_compliance.py +++ b/scripts/ci/check_compliance.py @@ -285,6 +285,7 @@ class KconfigCheck(ComplianceTest): self.check_no_undef_within_kconfig(kconf) self.check_no_redefined_in_defconfig(kconf) self.check_no_enable_in_boolean_prompt(kconf) + self.check_soc_name_sync(kconf) if full: self.check_no_undef_outside_kconfig(kconf) @@ -658,6 +659,34 @@ https://docs.zephyrproject.org/latest/build/kconfig/tips.html#menuconfig-symbols if undef_ref_warnings: self.failure(f"Undefined Kconfig symbols:\n\n {undef_ref_warnings}") + def check_soc_name_sync(self, kconf): + root_args = argparse.Namespace(**{'soc_roots': [Path(ZEPHYR_BASE)]}) + v2_systems = list_hardware.find_v2_systems(root_args) + + soc_names = {soc.name for soc in v2_systems.get_socs()} + + soc_kconfig_names = set() + for node in kconf.node_iter(): + # 'kconfiglib' is global + # pylint: disable=undefined-variable + if isinstance(node.item, kconfiglib.Symbol) and node.item.name == "SOC": + n = node.item + for d in n.defaults: + soc_kconfig_names.add(d[0].name) + + soc_name_warnings = [] + for name in soc_names: + if name not in soc_kconfig_names: + soc_name_warnings.append(f"soc name: {name} not found in CONFIG_SOC defaults.") + + if soc_name_warnings: + soc_name_warning_str = '\n'.join(soc_name_warnings) + self.failure(f''' +Missing SoC names or CONFIG_SOC vs soc.yml out of sync: + +{soc_name_warning_str} +''') + def check_no_undef_outside_kconfig(self, kconf): """ Checks that there are no references to undefined Kconfig symbols