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

Function _compute_src_fingerprint

ci/wasm_build.py:129–180  ·  view source on GitHub ↗

Fast fingerprint of source tree based on file mtimes. Uses os.scandir (3x faster than os.walk on Windows — DirEntry.stat() reuses data from FindFirstFile, avoiding extra syscalls). Caches the result within the same process invocation (cleared after 0.5s).

()

Source from the content-addressed store, hash-verified

127
128
129def _compute_src_fingerprint() -> str:
130 """Fast fingerprint of source tree based on file mtimes.
131
132 Uses os.scandir (3x faster than os.walk on Windows — DirEntry.stat()
133 reuses data from FindFirstFile, avoiding extra syscalls).
134 Caches the result within the same process invocation (cleared after 0.5s).
135 """
136 global _cached_fingerprint, _cached_fingerprint_time
137 now = time.monotonic()
138 if _cached_fingerprint is not None and (now - _cached_fingerprint_time) < 0.5:
139 return _cached_fingerprint
140
141 h = hashlib.md5(usedforsecurity=False)
142 src_dir = str(PROJECT_ROOT / "src")
143 _EXTS = (".cpp", ".h", ".hpp", ".c")
144
145 # Recursive scandir — on Windows, DirEntry.stat() is free (no extra syscall)
146 def _scan(path: str) -> None:
147 try:
148 entries = sorted(os.scandir(path), key=lambda e: e.name)
149 except OSError:
150 return
151 subdirs: list[str] = []
152 for entry in entries:
153 if entry.is_dir(follow_symlinks=False):
154 subdirs.append(entry.path)
155 elif entry.is_file(follow_symlinks=False) and entry.name.endswith(_EXTS):
156 try:
157 st = entry.stat()
158 h.update(f"{entry.path}:{st.st_mtime:.6f}".encode())
159 except OSError:
160 h.update(f"{entry.path}:MISSING".encode())
161 for d in subdirs:
162 _scan(d)
163
164 _scan(src_dir)
165
166 # Also hash build config files that affect the library
167 for config_file in [
168 PROJECT_ROOT / "src" / "platforms" / "wasm" / "compiler" / "build_flags.toml",
169 PROJECT_ROOT / "meson.build",
170 PROJECT_ROOT / "ci" / "meson" / "wasm" / "meson.build",
171 PROJECT_ROOT / "ci" / "meson" / "wasm_cross_file.ini",
172 ]:
173 try:
174 h.update(f"{config_file}:{config_file.stat().st_mtime:.6f}".encode())
175 except OSError:
176 h.update(f"{config_file}:MISSING".encode())
177
178 _cached_fingerprint = h.hexdigest()
179 _cached_fingerprint_time = now
180 return _cached_fingerprint
181
182
183def _iter_js_affecting_files() -> list[Path]:

Callers 3

_library_is_freshFunction · 0.85
build_sketch_pchFunction · 0.85

Calls 2

_scanFunction · 0.85
updateMethod · 0.45

Tested by

no test coverage detected