Skip to content

Commit 744a563

Browse files
nordicjmfabiobaltieri
authored andcommitted
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]>
1 parent c7e97bb commit 744a563

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
@@ -723,6 +723,61 @@ def parse_kconfig(self):
723723
# Clean up the temporary directory
724724
shutil.rmtree(kconfiglib_dir)
725725

726+
def module_kconfigs(self, regex):
727+
manifest = Manifest.from_file()
728+
kconfigs = ""
729+
730+
# Use hard coded paths for Zephyr for tests, samples and ext. module root
731+
tmp_output = git("grep", "-I", "-h", "--perl-regexp", regex, "--", ":tests", ":samples",
732+
":modules", cwd=ZEPHYR_BASE, ignore_non_zero=True)
733+
734+
if len(tmp_output) > 0:
735+
kconfigs += tmp_output + "\n"
736+
737+
for project in manifest.get_projects([]):
738+
if not manifest.is_active(project):
739+
continue
740+
741+
if not project.is_cloned():
742+
continue
743+
744+
module_path = PurePath(project.abspath)
745+
module_yml = module_path.joinpath('zephyr/module.yml')
746+
747+
if not Path(module_yml).is_file():
748+
module_yml = module_path.joinpath('zephyr/module.yaml')
749+
750+
if Path(module_yml).is_file():
751+
dirs = []
752+
753+
with Path(module_yml).open('r', encoding='utf-8') as f:
754+
meta = yaml.load(f.read(), Loader=SafeLoader)
755+
756+
for folder_type in ['samples', 'tests']:
757+
if folder_type in meta:
758+
for path_ext in meta[folder_type]:
759+
path_full = module_path.joinpath(path_ext)
760+
761+
if Path(path_full).is_dir():
762+
dirs.append(":" + path_ext)
763+
764+
# Add ext. module root, if one is defined
765+
if 'build' in meta and 'settings' in meta['build'] and \
766+
'module_ext_root' in meta['build']['settings']:
767+
path_full = module_path.joinpath(meta['build']['settings']['module_ext_root'])
768+
769+
if Path(path_full).is_dir():
770+
dirs.append(":" + meta['build']['settings']['module_ext_root'])
771+
772+
if len(dirs) > 0:
773+
tmp_output = git("grep", "-I", "-h", "--perl-regexp", regex, "--",
774+
*dirs, cwd=module_path, ignore_non_zero=True)
775+
776+
if len(tmp_output) > 0:
777+
kconfigs += tmp_output + "\n"
778+
779+
return kconfigs
780+
726781
def get_logging_syms(self, kconf):
727782
# Returns a set() with the names of the Kconfig symbols generated with
728783
# logging template in samples/tests folders. The Kconfig symbols doesn't
@@ -743,9 +798,8 @@ def get_logging_syms(self, kconf):
743798
# Warning: Needs to work with both --perl-regexp and the 're' module.
744799
regex = r"^\s*(?:module\s*=\s*)([A-Z0-9_]+)\s*(?:#|$)"
745800

746-
# Grep samples/ and tests/ for symbol definitions
747-
grep_stdout = git("grep", "-I", "-h", "--perl-regexp", regex, "--",
748-
":samples", ":tests", cwd=ZEPHYR_BASE)
801+
# Grep samples/ and tests/ for symbol definitions in all modules
802+
grep_stdout = self.module_kconfigs(regex)
749803

750804
names = re.findall(regex, grep_stdout, re.MULTILINE)
751805

@@ -898,9 +952,8 @@ def get_defined_syms(self, kconf):
898952
# (?:...) is a non-capturing group.
899953
regex = r"^\s*(?:menu)?config\s*([A-Z0-9_]+)\s*(?:#|$)"
900954

901-
# Grep samples/ and tests/ for symbol definitions
902-
grep_stdout = git("grep", "-I", "-h", "--perl-regexp", regex, "--",
903-
":samples", ":tests", cwd=ZEPHYR_BASE)
955+
# Grep samples/ and tests/ for symbol definitions in all modules
956+
grep_stdout = self.module_kconfigs(regex)
904957

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

0 commit comments

Comments
 (0)