Skip to content

Commit 6eb8468

Browse files
committed
[nrf fromtree] 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 Signed-off-by: Jamie McCrae <[email protected]> (cherry picked from commit 744a563)
1 parent 7b962e8 commit 6eb8468

File tree

1 file changed

+59
-6
lines changed

1 file changed

+59
-6
lines changed

scripts/ci/check_compliance.py

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,61 @@ def parse_kconfig(self):
768768
# Clean up the temporary directory
769769
shutil.rmtree(kconfiglib_dir)
770770

771+
def module_kconfigs(self, regex):
772+
manifest = Manifest.from_file()
773+
kconfigs = ""
774+
775+
# Use hard coded paths for Zephyr for tests, samples and ext. module root
776+
tmp_output = git("grep", "-I", "-h", "--perl-regexp", regex, "--", ":tests", ":samples",
777+
":modules", cwd=ZEPHYR_BASE, ignore_non_zero=True)
778+
779+
if len(tmp_output) > 0:
780+
kconfigs += tmp_output + "\n"
781+
782+
for project in manifest.get_projects([]):
783+
if not manifest.is_active(project):
784+
continue
785+
786+
if not project.is_cloned():
787+
continue
788+
789+
module_path = PurePath(project.abspath)
790+
module_yml = module_path.joinpath('zephyr/module.yml')
791+
792+
if not Path(module_yml).is_file():
793+
module_yml = module_path.joinpath('zephyr/module.yaml')
794+
795+
if Path(module_yml).is_file():
796+
dirs = []
797+
798+
with Path(module_yml).open('r', encoding='utf-8') as f:
799+
meta = yaml.load(f.read(), Loader=SafeLoader)
800+
801+
for folder_type in ['samples', 'tests']:
802+
if folder_type in meta:
803+
for path_ext in meta[folder_type]:
804+
path_full = module_path.joinpath(path_ext)
805+
806+
if Path(path_full).is_dir():
807+
dirs.append(":" + path_ext)
808+
809+
# Add ext. module root, if one is defined
810+
if 'build' in meta and 'settings' in meta['build'] and \
811+
'module_ext_root' in meta['build']['settings']:
812+
path_full = module_path.joinpath(meta['build']['settings']['module_ext_root'])
813+
814+
if Path(path_full).is_dir():
815+
dirs.append(":" + meta['build']['settings']['module_ext_root'])
816+
817+
if len(dirs) > 0:
818+
tmp_output = git("grep", "-I", "-h", "--perl-regexp", regex, "--",
819+
*dirs, cwd=module_path, ignore_non_zero=True)
820+
821+
if len(tmp_output) > 0:
822+
kconfigs += tmp_output + "\n"
823+
824+
return kconfigs
825+
771826
def get_logging_syms(self, kconf):
772827
# Returns a set() with the names of the Kconfig symbols generated with
773828
# logging template in samples/tests folders. The Kconfig symbols doesn't
@@ -788,9 +843,8 @@ def get_logging_syms(self, kconf):
788843
# Warning: Needs to work with both --perl-regexp and the 're' module.
789844
regex = r"^\s*(?:module\s*=\s*)([A-Z0-9_]+)\s*(?:#|$)"
790845

791-
# Grep samples/ and tests/ for symbol definitions
792-
grep_stdout = git("grep", "-I", "-h", "--perl-regexp", regex, "--",
793-
":samples", ":tests", cwd=ZEPHYR_BASE)
846+
# Grep samples/ and tests/ for symbol definitions in all modules
847+
grep_stdout = self.module_kconfigs(regex)
794848

795849
names = re.findall(regex, grep_stdout, re.MULTILINE)
796850

@@ -937,9 +991,8 @@ def get_defined_syms(self, kconf):
937991
# (?:...) is a non-capturing group.
938992
regex = r"^\s*(?:menu)?config\s*([A-Z0-9_]+)\s*(?:#|$)"
939993

940-
# Grep samples/ and tests/ for symbol definitions
941-
grep_stdout = git("grep", "-I", "-h", "--perl-regexp", regex, "--",
942-
":samples", ":tests", cwd=ZEPHYR_BASE)
994+
# Grep samples/ and tests/ for symbol definitions in all modules
995+
grep_stdout = self.module_kconfigs(regex)
943996

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

0 commit comments

Comments
 (0)