Skip to content

Commit 6d73a9c

Browse files
nordicjmdanieldegrasse
authored andcommitted
scripts: ci: check_compliance: Add support for modules for Kconfig
Adds support for checking modules for disallow Kconfig's in boards and SoCs, which have been defined in a Zephyr module file Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
1 parent 32d68be commit 6d73a9c

File tree

1 file changed

+54
-5
lines changed

1 file changed

+54
-5
lines changed

scripts/ci/check_compliance.py

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import json
1111
import logging
1212
import os
13-
from pathlib import Path
13+
from pathlib import Path, PurePath
1414
import platform
1515
import re
1616
import subprocess
@@ -31,6 +31,11 @@
3131
from west.manifest import Manifest
3232
from west.manifest import ManifestProject
3333

34+
try:
35+
from yaml import CSafeLoader as SafeLoader
36+
except ImportError:
37+
from yaml import SafeLoader
38+
3439
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
3540
from get_maintainer import Maintainers, MaintainersError
3641
import list_boards
@@ -751,6 +756,23 @@ def get_logging_syms(self, kconf):
751756

752757
return set(kconf_syms)
753758

759+
def module_disallowed_check(self, module_path, type, folder, meta, regex):
760+
# Returns a list with lines from git grep which includes Kconfigs from defconfig files
761+
entry = type + '_root'
762+
git_folder = ":" + folder
763+
764+
if entry in meta['build']['settings']:
765+
tmp_path = module_path.joinpath(meta['build']['settings'][entry])
766+
767+
if Path(tmp_path.joinpath(folder)).is_dir():
768+
tmp_output = git("grep", "--line-number", "-I", "--null",
769+
"--perl-regexp", regex, "--", git_folder,
770+
cwd=tmp_path, ignore_non_zero=True)
771+
772+
if len(tmp_output) > 0:
773+
return tmp_output.splitlines()
774+
return []
775+
754776
def check_disallowed_defconfigs(self, kconf):
755777
"""
756778
Checks that there are no disallowed Kconfigs used in board/SoC defconfig files
@@ -799,14 +821,41 @@ def check_disallowed_defconfigs(self, kconf):
799821

800822
grep_stdout_boards = git("grep", "--line-number", "-I", "--null",
801823
"--perl-regexp", regex_boards, "--", ":boards",
802-
cwd=ZEPHYR_BASE)
824+
cwd=ZEPHYR_BASE).splitlines()
803825
grep_stdout_socs = git("grep", "--line-number", "-I", "--null",
804826
"--perl-regexp", regex_socs, "--", ":soc",
805-
cwd=ZEPHYR_BASE)
827+
cwd=ZEPHYR_BASE).splitlines()
828+
829+
manifest = Manifest.from_file()
830+
for project in manifest.get_projects([]):
831+
if not manifest.is_active(project):
832+
continue
833+
834+
if not project.is_cloned():
835+
continue
836+
837+
module_path = PurePath(project.abspath)
838+
module_yml = module_path.joinpath('zephyr/module.yml')
839+
840+
if not Path(module_yml).is_file():
841+
module_yml = module_path.joinpath('zephyr/module.yaml')
842+
843+
if Path(module_yml).is_file():
844+
with Path(module_yml).open('r', encoding='utf-8') as f:
845+
meta = yaml.load(f.read(), Loader=SafeLoader)
846+
847+
if 'build' in meta and 'settings' in meta['build']:
848+
grep_stdout_boards.extend(self.module_disallowed_check(module_path,
849+
'board',
850+
'boards', meta,
851+
regex_boards))
852+
grep_stdout_socs.extend(self.module_disallowed_check(module_path, 'soc',
853+
'soc', meta,
854+
regex_socs))
806855

807856
# Board processing
808857
# splitlines() supports various line terminators
809-
for grep_line in grep_stdout_boards.splitlines():
858+
for grep_line in grep_stdout_boards:
810859
path, lineno, line = grep_line.split("\0")
811860

812861
# Extract symbol references (might be more than one) within the line
@@ -823,7 +872,7 @@ def check_disallowed_defconfigs(self, kconf):
823872

824873
# SoCs processing
825874
# splitlines() supports various line terminators
826-
for grep_line in grep_stdout_socs.splitlines():
875+
for grep_line in grep_stdout_socs:
827876
path, lineno, line = grep_line.split("\0")
828877

829878
# Extract symbol references (might be more than one) within the line

0 commit comments

Comments
 (0)