Hash the content of all input files to detect changes. Always includes each file path in the hash so that different sets of missing files produce distinct digests (avoiding false cache hits). Note: compiler args are NOT included in this hash. Meson/Ninja already tracks compiler fla
(files: list[Path])
| 179 | |
| 180 | |
| 181 | def hash_input_files(files: list[Path]) -> str: |
| 182 | """Hash the content of all input files to detect changes. |
| 183 | |
| 184 | Always includes each file path in the hash so that different sets of |
| 185 | missing files produce distinct digests (avoiding false cache hits). |
| 186 | |
| 187 | Note: compiler args are NOT included in this hash. Meson/Ninja already |
| 188 | tracks compiler flag changes via build.ninja regeneration. Including |
| 189 | args here caused a mismatch between compile_pch.py (which has args) |
| 190 | and invalidate_stale_pch (which doesn't), making the staleness check |
| 191 | always delete freshly-built PCH files. |
| 192 | """ |
| 193 | h = hashlib.sha256() |
| 194 | for f in sorted(str(p) for p in files): |
| 195 | p = Path(f) |
| 196 | h.update(f.encode("utf-8")) # Always include path in hash |
| 197 | if p.exists(): |
| 198 | h.update(b"\x01") # sentinel: file exists |
| 199 | with open(p, "rb") as fh: |
| 200 | for chunk in iter(lambda: fh.read(65536), b""): |
| 201 | h.update(chunk) |
| 202 | else: |
| 203 | h.update(b"\x00") # sentinel: file missing |
| 204 | return h.hexdigest() |
| 205 | |
| 206 | |
| 207 | def invalidate_stale_pch(pch_file: Path) -> None: |
no test coverage detected