Find cache data for a module. Args: id: module ID path: module path manager: the build manager (for pyversion, log/trace, and build options) skip_validation: if True skip any validation steps (used for parallel checking) Returns: A CacheMeta/CacheMetaEx instan
(
id: str, path: str, manager: BuildManager, skip_validation: bool = False
)
| 1991 | |
| 1992 | |
| 1993 | def find_cache_meta( |
| 1994 | id: str, path: str, manager: BuildManager, skip_validation: bool = False |
| 1995 | ) -> tuple[CacheMeta, CacheMetaEx] | None: |
| 1996 | """Find cache data for a module. |
| 1997 | |
| 1998 | Args: |
| 1999 | id: module ID |
| 2000 | path: module path |
| 2001 | manager: the build manager (for pyversion, log/trace, and build options) |
| 2002 | skip_validation: if True skip any validation steps (used for parallel checking) |
| 2003 | |
| 2004 | Returns: |
| 2005 | A CacheMeta/CacheMetaEx instance pair if the cache data was found and appears |
| 2006 | valid; otherwise None. |
| 2007 | """ |
| 2008 | # TODO: May need to take more build options into account |
| 2009 | meta_file, data_file, _ = get_cache_names(id, path, manager.options) |
| 2010 | if manager.tracing_enabled: |
| 2011 | manager.trace(f"Looking for {id} at {meta_file}") |
| 2012 | if manager.stats_enabled: |
| 2013 | t0 = time.time() |
| 2014 | if manager.options.fixed_format_cache: |
| 2015 | meta = _load_ff_file( |
| 2016 | meta_file, manager, log_error_fmt="Could not load cache for {}: ", id=id |
| 2017 | ) |
| 2018 | else: |
| 2019 | meta = _load_json_file( |
| 2020 | meta_file, |
| 2021 | manager, |
| 2022 | log_success=f"Meta {id} ", |
| 2023 | log_error=f"Could not load cache for {id}: ", |
| 2024 | ) |
| 2025 | if meta is None: |
| 2026 | return None |
| 2027 | if manager.stats_enabled: |
| 2028 | t1 = time.time() |
| 2029 | if isinstance(meta, bytes): |
| 2030 | # If either low-level buffer format or high-level cache layout changed, we |
| 2031 | # cannot use the cache files, even with --skip-version-check. |
| 2032 | # TODO: switch to something like librt.internal.read_byte() if this is slow. |
| 2033 | if meta[0] != cache_version() or meta[1] != CACHE_VERSION: |
| 2034 | manager.log(f"Metadata abandoned for {id}: incompatible cache format") |
| 2035 | return None |
| 2036 | data_io = ReadBuffer(meta[2:]) |
| 2037 | m = CacheMeta.read(data_io, data_file) |
| 2038 | else: |
| 2039 | m = CacheMeta.deserialize(meta, data_file) |
| 2040 | if m is None: |
| 2041 | manager.log(f"Metadata abandoned for {id}: cannot deserialize data") |
| 2042 | return None |
| 2043 | if manager.stats_enabled: |
| 2044 | t2 = time.time() |
| 2045 | manager.add_stats( |
| 2046 | load_meta_time=t2 - t0, load_meta_load_time=t1 - t0, load_meta_from_dict_time=t2 - t1 |
| 2047 | ) |
| 2048 | if skip_validation: |
| 2049 | # If the caller requested no validation, skip the implementation part of the meta |
| 2050 | # as well, as a performance optimization. Note: this may return an incomplete meta, |
no test coverage detected
searching dependent graphs…