MCPcopy Create free account
hub / github.com/FastLED/FastLED / scan_single_file

Function scan_single_file

ci/ci-iwyu.py:153–229  ·  view source on GitHub ↗

Scan a single C++ file for IWYU violations. Args: file_path: Path to the file to scan. Returns: (rel_path, removals) — empty rel_path if no violations.

(file_path: str)

Source from the content-addressed store, hash-verified

151
152
153def scan_single_file(file_path: str) -> tuple[str, list[str]]:
154 """Scan a single C++ file for IWYU violations.
155
156 Args:
157 file_path: Path to the file to scan.
158
159 Returns:
160 (rel_path, removals) — empty rel_path if no violations.
161 """
162 f = Path(file_path).resolve()
163 project_root = _PROJECT_ROOT
164
165 is_header = f.suffix in (".h", ".hpp", ".hh", ".hxx")
166 is_test = False
167 try:
168 f.relative_to(project_root / "tests")
169 is_test = True
170 except ValueError:
171 pass
172
173 compiler_args = [
174 "clang-tool-chain-cpp",
175 "-std=gnu++11",
176 "-DSTUB_PLATFORM",
177 "-DARDUINO=10808",
178 "-DFASTLED_USE_STUB_ARDUINO",
179 "-DFASTLED_STUB_IMPL",
180 "-DFASTLED_TESTING",
181 "-DFASTLED_UNIT_TEST=1",
182 f"-I{project_root / 'src'}",
183 f"-I{project_root / 'src' / 'platforms' / 'stub'}",
184 ]
185 if is_test:
186 compiler_args.append(f"-I{project_root / 'tests'}")
187 if is_header:
188 compiler_args.extend(["-x", "c++-header"])
189 compiler_args.extend(["-c", str(f)])
190
191 iwyu_cmd = [
192 sys.executable,
193 str(project_root / "ci" / "iwyu_wrapper.py"),
194 "-Xiwyu",
195 "--error",
196 "--",
197 ] + compiler_args
198
199 try:
200 result = subprocess.run(iwyu_cmd, capture_output=True, text=True, timeout=60)
201 except subprocess.TimeoutExpired:
202 return ("", [])
203
204 if result.returncode == 0:
205 return ("", [])
206
207 removals: list[str] = []
208 in_remove = False
209 for line in result.stderr.split("\n"):
210 if "should remove" in line:

Callers 1

mainFunction · 0.85

Calls 5

_extract_line_numberFunction · 0.85
_line_has_real_violationFunction · 0.85
resolveMethod · 0.45
appendMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected