devops.cpp.ast.rule
Rule adapter exposing the AST-check engine through devops’s Rule interface.
Functions
|
Check one file against this worker's local ASTChecksRule. |
Classes
|
Run every enabled libclang AST-based check in a single pass. |
|
Picklable snapshot of ASTChecksRule's constructor args. |
- class devops.cpp.ast.rule.ASTWorkerSpec(compile_args, compile_commands_db, enabled_check_ids, disabled_check_ids, check_config)[source]
Bases:
objectPicklable snapshot of ASTChecksRule’s constructor args.
Sent to a ProcessPoolExecutor worker so it can build its own ASTChecksRule locally (fresh Check instances, its own clang.CompilationDatabase), since the rule instance itself holds unpicklable libclang/ctypes objects.
- Parameters:
- class devops.cpp.ast.rule.ASTChecksRule(compile_args=None, compile_commands_db=None, enabled_check_ids=None, disabled_check_ids=None, check_config=None)[source]
Bases:
RuleRun every enabled libclang AST-based check in a single pass.
Slots into build_cpp_rules as one ordinary FILE rule: each file is parsed once by libclang, and every enabled check in devops.cpp.ast.registry.ALL_CHECKS is dispatched against that single AST walk. All diagnostics found are combined into one ResultType.
- Parameters:
- check_file(path, content)[source]
Run all enabled AST checks against a single file’s content.
Public equivalent of _run, usable directly (without constructing a FileRuleInput) by callers like the process-pool worker in run_ast_checks_in_worker.
- Parameters:
path (Path) – The file being checked.
content (str) – The file’s full content.
- Returns:
ResultType – Same as _run.
- Return type:
- finalize_run()[source]
Call global_finalize() on every active check after all files are done.
- Returns:
bool – True if all checks passed, False if any check reported an error.
- Return type:
- worker_spec()[source]
Return a picklable spec that can rebuild an equivalent instance.
Used by devops.cpp.checks to run this rule’s checks across a ProcessPoolExecutor: the spec (not this instance, which holds unpicklable libclang objects) is sent to each worker, which calls ASTChecksRule.from_spec to build its own local instance.
- Returns:
ASTWorkerSpec – The constructor args this instance was built with.
- Return type:
- classmethod from_spec(spec)[source]
Build a fresh ASTChecksRule from a previously captured spec.
- Parameters:
spec (ASTWorkerSpec) – As returned by another instance’s worker_spec().
- Returns:
ASTChecksRule – A new, independently-constructed instance with the same configuration (fresh Check instances, its own clang.CompilationDatabase).
- Return type:
- devops.cpp.ast.rule.run_ast_checks_in_worker(path, content)[source]
Check one file against this worker’s local ASTChecksRule.
- Parameters:
path (Path) – The file to check.
content (str) – The file’s full content (read once by the main process and sent here, rather than re-read from disk in the worker).
- Returns:
tuple[ResultType, dict[str, dict]] – The check result, and a collect_state() snapshot of this worker’s checks for the main process to merge back after every file (state only grows, so merging the snapshot from every call, not just the last, is safe and gives the correct union across all workers).
- Return type:
tuple[ResultType, dict[str, dict]]