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 <jamie.mccrae@nordicsemi.no>
This commit is contained in:
parent
c7e97bb5f8
commit
744a5635f9
@ -723,6 +723,61 @@ class KconfigCheck(ComplianceTest):
|
||||
# Clean up the temporary directory
|
||||
shutil.rmtree(kconfiglib_dir)
|
||||
|
||||
def module_kconfigs(self, regex):
|
||||
manifest = Manifest.from_file()
|
||||
kconfigs = ""
|
||||
|
||||
# Use hard coded paths for Zephyr for tests, samples and ext. module root
|
||||
tmp_output = git("grep", "-I", "-h", "--perl-regexp", regex, "--", ":tests", ":samples",
|
||||
":modules", cwd=ZEPHYR_BASE, ignore_non_zero=True)
|
||||
|
||||
if len(tmp_output) > 0:
|
||||
kconfigs += tmp_output + "\n"
|
||||
|
||||
for project in manifest.get_projects([]):
|
||||
if not manifest.is_active(project):
|
||||
continue
|
||||
|
||||
if not project.is_cloned():
|
||||
continue
|
||||
|
||||
module_path = PurePath(project.abspath)
|
||||
module_yml = module_path.joinpath('zephyr/module.yml')
|
||||
|
||||
if not Path(module_yml).is_file():
|
||||
module_yml = module_path.joinpath('zephyr/module.yaml')
|
||||
|
||||
if Path(module_yml).is_file():
|
||||
dirs = []
|
||||
|
||||
with Path(module_yml).open('r', encoding='utf-8') as f:
|
||||
meta = yaml.load(f.read(), Loader=SafeLoader)
|
||||
|
||||
for folder_type in ['samples', 'tests']:
|
||||
if folder_type in meta:
|
||||
for path_ext in meta[folder_type]:
|
||||
path_full = module_path.joinpath(path_ext)
|
||||
|
||||
if Path(path_full).is_dir():
|
||||
dirs.append(":" + path_ext)
|
||||
|
||||
# Add ext. module root, if one is defined
|
||||
if 'build' in meta and 'settings' in meta['build'] and \
|
||||
'module_ext_root' in meta['build']['settings']:
|
||||
path_full = module_path.joinpath(meta['build']['settings']['module_ext_root'])
|
||||
|
||||
if Path(path_full).is_dir():
|
||||
dirs.append(":" + meta['build']['settings']['module_ext_root'])
|
||||
|
||||
if len(dirs) > 0:
|
||||
tmp_output = git("grep", "-I", "-h", "--perl-regexp", regex, "--",
|
||||
*dirs, cwd=module_path, ignore_non_zero=True)
|
||||
|
||||
if len(tmp_output) > 0:
|
||||
kconfigs += tmp_output + "\n"
|
||||
|
||||
return kconfigs
|
||||
|
||||
def get_logging_syms(self, kconf):
|
||||
# Returns a set() with the names of the Kconfig symbols generated with
|
||||
# logging template in samples/tests folders. The Kconfig symbols doesn't
|
||||
@ -743,9 +798,8 @@ class KconfigCheck(ComplianceTest):
|
||||
# Warning: Needs to work with both --perl-regexp and the 're' module.
|
||||
regex = r"^\s*(?:module\s*=\s*)([A-Z0-9_]+)\s*(?:#|$)"
|
||||
|
||||
# Grep samples/ and tests/ for symbol definitions
|
||||
grep_stdout = git("grep", "-I", "-h", "--perl-regexp", regex, "--",
|
||||
":samples", ":tests", cwd=ZEPHYR_BASE)
|
||||
# Grep samples/ and tests/ for symbol definitions in all modules
|
||||
grep_stdout = self.module_kconfigs(regex)
|
||||
|
||||
names = re.findall(regex, grep_stdout, re.MULTILINE)
|
||||
|
||||
@ -898,9 +952,8 @@ Found disallowed Kconfig symbol in SoC Kconfig files: {sym_name:35}
|
||||
# (?:...) is a non-capturing group.
|
||||
regex = r"^\s*(?:menu)?config\s*([A-Z0-9_]+)\s*(?:#|$)"
|
||||
|
||||
# Grep samples/ and tests/ for symbol definitions
|
||||
grep_stdout = git("grep", "-I", "-h", "--perl-regexp", regex, "--",
|
||||
":samples", ":tests", cwd=ZEPHYR_BASE)
|
||||
# Grep samples/ and tests/ for symbol definitions in all modules
|
||||
grep_stdout = self.module_kconfigs(regex)
|
||||
|
||||
# Generate combined list of configs and choices from the main Kconfig tree.
|
||||
kconf_syms = kconf.unique_defined_syms + kconf.unique_choices
|
||||
|
||||
Loading…
Reference in New Issue
Block a user