ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
suppression_hardware_todo.py
Go to the documentation of this file.
1# SPDX-License-Identifier: MIT
2# Copyright (c) 2026 Brighton Sikarskie
3"""Semantic inventory for named-hardware waivers on canned silent stubs."""
4
5from __future__ import annotations
6
7from pathlib import Path
8
9from check_no_silent_stubs import CANNED_ERRORS, EXCLUDED, ROOTS, real_definitions, scan_text
10from suppression_catalog import ownership
11from suppression_model import Finding, Suppression
12
13
14def scan_hardware_todo_controls(
15 root: Path, paths: list[str]
16) -> tuple[list[Suppression], list[Finding]]:
17 """Bind TODO hardware names only to real CANNED candidates, never SHADOW."""
18 rels = [
19 rel
20 for rel in paths
21 if rel.endswith(".c")
22 and rel.startswith(tuple(f"{prefix}/" for prefix in ROOTS))
23 and not rel.startswith(EXCLUDED)
24 and ownership(rel) == "first-party"
25 ]
26 pairs = [(rel, root / rel) for rel in rels if (root / rel).is_file()]
27 files = [item[1] for item in pairs]
28 definitions = real_definitions(files)
29 records: list[Suppression] = []
30 for rel, file_path in pairs:
31 for candidate in scan_text(file_path.read_text(errors="replace"), rel):
32 if candidate["returns"] not in CANNED_ERRORS or not candidate["waiver"]:
33 continue
34 shadowed = [
35 item
36 for item in definitions.get(candidate["name"], [])
37 if item["path"] != rel and not item["internal"] and not candidate["internal"]
38 ]
39 if shadowed:
40 continue
41 reason = str(candidate["waiver"])
42 records.append(
43 Suppression(
44 rel,
45 int(candidate["line"]),
46 1,
47 "project-policy",
48 "check-no-silent-stubs",
49 "hardware-blocked-canned-stub",
50 "TODO(named-hardware)",
51 f"function:{candidate['name']}",
52 reason,
53 "semantic-function-binding",
54 ownership(rel),
55 (),
56 )
57 )
58 return records, []