Return the list of source files in ``compile_db`` under `` /src/``. Filters out third-party / framework TUs so we only analyze FastLED's own code, matching the legacy ``pio check --src-filters=+ `` scope. Per the `JSON Compilation Database spec <https://clang.llvm
(compile_db: Path, project_root: Path)
| 103 | |
| 104 | |
| 105 | def _load_src_files_from_compile_db(compile_db: Path, project_root: Path) -> list[str]: |
| 106 | """Return the list of source files in ``compile_db`` under ``<project_root>/src/``. |
| 107 | |
| 108 | Filters out third-party / framework TUs so we only analyze FastLED's own |
| 109 | code, matching the legacy ``pio check --src-filters=+<src/>`` scope. |
| 110 | |
| 111 | Per the `JSON Compilation Database spec |
| 112 | <https://clang.llvm.org/docs/JSONCompilationDatabase.html>`_, the |
| 113 | ``file`` field may be absolute OR relative to the entry's ``directory`` |
| 114 | field (which itself is absolute). Resolve relatives against |
| 115 | ``directory`` (falling back to ``compile_db.parent`` when ``directory`` |
| 116 | is missing) rather than against the Python CWD — otherwise fbuild |
| 117 | emitting a single relative path would silently drop its TU from the |
| 118 | analysis set. |
| 119 | """ |
| 120 | src_root = (project_root / "src").resolve() |
| 121 | with compile_db.open("r", encoding="utf-8") as fh: |
| 122 | entries = json.load(fh) |
| 123 | files: list[str] = [] |
| 124 | for entry in entries: |
| 125 | raw = entry.get("file") |
| 126 | if not raw: |
| 127 | continue |
| 128 | raw_path = Path(raw) |
| 129 | if not raw_path.is_absolute(): |
| 130 | directory = entry.get("directory") or compile_db.parent |
| 131 | raw_path = Path(directory) / raw_path |
| 132 | try: |
| 133 | resolved = raw_path.resolve() |
| 134 | except OSError: |
| 135 | continue |
| 136 | try: |
| 137 | resolved.relative_to(src_root) |
| 138 | except ValueError: |
| 139 | continue |
| 140 | files.append(str(resolved)) |
| 141 | return files |
| 142 | |
| 143 | |
| 144 | def run_static_analysis_against_compile_db(compile_db: Path, project_root: Path) -> int: |