Skip to content

Commit d835f56

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 c2d705e commit d835f56

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
@@ -762,6 +762,61 @@ def parse_kconfig(self):
762762
# Clean up the temporary directory
763763
shutil.rmtree(kconfiglib_dir)
764764

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

785-
# Grep samples/ and tests/ for symbol definitions
786-
grep_stdout = git("grep", "-I", "-h", "--perl-regexp", regex, "--",
787-
":samples", ":tests", cwd=ZEPHYR_BASE)
840+
# Grep samples/ and tests/ for symbol definitions in all modules
841+
grep_stdout = self.module_kconfigs(regex)
788842

789843
names = re.findall(regex, grep_stdout, re.MULTILINE)
790844

@@ -931,9 +985,8 @@ def get_defined_syms(self, kconf):
931985
# (?:...) is a non-capturing group.
932986
regex = r"^\s*(?:menu)?config\s*([A-Z0-9_]+)\s*(?:#|$)"
933987

934-
# Grep samples/ and tests/ for symbol definitions
935-
grep_stdout = git("grep", "-I", "-h", "--perl-regexp", regex, "--",
936-
":samples", ":tests", cwd=ZEPHYR_BASE)
988+
# Grep samples/ and tests/ for symbol definitions in all modules
989+
grep_stdout = self.module_kconfigs(regex)
937990

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

0 commit comments

Comments
 (0)