devops.cpp.checks

C++ checks module.

Functions

run_cpp_checks(rules[, config, dirs, ...])

Run C++ checks based on the provided rules.

run_cpp_only_include_precheck(config)

Hard pre-check: scan every header in the project for cpp-only violations.

run_file_rules(rules, file[, content])

Run file-based C++ checks on a given file.

run_line_checks(rules, file[, content])

Run line-based C++ checks on a given file.

Exceptions

CppCheckError

Custom exception for C++ check errors.

exception devops.cpp.checks.CppCheckError[source]

Bases: Exception

Custom exception for C++ check errors.

devops.cpp.checks.run_line_checks(rules, file, content=None)[source]

Run line-based C++ checks on a given file.

Parameters:
  • rules (list[Rule]) – The list of rules to apply.

  • file (Path) – The file to check.

  • content (str | None) – The file’s full content, if already read by the caller. When None (the default), the file is read from disk.

Returns:

list[ResultType] – The list of results from the checks.

Raises:

CppCheckError – If a non-line rule is provided.

Return type:

list[ResultType]

devops.cpp.checks.run_file_rules(rules, file, content=None)[source]

Run file-based C++ checks on a given file.

Parameters:
  • rules (list[Rule]) – The list of rules to apply.

  • file (Path) – The file to check.

  • content (str | None) – The file’s full content, if already read by the caller. When None (the default), the file is read from disk.

Returns:

list[ResultType] – The list of results from the checks.

Raises:

CppCheckError – If a non-file rule is provided.

Return type:

list[ResultType]

devops.cpp.checks.run_cpp_only_include_precheck(config)[source]

Hard pre-check: scan every header in the project for cpp-only violations.

This is a text/regex scan (see devops.cpp.cpp_only_include_scan), not the libclang-based enforceCppOnlyInclude AST check, and it always covers the entire repository (_collect_all_header_files) rather than whatever subset of files a given invocation happens to be scoped to. That makes it independent of incremental caching, any git-diff-based file selection (--base-ref, check_only_staged_files), and even config.check_dirs itself: a violation sitting in a header that wasn’t touched in the current diff, was already marked “passed” by the incremental state file, or simply lives outside the configured check_dirs, is still caught every single run.

Honors config.fail_fast the same way the rest of the pipeline does: when set (the default), scanning stops at the first file with a violation instead of walking every remaining header.

Parameters:

config (CppConfig) – The global C++ configuration. Reads the same [cpp.ast_check_config.enforceCppOnlyInclude] block as the AST check.

Returns:

bool – True if no violations were found (including when the check is disabled or unconfigured), False otherwise.

Return type:

bool

devops.cpp.checks.run_cpp_checks(rules, config=CppConfig(style_checks=True, license_header_check=True, license_header=None, check_only_staged_files=False, check_dirs=[], exclude_dirs=[], header_guards_according_to_filepath=False, header_guard_pattern=None, ast_checks=True, ast_check_compile_args=['-std=c++23'], ast_check_compile_commands_db=None, ast_check_enabled_ids=[], ast_check_disabled_ids=[], ast_check_config={}, forbidden_spellings={}, incremental_state_file=None, fail_fast=True, parallel_jobs=1), dirs=None, state_file=None, base_ref=None, config_file=None)[source]

Run C++ checks based on the provided rules.

By default the function returns immediately after encountering the first file with errors (fail-fast). Set config.fail_fast = False (or pass --no-fail-fast on the CLI) to check all files regardless.

When state_file is given the run is incremental: results are persisted to state_file after every checked file, and only files that are new, previously failed, or modified since the last run are re-checked. The return value is False whenever any entry in the accumulated state is failed. The state is discarded whenever config_file changed since it was written.

When config.parallel_jobs != 1 and an AST-checks rule is present, the libclang parse (the one CPU-bound, per-file cost) is dispatched across a process pool instead of running serially; every other rule (line/file/style rules) still runs once per file in the main process, since that work is cheap. With parallel_jobs > 1 and fail_fast enabled, the run stops scheduling further files soon after a failure is seen, rather than at the exact first failing file in listing order.

Parameters:
  • rules (list[Rule]) – The list of rules to apply.

  • config (CppConfig) – The global C++ configuration.

  • dirs (list[Path] | None) – If given, only files under these directories are checked.

  • state_file (Path | None) – Path to the JSON state file used for incremental runs. When None (the default) no state is read or written and the classic fail-fast behavior is used.

  • base_ref (str | None) – A git commit hash or branch name. When given, only files changed relative to it (see get_changed_files) are checked, overriding check_only_staged_files. The changed files are still further restricted to config.check_dirs (if set) and, when given, to dirs, which takes precedence over config.check_dirs.

  • config_file (Path | None) – The TOML config file in use. Its content hash is stored in the state file; when it differs on the next run, all incremental state is invalidated and every file is re-checked.

Raises:
  • CppCheckError – If invalid (non-file or non-line) rules are provided.

  • GitRefError – If base_ref cannot be resolved.

Returns:

bool – True if all checks pass, False if any check fails.

Return type:

bool