Skip to content

Commit f40f7bf

Browse files
committed
[nrf fromlist] scripts: ci: check_compliance: Add support for module Kconfigs
Adds support for checking module samples and tests for additional Kconfigs, as well as logging Kconfigs, so that this check can be reused more easily with out of tree manifest repos Upstream PR #: 92765 Signed-off-by: Jamie McCrae <[email protected]>
1 parent 5e82556 commit f40f7bf

File tree

1 file changed

+56
-6
lines changed

1 file changed

+56
-6
lines changed

scripts/ci/check_compliance.py

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,58 @@ def parse_kconfig(self):
753753
# Clean up the temporary directory
754754
shutil.rmtree(kconfiglib_dir)
755755

756+
def module_kconfigs(self, regex):
757+
manifest = Manifest.from_file()
758+
kconfigs = ""
759+
760+
for project in manifest.get_projects([]):
761+
if not manifest.is_active(project):
762+
continue
763+
764+
if not project.is_cloned():
765+
continue
766+
767+
module_path = PurePath(project.abspath)
768+
module_yml = module_path.joinpath('zephyr/module.yml')
769+
770+
if not Path(module_yml).is_file():
771+
module_yml = module_path.joinpath('zephyr/module.yaml')
772+
773+
if Path(module_yml).is_file():
774+
dirs = []
775+
776+
with Path(module_yml).open('r', encoding='utf-8') as f:
777+
meta = yaml.load(f.read(), Loader=SafeLoader)
778+
779+
for folder_type in ['samples', 'tests']:
780+
if folder_type in meta:
781+
for path_ext in meta[folder_type]:
782+
path_full = module_path.joinpath(path_ext)
783+
784+
if Path(path_full).is_dir():
785+
dirs.append(":" + path_ext)
786+
787+
# Add ext. module root, if one is defined. For zephyr, the base one is added
788+
# directly since in CMake it is added statically instead of by parsing the
789+
# zephyr module file
790+
if module_path == ZEPHYR_BASE:
791+
dirs.append(":" + str(module_path / "modules"))
792+
elif 'build' in meta and 'settings' in meta['build'] and \
793+
'module_ext_root' in meta['build']['settings']:
794+
path_full = module_path.joinpath(meta['build']['settings']['module_ext_root'])
795+
796+
if Path(path_full).is_dir():
797+
dirs.append(":" + meta['build']['settings']['module_ext_root'])
798+
799+
if len(dirs) > 0:
800+
tmp_output = git("grep", "-I", "-h", "--perl-regexp", regex, "--",
801+
*dirs, cwd=module_path, ignore_non_zero=True)
802+
803+
if len(tmp_output) > 0:
804+
kconfigs += tmp_output + "\n"
805+
806+
return kconfigs
807+
756808
def get_logging_syms(self, kconf):
757809
# Returns a set() with the names of the Kconfig symbols generated with
758810
# logging template in samples/tests folders. The Kconfig symbols doesn't
@@ -773,9 +825,8 @@ def get_logging_syms(self, kconf):
773825
# Warning: Needs to work with both --perl-regexp and the 're' module.
774826
regex = r"^\s*(?:module\s*=\s*)([A-Z0-9_]+)\s*(?:#|$)"
775827

776-
# Grep samples/ and tests/ for symbol definitions
777-
grep_stdout = git("grep", "-I", "-h", "--perl-regexp", regex, "--",
778-
":samples", ":tests", cwd=ZEPHYR_BASE)
828+
# Grep samples/ and tests/ for symbol definitions in all modules
829+
grep_stdout = self.module_kconfigs(regex)
779830

780831
names = re.findall(regex, grep_stdout, re.MULTILINE)
781832

@@ -922,9 +973,8 @@ def get_defined_syms(self, kconf):
922973
# (?:...) is a non-capturing group.
923974
regex = r"^\s*(?:menu)?config\s*([A-Z0-9_]+)\s*(?:#|$)"
924975

925-
# Grep samples/ and tests/ for symbol definitions
926-
grep_stdout = git("grep", "-I", "-h", "--perl-regexp", regex, "--",
927-
":samples", ":tests", cwd=ZEPHYR_BASE)
976+
# Grep samples/ and tests/ for symbol definitions in all modules
977+
grep_stdout = self.module_kconfigs(regex)
928978

929979
# Generate combined list of configs and choices from the main Kconfig tree.
930980
kconf_syms = kconf.unique_defined_syms + kconf.unique_choices

0 commit comments

Comments
 (0)