Check if fastled shared library content matches the saved fingerprint. If so, touch all DLL files whose content also matches the saved fingerprint, making their mtime newer than fastled shared library so ninja skips relinking them. This is called immediately after t
(self, build_dir: Path)
| 90 | self._saved = {} |
| 91 | |
| 92 | def touch_dlls_if_lib_unchanged(self, build_dir: Path) -> int: |
| 93 | """ |
| 94 | Check if fastled shared library content matches the saved fingerprint. |
| 95 | If so, touch all DLL files whose content also matches the saved fingerprint, |
| 96 | making their mtime newer than fastled shared library so ninja skips relinking them. |
| 97 | |
| 98 | This is called immediately after the "Linking static target fastled shared library" |
| 99 | line appears in ninja output - at that point fastled shared library has been freshly |
| 100 | archived and its content can be compared to the saved fingerprint. |
| 101 | |
| 102 | Returns: number of DLLs touched (had mtime updated) |
| 103 | """ |
| 104 | lib_path = build_dir / _LIBFASTLED_REL_PATH |
| 105 | if not lib_path.exists(): |
| 106 | return 0 |
| 107 | |
| 108 | saved_lib_hash = self._saved.get("libfastled_hash", "") |
| 109 | if not saved_lib_hash: |
| 110 | return 0 |
| 111 | |
| 112 | current_lib_hash = _hash_file(lib_path) |
| 113 | if not current_lib_hash or current_lib_hash != saved_lib_hash: |
| 114 | # Library content changed - let ninja relink normally |
| 115 | return 0 |
| 116 | |
| 117 | # Library content unchanged - touch DLLs whose content also matches |
| 118 | saved_dll_hashes: dict[str, str] = self._saved.get("dll_hashes", {}) |
| 119 | if not saved_dll_hashes: |
| 120 | return 0 |
| 121 | |
| 122 | now = time.time() |
| 123 | touched = 0 |
| 124 | |
| 125 | for dll_path in _find_dlls(build_dir): |
| 126 | dll_key = str(dll_path) |
| 127 | saved_hash = saved_dll_hashes.get(dll_key, "") |
| 128 | if not saved_hash: |
| 129 | continue |
| 130 | |
| 131 | current_hash = _hash_file(dll_path) |
| 132 | if current_hash and current_hash == saved_hash: |
| 133 | try: |
| 134 | # Update mtime to just after fastled shared library was archived |
| 135 | # so ninja sees the DLL as newer than its inputs |
| 136 | os.utime(str(dll_path), (now, now)) |
| 137 | touched += 1 |
| 138 | except OSError: |
| 139 | pass |
| 140 | |
| 141 | return touched |
| 142 | |
| 143 | def save_fingerprints(self, build_dir: Path) -> None: |
| 144 | """ |
no test coverage detected