Run IWYU on a single header and return (rel_path, removals). Returns ("", []) when there are no real violations.
(file_path_str: str)
| 89 | |
| 90 | |
| 91 | def _scan_one_header(file_path_str: str) -> tuple[str, list[str]]: |
| 92 | """Run IWYU on a single header and return (rel_path, removals). |
| 93 | |
| 94 | Returns ("", []) when there are no real violations. |
| 95 | """ |
| 96 | f = Path(file_path_str) |
| 97 | iwyu_cmd = [ |
| 98 | sys.executable, |
| 99 | str(_PROJECT_ROOT / "ci" / "iwyu_wrapper.py"), |
| 100 | "-Xiwyu", |
| 101 | "--error", |
| 102 | "--", |
| 103 | "clang-tool-chain-cpp", |
| 104 | "-std=gnu++11", |
| 105 | "-DSTUB_PLATFORM", |
| 106 | "-DARDUINO=10808", |
| 107 | "-DFASTLED_USE_STUB_ARDUINO", |
| 108 | "-DFASTLED_STUB_IMPL", |
| 109 | "-DFASTLED_TESTING", |
| 110 | "-DFASTLED_UNIT_TEST=1", |
| 111 | f"-I{_PROJECT_ROOT / 'src'}", |
| 112 | f"-I{_PROJECT_ROOT / 'src' / 'platforms' / 'stub'}", |
| 113 | "-x", |
| 114 | "c++-header", |
| 115 | "-c", |
| 116 | str(f), |
| 117 | ] |
| 118 | try: |
| 119 | result = subprocess.run(iwyu_cmd, capture_output=True, text=True, timeout=30) |
| 120 | except subprocess.TimeoutExpired: |
| 121 | return ("", []) |
| 122 | |
| 123 | if result.returncode == 0: |
| 124 | return ("", []) |
| 125 | |
| 126 | removals: list[str] = [] |
| 127 | in_remove = False |
| 128 | for line in result.stderr.split("\n"): |
| 129 | if "should remove" in line: |
| 130 | in_remove = True |
| 131 | continue |
| 132 | if "The full include-list" in line or "should add" in line: |
| 133 | in_remove = False |
| 134 | continue |
| 135 | if in_remove and line.startswith("- "): |
| 136 | removal = line[2:].strip() |
| 137 | line_num = _extract_line_number(removal) |
| 138 | if line_num is not None and not _line_has_real_violation(f, line_num): |
| 139 | continue # Phantom violation — skip |
| 140 | removals.append(removal) |
| 141 | |
| 142 | if removals: |
| 143 | rel = str(f.relative_to(_PROJECT_ROOT)).replace("\\", "/") |
| 144 | return (rel, removals) |
| 145 | return ("", []) |
| 146 | |
| 147 | |
| 148 | # --------------------------------------------------------------------------- |
nothing calls this directly
no test coverage detected