Lines Matching +full:class +full:- +full:rev

5 # SPDX-License-Identifier: Apache-2.0
57 f"{cp.stdout.decode('utf-8')}\n"
59 f"{cp.stderr.decode('utf-8')}\n")
61 return cp.stdout.decode("utf-8").rstrip()
70 return git('rev-list',
71 f'--max-count={-1 if "." in refspec else 1}', refspec).split()
74 filter_arg = (f'--diff-filter={filter}',) if filter else ()
75 paths_arg = ('--', *paths) if paths else ()
76 out = git('diff', '--name-only', *filter_arg, COMMIT_RANGE, *paths_arg)
84 class FmtdFailure(Failure):
112 class ComplianceTest:
114 Base class for tests. Inheriting classes should have a run() method and set
115 these class variables:
128 - The magic string "<zephyr-base>" can be used to refer to the
131 - The magic string "<git-top>" refers to the top-level repository
132 directory. This avoids running 'git' to find the top-level directory
133 before main() runs (class variable assignments run when the 'class ...'
192 class EndTest(Exception):
201 class CheckPatch(ComplianceTest):
207 …doc = "See https://docs.zephyrproject.org/latest/contribute/guidelines.html#coding-style for more …
208 path_hint = "<git-top>"
215 diff = subprocess.Popen(('git', 'diff', '--no-ext-diff', COMMIT_RANGE),
219 subprocess.run((checkpatch, '--mailback', '--no-tree', '-'),
227 output = ex.output.decode("utf-8")
248 class BoardYmlCheck(ComplianceTest):
254 path_hint = "<zephyr-base>"
270 with open(os.path.join(ZEPHYR_BASE, "dts", "bindings", "vendor-prefixes.txt")) as fp:
279 self.error(f"Invalid line in vendor-prefixes.txt:\"{line}\".")
287 class ClangFormatCheck(ComplianceTest):
289 Check if clang-format reports any issues
292 …doc = "See https://docs.zephyrproject.org/latest/contribute/guidelines.html#clang-format for more …
293 path_hint = "<git-top>"
296 exe = f"clang-format-diff.{'exe' if platform.system() == 'Windows' else 'py'}"
302 diff = subprocess.Popen(('git', 'diff', '-U0', '--no-color', COMMIT_RANGE, '--', file),
306 subprocess.run((exe, '-p1'),
314 patchset = unidiff.PatchSet.from_string(ex.output, encoding="utf-8")
318 before = next(i for i,v in enumerate(hunk) if str(v).startswith(('-', '+')))
319 … after = next(i for i,v in enumerate(reversed(hunk)) if str(v).startswith(('-', '+')))
320 msg = "".join([str(l) for l in hunk[before:-after or None]])
324 "You may want to run clang-format on this change",
325 file, line=hunk.source_start + hunk.source_length - after,
329 class DevicetreeBindingsCheck(ComplianceTest):
335 path_hint = "<zephyr-base>"
365 class KconfigCheck(ComplianceTest):
372 path_hint = "<zephyr-base>"
402 # not a module nor a pip-installed Python utility
406 '--kconfig-out', modules_file, '--settings-out', settings_file]
411 self.error(ex.output.decode("utf-8"))
423 re.sub('[^a-zA-Z0-9]', '_', module).upper(),
434 # not a module nor a pip-installed Python utility
457 # not a module nor a pip-installed Python utility
468 '--kconfig-out', kconfig_dts_file, '--bindings-dirs']
475 self.error(ex.output.decode("utf-8"))
488 # pylint: disable=undefined-variable
531 board_str = 'BOARD_' + re.sub(r"[^a-zA-Z0-9_]", "_", board.name).upper()
536 re.sub(r"[^a-zA-Z0-9_]", "_", qualifier)).upper()
666 # Warning: Needs to work with both --perl-regexp and the 're' module.
667 regex = r"^\s*(?:module\s*=\s*)([A-Z0-9_]+)\s*(?:#|$)"
670 grep_stdout = git("grep", "-I", "-h", "--perl-regexp", regex, "--",
690 # Warning: Needs to work with both --perl-regexp and the 're' module.
691 # (?:...) is a non-capturing group.
692 regex = r"^\s*(?:menu)?config\s*([A-Z0-9_]+)\s*(?:#|$)"
695 grep_stdout = git("grep", "-I", "-h", "--perl-regexp", regex, "--",
710 Checks that there aren't too many items in the top-level menu (which
719 # shown in the menuconfig (outside show-all mode).
727 prompts) in the top-level Kconfig menu, found {n_top_items} items. If you're
736 # pylint: disable=undefined-variable
750 # skip Kconfig nodes not in-tree (will present an absolute path)
755 # pylint: disable=undefined-variable
778 # pylint: disable=undefined-variable
792 https://docs.zephyrproject.org/latest/build/kconfig/tips.html#menuconfig-symbols.
817 # pylint: disable=undefined-variable
848 # 'git grep --only-matching' would get rid of the surrounding context
855 # - ##, for token pasting (CONFIG_FOO_##X)
857 # - $, e.g. for CMake variable expansion (CONFIG_FOO_${VAR})
859 # - @, e.g. for CMakes's configure_file() (CONFIG_FOO_@VAR@)
861 # - {, e.g. for Python scripts ("CONFIG_FOO_{}_BAR".format(...)")
863 # - *, meant for comments like '#endif /* CONFIG_FOO_* */
870 # Warning: Needs to work with both --perl-regexp and the 're' module
871 regex = r"\bCONFIG_[A-Z0-9_]+\b(?!\s*##|[$@{(.*])"
875 grep_stdout = git("grep", "--line-number", "-I", "--null",
876 "--perl-regexp", regex, "--", ":!/doc/releases",
890 not (sym_name.endswith("_MODULE") and sym_name[:-7] in defined_syms):
922 # zephyr-keep-sorted-start re(^\s+")
945 "BOOT_SERIAL_BOOT_MODE", # Used in (sysbuild-based) test/
947 "BOOT_SERIAL_CDC_ACM", # Used in (sysbuild-based) test
948 "BOOT_SERIAL_ENTRANCE_GPIO", # Used in (sysbuild-based) test
952 "BOOT_SHARE_DATA_BOOTINFO", # Used in (sysbuild-based) test
962 "BOOT_VALIDATE_SLOT0", # Used in (sysbuild-based) test
963 "BOOT_WATCHDOG_FEED", # Used in (sysbuild-based) test
969 "CMD_CACHE", # Defined in U-Boot, mentioned in docs
995 "MCUBOOT_ACTION_HOOKS", # Used in (sysbuild-based) test
996 "MCUBOOT_CLEANUP_ARM_CORE", # Used in (sysbuild-based) test
1002 "MCUBOOT_SERIAL", # Used in (sysbuild-based) test/
1015 "PSA_H", # This is used in config-psa.h as guard for the header file
1044 # zephyr-keep-sorted-stop
1048 class KconfigBasicCheck(KconfigCheck):
1057 path_hint = "<zephyr-base>"
1062 class KconfigBasicNoModulesCheck(KconfigCheck):
1070 path_hint = "<zephyr-base>"
1075 class KconfigHWMv2Check(KconfigCheck, ComplianceTest):
1080 This ensures the board and SoC trees are fully self-contained and reusable.
1092 class Nits(ComplianceTest):
1098 …doc = "See https://docs.zephyrproject.org/latest/contribute/guidelines.html#coding-style for more …
1099 path_hint = "<git-top>"
1121 # Checks for a spammy copy-pasted header format
1123 with open(os.path.join(GIT_TOP, fname), encoding="utf-8") as f:
1126 # 'Kconfig - yada yada' has a copy-pasted redundant filename at the
1127 # top. This probably means all of the header was copy-pasted.
1128 if re.match(r"\s*#\s*(K|k)config[\w.-]*\s*-", contents):
1131 https://docs.zephyrproject.org/latest/build/kconfig/tips.html#header-comments-and-other-nits):
1136 # SPDX-License-Identifier: <License>
1140 Skip the "Kconfig - " part of the first line, since it's clear that the comment
1141 is about Kconfig from context. The "# Kconfig - " is what triggers this
1149 with open(os.path.join(GIT_TOP, fname), encoding="utf-8") as f:
1164 with open(os.path.join(GIT_TOP, fname), encoding="utf-8") as f:
1173 with open(os.path.join(GIT_TOP, fname), encoding="utf-8") as f:
1187 class GitDiffCheck(ComplianceTest):
1189 Checks for conflict markers or whitespace errors with git diff --check
1193 path_hint = "<git-top>"
1198 # Reason: `--check` is mutually exclusive with `--name-only` and `-s`
1202 # Ignore non-zero return status code
1203 # Reason: `git diff --check` sets the return code to the number of offending lines
1204 diff = git("diff", f"{shaidx}^!", "--check", ignore_non_zero=True)
1214 class GitLint(ComplianceTest):
1220 …doc = "See https://docs.zephyrproject.org/latest/contribute/guidelines.html#commit-guidelines for …
1221 path_hint = "<git-top>"
1227 subprocess.run('gitlint --commits ' + COMMIT_RANGE,
1234 self.failure(ex.output.decode("utf-8"))
1237 class PyLint(ComplianceTest):
1244 path_hint = "<git-top>"
1272 pylintcmd = ["pylint", "--output-format=json2", "--rcfile=" + pylintrc,
1273 "--load-plugins=argparse-checker"] + py_files
1283 output = ex.output.decode("utf-8")
1304 # Uses the python-magic library, so that we can detect Python
1305 # files that don't end in .py as well. python-magic is a frontend
1310 mime=True) == "text/x-python")]
1313 class Identity(ComplianceTest):
1315 Checks if Emails of author and signed-off messages are consistent.
1318 …doc = "See https://docs.zephyrproject.org/latest/contribute/guidelines.html#commit-guidelines for …
1319 # git rev-list and git log don't depend on the current (sub)directory
1321 path_hint = "<git-top>"
1325 commit = git("log", "--decorate=short", "-n 1", shaidx)
1338 match = re.search(r"signed-off-by:\s(.*)", line, re.IGNORECASE)
1343 f"the signed-off-by entries."
1365 class BinaryFiles(ComplianceTest):
1371 path_hint = "<git-top>"
1378 for stat in git("diff", "--numstat", "--diff-filter=A",
1381 if added == "-" and deleted == "-":
1388 class ImageSize(ComplianceTest):
1394 path_hint = "<git-top>"
1418 class MaintainersFormat(ComplianceTest):
1424 path_hint = "<git-top>"
1438 class ModulesMaintainers(ComplianceTest):
1444 path_hint = "<git-top>"
1473 class YAMLLint(ComplianceTest):
1479 path_hint = "<git-top>"
1492 yaml_config.rules["line-length"] = False
1493 yaml_config.rules["truthy"]["allowed-values"].extend(['on', 'off'])
1495 yaml_config.rules["truthy"]["allowed-values"].extend(['yes', 'no'])
1503 class SphinxLint(ComplianceTest):
1509 doc = "Check Sphinx/reStructuredText files with sphinx-lint."
1510 path_hint = "<git-top>"
1512 # Checkers added/removed to sphinx-lint's default set
1513 DISABLE_CHECKERS = ["horizontal-tab", "missing-space-before-default-role"]
1514 ENABLE_CHECKERS = ["default-role"]
1522 # sphinx-lint does not expose a public API so interaction is done via CLI
1524 … f"sphinx-lint -d {','.join(self.DISABLE_CHECKERS)} -e {','.join(self.ENABLE_CHECKERS)} {file}",
1533 for line in ex.output.decode("utf-8").splitlines():
1546 class KeepSorted(ComplianceTest):
1552 path_hint = "<git-top>"
1554 MARKER = "zephyr-keep-sorted"
1588 return -1
1599 start_marker = f"{self.MARKER}-start"
1600 stop_marker = f"{self.MARKER}-stop"
1627 desc = f"sorted block has out-of-order line at {start_line + idx}"
1642 class Ruff(ComplianceTest):
1648 path_hint = "<git-top>"
1657 f"ruff check --force-exclude --output-format=json {file}",
1665 output = ex.output.decode("utf-8")
1680 f"ruff format --force-exclude --diff {file}",
1690 class TextEncoding(ComplianceTest):
1692 Check that any text file is encoded in ascii or utf-8.
1696 path_hint = "<git-top>"
1698 ALLOWED_CHARSETS = ["us-ascii", "utf-8"]
1711 if mime_type.rsplit('=')[-1] not in self.ALLOWED_CHARSETS:
1724 console.setFormatter(logging.Formatter('%(levelname)-8s: %(message)s'))
1748 …https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#about-work…
1761 if hint == "<zephyr-base>":
1763 elif hint == "<git-top>":
1774 parser.add_argument('-c', '--commits', default=default_range,
1777 parser.add_argument('-o', '--output', default="compliance.xml",
1780 parser.add_argument('-n', '--no-case-output', action="store_true",
1782 parser.add_argument('-l', '--list', action="store_true",
1784 parser.add_argument("-v", "--loglevel", choices=['DEBUG', 'INFO', 'WARNING',
1787 parser.add_argument('-m', '--module', action="append", default=[],
1790 parser.add_argument('-e', '--exclude-module', action="append", default=[],
1793 parser.add_argument('-j', '--previous-run', default=None,
1794 help='''Pre-load JUnit results in XML format
1796 parser.add_argument('--annotate', action="store_true",
1797 help="Print GitHub Actions-compatible annotations.")
1815 # The absolute path of the top-level git directory. Initialize it here so
1818 GIT_TOP = git("rev-parse", "--show-toplevel")
1820 # The commit range passed in --commit, e.g. "HEAD~3"
1837 # (the script is currently run multiple times by the ci-pipelines
1857 # been --tests and --exclude-tests or the like, but it's awkward to
1928 # pylint: disable=unused-import
1949 # Formats the command-line arguments in the iterable 'cmd' into a string,