Lines Matching +full:- +full:- +full:short +full:- +full:build +full:- +full:path

5 # SPDX-License-Identifier: Apache-2.0
14 from pathlib import Path
34 sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
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)
79 if not os.path.isfile(os.path.join(GIT_TOP, file)):
124 The path the test runs itself in. This is just informative and used in
127 There are two magic strings that can be used instead of a path:
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
207 …doc = "See https://docs.zephyrproject.org/latest/contribute/guidelines.html#coding-style for more …
208 path_hint = "<git-top>"
211 checkpatch = os.path.join(ZEPHYR_BASE, 'scripts', 'checkpatch.pl')
212 if not os.path.exists(checkpatch):
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")
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}\".")
282 path = Path(ZEPHYR_BASE)
283 for file in path.glob("**/board.yml"):
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'}"
299 if Path(file).suffix not in ['.c', '.h']:
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,
334 doc = "See https://docs.zephyrproject.org/latest/build/dts/bindings.html for more details."
335 path_hint = "<zephyr-base>"
371 doc = "See https://docs.zephyrproject.org/latest/build/kconfig/tips.html for more details."
372 path_hint = "<zephyr-base>"
402 # not a module nor a pip-installed Python utility
403 zephyr_module_path = os.path.join(ZEPHYR_BASE, "scripts",
406 '--kconfig-out', modules_file, '--settings-out', settings_file]
411 self.error(ex.output.decode("utf-8"))
415 os.path.exists(os.path.join(modules_dir, name, 'Kconfig'))]
423 re.sub('[^a-zA-Z0-9]', '_', module).upper(),
434 # not a module nor a pip-installed Python utility
437 if os.path.exists(settings_file):
446 root_paths.append(Path(root_path.strip('"')))
457 # not a module nor a pip-installed Python utility
458 zephyr_drv_kconfig_path = os.path.join(ZEPHYR_BASE, "scripts", "dts",
461 binding_paths.append(os.path.join(ZEPHYR_BASE, "dts", "bindings"))
468 '--kconfig-out', kconfig_dts_file, '--bindings-dirs']
475 self.error(ex.output.decode("utf-8"))
488 # pylint: disable=undefined-variable
511 kconfig_file = os.path.join(kconfig_dir, 'boards', 'Kconfig')
512 kconfig_boards_file = os.path.join(kconfig_dir, 'boards', 'Kconfig.boards')
513 kconfig_defconfig_file = os.path.join(kconfig_dir, 'boards', 'Kconfig.defconfig')
516 board_roots.insert(0, Path(ZEPHYR_BASE))
518 soc_roots.insert(0, Path(ZEPHYR_BASE))
531 board_str = 'BOARD_' + re.sub(r"[^a-zA-Z0-9_]", "_", board.name).upper()
536 re.sub(r"[^a-zA-Z0-9_]", "_", qualifier)).upper()
546 'osource "' + (Path(kconfig_dir) / 'boards' / 'Kconfig.syms.v1').as_posix() + '"\n'
552 kconfig_defconfig_file = os.path.join(kconfig_dir, 'soc', 'Kconfig.defconfig')
553 kconfig_soc_file = os.path.join(kconfig_dir, 'soc', 'Kconfig.soc')
554 kconfig_file = os.path.join(kconfig_dir, 'soc', 'Kconfig')
562 fp.write('osource "' + (Path(folder) / 'Kconfig.defconfig').as_posix() + '"\n')
566 fp.write('source "' + (Path(folder) / 'Kconfig.soc').as_posix() + '"\n')
570 fp.write('source "' + (Path(folder) / 'Kconfig').as_posix() + '"\n')
572 kconfig_file = os.path.join(kconfig_dir, 'arch', 'Kconfig')
574 root_args = argparse.Namespace(**{'arch_roots': [Path(ZEPHYR_BASE)], 'arch': None})
579 fp.write('source "' + (Path(arch['path']) / 'Kconfig').as_posix() + '"\n')
586 # Put the Kconfiglib path first to make sure no local Kconfiglib version is
588 kconfig_path = os.path.join(ZEPHYR_BASE, "scripts", "kconfig")
589 if not os.path.exists(kconfig_path):
594 sys.path.insert(0, kconfig_path)
617 self.get_modules(os.path.join(kconfiglib_dir, "Kconfig.modules"),
618 os.path.join(kconfiglib_dir, "settings_file.txt"))
620 self.get_kconfig_dts(os.path.join(kconfiglib_dir, "Kconfig.dts"),
621 os.path.join(kconfiglib_dir, "settings_file.txt"))
624 kconfiglib_boards_dir = os.path.join(kconfiglib_dir, 'boards')
626 os.makedirs(os.path.join(kconfiglib_dir, 'soc'), exist_ok=True)
627 os.makedirs(os.path.join(kconfiglib_dir, 'arch'), exist_ok=True)
630 self.get_v2_model(kconfiglib_dir, os.path.join(kconfiglib_dir, "settings_file.txt"))
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)
751 if os.path.isabs(node.filename):
755 # pylint: disable=undefined-variable
778 # pylint: disable=undefined-variable
792 https://docs.zephyrproject.org/latest/build/kconfig/tips.html#menuconfig-symbols.
809 root_args = argparse.Namespace(**{'soc_roots': [Path(ZEPHYR_BASE)]})
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",
878 cwd=Path(GIT_TOP))
882 path, lineno, line = grep_line.split("\0")
890 not (sym_name.endswith("_MODULE") and sym_name[:-7] in defined_syms):
892 undef_to_locs[sym_name].append(f"{path}:{lineno}")
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
1056 doc = "See https://docs.zephyrproject.org/latest/build/kconfig/tips.html for more details."
1057 path_hint = "<zephyr-base>"
1069 doc = "See https://docs.zephyrproject.org/latest/build/kconfig/tips.html for more details."
1070 path_hint = "<zephyr-base>"
1080 This ensures the board and SoC trees are fully self-contained and reusable.
1088 kconfig_file = os.path.join(os.path.dirname(__file__), "Kconfig.board.v2")
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:
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)
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"))
1244 path_hint = "<git-top>"
1247 # Path to pylint configuration file
1248 pylintrc = os.path.abspath(os.path.join(os.path.dirname(__file__),
1251 # Path to additional pylint check scripts
1252 check_script_dir = os.path.abspath(os.path.join(os.path.dirname(__file__),
1272 pylintcmd = ["pylint", "--output-format=json2", "--rcfile=" + pylintrc,
1273 "--load-plugins=argparse-checker"] + py_files
1283 output = ex.output.decode("utf-8")
1291 self.fmtd_failure(severity, m['messageId'], m['path'],
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
1309 magic.from_file(os.path.join(root, fname),
1310 mime=True) == "text/x-python")]
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."
1371 path_hint = "<git-top>"
1378 for stat in git("diff", "--numstat", "--diff-filter=A",
1381 if added == "-" and deleted == "-":
1394 path_hint = "<git-top>"
1401 full_path = os.path.join(GIT_TOP, file)
1407 size = os.path.getsize(full_path)
1424 path_hint = "<git-top>"
1430 if not os.path.exists(file):
1444 path_hint = "<git-top>"
1453 if os.path.exists(file):
1479 path_hint = "<git-top>"
1482 config_file = os.path.join(ZEPHYR_BASE, ".yamllint")
1485 if Path(file).suffix not in ['.yaml', '.yml']:
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'])
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():
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}"
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}",
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"]
1704 full_path = os.path.join(GIT_TOP, file)
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.")
1810 ZEPHYR_BASE = str(Path(__file__).resolve().parents[2])
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"
1835 if not os.path.exists(args.previous_run):
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,