Skip to content

Commit

Permalink
scripts: ci: check_compliance: Add support for modules for Kconfig
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
nordicjm committed Mar 4, 2025
1 parent 5736aed commit 068c57b
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions scripts/ci/check_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@
import shutil
import textwrap
import unidiff
import yaml

from yamllint import config, linter

from junitparser import TestCase, TestSuite, JUnitXml, Skipped, Error, Failure
import magic

from pathlib import Path, PurePath

Check failure on line 32 in scripts/ci/check_compliance.py

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

Python lint error (F811) see https://docs.astral.sh/ruff/rules/redefined-while-unused

scripts/ci/check_compliance.py:32 Redefinition of unused `Path` from line 14

Check warning on line 32 in scripts/ci/check_compliance.py

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

W0404

scripts/ci/check_compliance.py:32 Reimport 'Path' (imported line 14) (reimported)

from west.manifest import Manifest
from west.manifest import ManifestProject

try:
from yaml import CSafeLoader as SafeLoader
except ImportError:
from yaml import SafeLoader

sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from get_maintainer import Maintainers, MaintainersError
import list_boards
Expand Down Expand Up @@ -720,6 +728,45 @@ def check_disallowed_defconfigs(self, kconf):
"--perl-regexp", regex_socs, "--", ":soc",
cwd=ZEPHYR_BASE)

manifest = Manifest.from_file()
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():
with Path(module_yml).open('r', encoding='utf-8') as f:
meta = yaml.load(f.read(), Loader=SafeLoader)

if 'build' in meta and 'settings' in meta['build']:
if 'board_root' in meta['build']['settings']:
tmp_path = module_path.joinpath(meta['build']['settings']['board_root'])
if Path(tmp_path.joinpath('boards')).is_dir():
tmp_output = git("grep", "--line-number", "-I", "--null",
"--perl-regexp", regex_boards, "--", ":boards",
cwd=tmp_path, ignore_non_zero=True)

if len(tmp_output) > 0:
grep_stdout_boards = grep_stdout_boards + "\n" + tmp_output

if 'soc_root' in meta['build']['settings']:
tmp_path = module_path.joinpath(meta['build']['settings']['soc_root'])
if Path(tmp_path.joinpath('soc')).is_dir():
tmp_output = git("grep", "--line-number", "-I", "--null",
"--perl-regexp", regex_socs, "--", ":soc",
cwd=tmp_path, ignore_non_zero=True)

if len(tmp_output) > 0:
grep_stdout_socs = grep_stdout_socs + "\n" + tmp_output

# Board processing
# splitlines() supports various line terminators
for grep_line in grep_stdout_boards.splitlines():
Expand Down

0 comments on commit 068c57b

Please sign in to comment.