Lines Matching +full:if +full:- +full:no +full:- +full:files +full:- +full:found

5 # SPDX-License-Identifier: Apache-2.0
44 # errors if 'ignore_non_zero' is set to False (default: False). 'cwd' is the
53 if not ignore_non_zero and (cp.returncode or cp.stderr):
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)
77 files = out.splitlines()
78 for file in list(files):
79 if not os.path.isfile(os.path.join(GIT_TOP, file)):
81 files.remove(file)
82 return files
96 description = f':{desc}' if desc else ''
100 (f'\nLine:{line}' if line else '') + \
101 (f'\nColumn:{col}' if col else '') + \
102 (f'\nEndLine:{end_line}' if end_line else '') + \
103 (f'\nEndColumn:{end_col}' if end_col else '')
104 msg = f'{file}' + (f':{line}' if line else '') + f' {msg_body}'
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
203 Runs checkpatch and reports found issues
207 …doc = "See https://docs.zephyrproject.org/latest/contribute/guidelines.html#coding-style for more …
208 path_hint = "<git-top>"
212 if not os.path.exists(checkpatch):
213 self.skip(f'{checkpatch} not found')
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")
235 if len(matches) > 500:
243 # If the regex has not matched add the whole output as a failure
244 if len(matches) == 0:
250 Check the board.yml files
254 path_hint = "<zephyr-base>"
260 if "vendor:" in line:
263 if vnd not in vendor_prefixes:
270 with open(os.path.join(ZEPHYR_BASE, "dts", "bindings", "vendor-prefixes.txt")) as fp:
273 if not line or line.startswith("#"):
279 self.error(f"Invalid line in vendor-prefixes.txt:\"{line}\".")
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,
331 Checks if we are introducing any unwanted properties in Devicetree Bindings.
335 path_hint = "<zephyr-base>"
345 Returns a list of dts/bindings/**/*.yaml files
350 if 'dts/bindings/' in file_name and file_name.endswith('.yaml'):
358 if 'required: false' in line:
372 path_hint = "<zephyr-base>"
385 if full:
396 if self.no_modules:
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"))
414 modules = [name for name in os.listdir(modules_dir) if
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):
444 if line.startswith(f'"{root}_ROOT":'):
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
498 if s.type != kconfiglib.UNKNOWN:
531 board_str = 'BOARD_' + re.sub(r"[^a-zA-Z0-9_]", "_", board.name).upper()
536 re.sub(r"[^a-zA-Z0-9_]", "_", qualifier)).upper()
583 Returns a kconfiglib.Kconfig object for the Kconfig files. We reuse
586 # Put the Kconfiglib path first to make sure no local Kconfiglib version is
589 if not os.path.exists(kconfig_path):
590 self.error(kconfig_path + " not found")
600 # Look up Kconfig files relative to ZEPHYR_BASE
633 # symbols within Kconfig files
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, "--",
683 # Returns a set() with the names of all defined Kconfig symbols (with no
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).
720 if node.prompt:
724 if n_top_items > max_top_items:
726 Expected no more than {max_top_items} potentially visible items (items with
727 prompts) in the top-level Kconfig menu, found {n_top_items} items. If you're
732 # Checks that no symbols are (re)defined in defconfigs.
736 # pylint: disable=undefined-variable
737 if "defconfig" in node.filename and (node.prompt or node.help):
738 name = (node.item.name if node.item not in
741 Kconfig node '{name}' found with prompt or help in {node.filename}.
742 Options must not be defined in defconfig files.
750 # skip Kconfig nodes not in-tree (will present an absolute path)
751 if os.path.isabs(node.filename):
755 # pylint: disable=undefined-variable
758 if (not isinstance(node.item, kconfiglib.Symbol) or
764 if re.match(r"^[Ee]nable.*", node.prompt[0]):
772 # Checks that there are no pointless 'menuconfig' symbols without
773 # children in the Kconfig files
778 # pylint: disable=undefined-variable
783 if node.is_menuconfig and not node.list and \
788 if bad_mconfs:
790 Found pointless 'menuconfig' symbols without children. Use regular 'config'
792 https://docs.zephyrproject.org/latest/build/kconfig/tips.html#menuconfig-symbols.
799 Checks that there are no references to undefined Kconfig symbols within
800 the Kconfig files
803 if "undefined symbol" in warning)
805 if undef_ref_warnings:
817 # pylint: disable=undefined-variable
818 if isinstance(node.item, kconfiglib.Symbol) and node.item.name == "SOC":
825 if name not in soc_kconfig_names:
826 soc_name_warnings.append(f"soc name: {name} not found in CONFIG_SOC defaults.")
828 if soc_name_warnings:
838 Checks that there are no references to undefined Kconfig symbols
839 outside Kconfig files (any CONFIG_FOO where no FOO symbol exists)
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",
888 if sym_name not in defined_syms and \
890 not (sym_name.endswith("_MODULE") and sym_name[:-7] in defined_syms):
894 if not undef_to_locs:
907 Found references to undefined Kconfig symbols. If any of these are false
910 If the reference is for a comment like /* CONFIG_FOO_* */ (or
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
989 "LLVM_USE_LLD", # which are only included if LLVM is selected but
991 # for example, if you are using GCC.
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
1050 Checks if we are introducing any new warnings/errors with Kconfig,
1057 path_hint = "<zephyr-base>"
1064 Checks if we are introducing any new warnings/errors with Kconfig when no
1070 path_hint = "<zephyr-base>"
1080 This ensures the board and SoC trees are fully self-contained and reusable.
1094 Checks various nits in added/modified files. Doesn't check stuff that's
1098 …doc = "See https://docs.zephyrproject.org/latest/contribute/guidelines.html#coding-style for more …
1099 path_hint = "<git-top>"
1102 # Loop through added/modified files
1104 if "Kconfig" in fname:
1108 if fname.startswith("dts/bindings/"):
1111 if fname.endswith((".c", ".conf", ".cpp", ".dts", ".overlay",
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:
1155 if match:
1164 with open(os.path.join(GIT_TOP, fname), encoding="utf-8") as f:
1165 if re.search(r"^\.\.\.", f.read(), re.MULTILINE):
1167 Redundant '...' document separator in {fname}. Binding YAML files are never
1168 concatenated together, so no document separators are needed.""")
1171 # Generic nits related to various source files
1173 with open(os.path.join(GIT_TOP, fname), encoding="utf-8") as f:
1176 if not contents.endswith("\n"):
1180 if contents.startswith("\n"):
1183 if contents.endswith("\n\n"):
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)
1210 if len(offending_lines) > 0:
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"))
1239 Runs pylint on all .py files, with a limited set of checks enabled. The
1244 path_hint = "<git-top>"
1255 # List of files added/modified by the commit(s).
1256 files = get_files(filter="d")
1258 # Filter out everything but Python files. Keep filenames
1261 py_files = filter_py(GIT_TOP, files)
1262 if not py_files:
1266 if "PYTHONPATH" in python_environment:
1272 pylintcmd = ["pylint", "--output-format=json2", "--rcfile=" + pylintrc,
1273 "--load-plugins=argparse-checker"] + py_files
1283 output = ex.output.decode("utf-8")
1287 if m['messageId'][0] in ('F', 'E'):
1295 if len(messages) == 0:
1296 # If there are no specific messages add the whole output as a failure
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
1308 if (fname.endswith(".py") or
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)
1332 if match:
1335 if match:
1338 match = re.search(r"signed-off-by:\s(.*)", line, re.IGNORECASE)
1339 if match:
1343 f"the signed-off-by entries."
1349 if author not in signed:
1352 if not parsed_addr or len(parsed_addr[0].split(" ")) < 2:
1353 if not failure:
1361 if failure:
1367 Check that the diff contains no binary files.
1370 doc = "No binary files allowed."
1371 path_hint = "<git-top>"
1375 # svg files are always detected as binary, see .gitattributes
1378 for stat in git("diff", "--numstat", "--diff-filter=A",
1381 if added == "-" and deleted == "-":
1382 if (fname.startswith(BINARY_ALLOW_PATHS) and
1393 doc = "Check the size of image files."
1394 path_hint = "<git-top>"
1404 if not mime_type.startswith("image/"):
1410 if file.startswith("boards/"):
1413 if size > limit:
1424 path_hint = "<git-top>"
1430 if not os.path.exists(file):
1444 path_hint = "<git-top>"
1453 if os.path.exists(file):
1456 if not maintainers_file:
1462 if not manifest.is_active(project):
1465 if isinstance(project, ManifestProject):
1469 if area not in maintainers.areas:
1478 doc = "Check YAML files with YAMLLint."
1479 path_hint = "<git-top>"
1485 if Path(file).suffix not in ['.yaml', '.yml']:
1490 if file.startswith(".github/"):
1491 # Tweak few rules for workflow files.
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"]
1518 if not file.endswith(".rst"):
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():
1536 if match:
1552 path_hint = "<git-top>"
1554 MARKER = "zephyr-keep-sorted"
1560 if regex is None:
1567 if not line.strip():
1571 if regex:
1573 if not re.match(regex, line):
1576 if _test_indent(line):
1583 if line < last:
1588 return -1
1593 if not mime_type.startswith("text/"):
1599 start_marker = f"{self.MARKER}-start"
1600 stop_marker = f"{self.MARKER}-stop"
1606 if start_marker in line:
1607 if in_block:
1617 regex = match.group(1) if match else None
1619 if not in_block:
1626 if idx >= 0:
1627 desc = f"sorted block has out-of-order line at {start_line + idx}"
1633 if in_block:
1647 doc = "Check python files with ruff."
1648 path_hint = "<git-top>"
1652 if not file.endswith(".py"):
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.
1695 doc = "Check the encoding of text files."
1696 path_hint = "<git-top>"
1698 ALLOWED_CHARSETS = ["us-ascii", "utf-8"]
1707 if not mime_type.startswith("text/"):
1711 if mime_type.rsplit('=')[-1] not in self.ALLOWED_CHARSETS:
1724 console.setFormatter(logging.Formatter('%(levelname)-8s: %(message)s'))
1740 if child not in subclasses:
1748 …https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#about-work…
1752 (f',line={res.line}' if res.line else '') + \
1753 (f',col={res.col}' if res.col else '') + \
1754 (f',endLine={res.end_line}' if res.end_line else '') + \
1755 (f',endColumn={res.end_col}' if res.end_col else '') + \
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.")
1807 if not ZEPHYR_BASE:
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"
1828 if args.list:
1833 # Load saved test results from an earlier run, if requested
1834 if args.previous_run:
1835 if not os.path.exists(args.previous_run):
1837 # (the script is currently run multiple times by the ci-pipelines
1841 print(f"error: '{args.previous_run}' not found",
1857 # been --tests and --exclude-tests or the like, but it's awkward to
1860 if included and testcase.name.lower() not in included:
1863 if testcase.name.lower() in excluded:
1875 # Annotate if required
1876 if args.annotate:
1882 if args.output:
1893 if case.result:
1894 if case.is_skipped:
1899 # Some checks can produce no .result
1900 logging.info(f"No JUnit result for {case.name}")
1904 if n_fails:
1910 if args.no_case_output:
1919 if args.output:
1928 # pylint: disable=unused-import
1949 # Formats the command-line arguments in the iterable 'cmd' into a string,
1956 cmd = sys.argv[0] # Empty if missing
1957 if cmd:
1962 if __name__ == "__main__":