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

Function _load_introspect_tests_cache

ci/meson/test_discovery.py:22–55  ·  view source on GitHub ↗

Load cached test names from disk if the cache is still valid. The cache is stored in `` /.meson_introspect_tests_cache.json`` as a plain JSON array of test name strings (NOT the full meson introspect output). Storing only names keeps the file small (~6 KB vs ~180 KB),

(build_dir: Path)

Source from the content-addressed store, hash-verified

20
21
22def _load_introspect_tests_cache(build_dir: Path) -> list[str] | None:
23 """
24 Load cached test names from disk if the cache is still valid.
25
26 The cache is stored in ``<build_dir>/.meson_introspect_tests_cache.json``
27 as a plain JSON array of test name strings (NOT the full meson introspect
28 output). Storing only names keeps the file small (~6 KB vs ~180 KB),
29 reducing parse time from ~100 ms to ~5 ms.
30
31 The cache is considered valid when its mtime is at least as recent as
32 ``<build_dir>/build.ninja``. build.ninja is rewritten whenever meson
33 reconfigures (adding or removing tests), so its mtime is a reliable
34 invalidation signal for the registered test list.
35
36 Returns:
37 List of registered test name strings on cache hit, or None on miss/error.
38 """
39 cache_path = build_dir / ".meson_introspect_tests_cache.json"
40 build_ninja = build_dir / "build.ninja"
41 if not cache_path.exists() or not build_ninja.exists():
42 return None
43 try:
44 cache_mtime = cache_path.stat().st_mtime
45 ninja_mtime = build_ninja.stat().st_mtime
46 if cache_mtime < ninja_mtime:
47 return None # build.ninja is newer → cache is stale
48 data = json.loads(cache_path.read_text(encoding="utf-8"))
49 # Validate: must be a list of strings (names-only format)
50 if isinstance(data, list) and (not data or isinstance(data[0], str)):
51 return data
52 # Stale full-dict format from a previous version → treat as miss
53 return None
54 except (OSError, json.JSONDecodeError):
55 return None
56
57
58def _save_introspect_tests_cache(build_dir: Path, test_names: list[str]) -> None:

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected