Skip to content

Commit e2e216b

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 c40aebf commit e2e216b

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

scripts/ci/check_compliance.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,45 @@ 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+
with Path(module_yml).open('r', encoding='utf-8') as f:
775+
meta = yaml.load(f.read(), Loader=SafeLoader)
776+
dirs = []
777+
778+
for folder_type in ['samples', 'tests']:
779+
if folder_type in meta:
780+
for path_ext in meta[folder_type]:
781+
path_full = module_path.joinpath(path_ext)
782+
783+
if Path(path_full).is_dir():
784+
dirs.append(":" + path_ext)
785+
786+
if len(dirs) > 0:
787+
tmp_output = git("grep", "-I", "-h", "--perl-regexp", regex, "--",
788+
*dirs, cwd=module_path, ignore_non_zero=True)
789+
790+
if len(tmp_output) > 0:
791+
kconfigs += tmp_output + "\n"
792+
793+
return kconfigs
794+
756795
def get_logging_syms(self, kconf):
757796
# Returns a set() with the names of the Kconfig symbols generated with
758797
# logging template in samples/tests folders. The Kconfig symbols doesn't
@@ -773,9 +812,8 @@ def get_logging_syms(self, kconf):
773812
# Warning: Needs to work with both --perl-regexp and the 're' module.
774813
regex = r"^\s*(?:module\s*=\s*)([A-Z0-9_]+)\s*(?:#|$)"
775814

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

780818
names = re.findall(regex, grep_stdout, re.MULTILINE)
781819

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

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

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

0 commit comments

Comments
 (0)