Compute a hash over all header files' paths and mtimes. This acts as a "generation" marker: when any header changes, the hash changes, invalidating all cached IWYU results. Correctly handles transitive dependency changes. Args: header_files: All headers that IWYU will scan.
(header_files: list[Path])
| 35 | |
| 36 | |
| 37 | def compute_source_tree_hash(header_files: list[Path]) -> str: |
| 38 | """Compute a hash over all header files' paths and mtimes. |
| 39 | |
| 40 | This acts as a "generation" marker: when any header changes, |
| 41 | the hash changes, invalidating all cached IWYU results. |
| 42 | Correctly handles transitive dependency changes. |
| 43 | |
| 44 | Args: |
| 45 | header_files: All headers that IWYU will scan. |
| 46 | |
| 47 | Returns: |
| 48 | Hex digest string. |
| 49 | """ |
| 50 | hasher = hashlib.sha256() |
| 51 | for f in sorted(header_files, key=str): |
| 52 | hasher.update(str(f).encode("utf-8")) |
| 53 | try: |
| 54 | hasher.update(str(os.path.getmtime(str(f))).encode("utf-8")) |
| 55 | except OSError: |
| 56 | hasher.update(b"MISSING") |
| 57 | return hasher.hexdigest() |
| 58 | |
| 59 | |
| 60 | def _compute_file_hash( |
no test coverage detected