Checks whether the cached AST of this module can be used. Returns: None, if the cached AST is unusable. Original meta, if mtime/size matched. Meta with mtime updated to match source file, if hash/size matched but mtime/path didn't.
(
meta: CacheMeta | None, id: str, path: str | None, ignore_all: bool, manager: BuildManager
)
| 2124 | |
| 2125 | |
| 2126 | def validate_meta( |
| 2127 | meta: CacheMeta | None, id: str, path: str | None, ignore_all: bool, manager: BuildManager |
| 2128 | ) -> CacheMeta | None: |
| 2129 | """Checks whether the cached AST of this module can be used. |
| 2130 | |
| 2131 | Returns: |
| 2132 | None, if the cached AST is unusable. |
| 2133 | Original meta, if mtime/size matched. |
| 2134 | Meta with mtime updated to match source file, if hash/size matched but mtime/path didn't. |
| 2135 | """ |
| 2136 | # This requires two steps. The first one is obvious: we check that the module source file |
| 2137 | # contents is the same as it was when the cache data file was created. The second one is not |
| 2138 | # too obvious: we check that the cache data file mtime has not changed; it is needed because |
| 2139 | # we use cache data file mtime to propagate information about changes in the dependencies. |
| 2140 | |
| 2141 | if meta is None: |
| 2142 | manager.log(f"Metadata not found for {id}") |
| 2143 | return None |
| 2144 | |
| 2145 | if meta.ignore_all and not ignore_all: |
| 2146 | manager.log(f"Metadata abandoned for {id}: errors were previously ignored") |
| 2147 | return None |
| 2148 | |
| 2149 | if manager.stats_enabled: |
| 2150 | t0 = time.time() |
| 2151 | bazel = manager.options.bazel |
| 2152 | assert path is not None, "Internal error: meta was provided without a path" |
| 2153 | if not manager.options.skip_cache_mtime_checks: |
| 2154 | # Check data_file; assume if its mtime matches it's good. |
| 2155 | try: |
| 2156 | data_mtime = manager.getmtime(meta.data_file) |
| 2157 | except OSError: |
| 2158 | manager.log(f"Metadata abandoned for {id}: failed to stat data_file") |
| 2159 | return None |
| 2160 | if data_mtime != meta.data_mtime: |
| 2161 | manager.log(f"Metadata abandoned for {id}: data cache is modified") |
| 2162 | return None |
| 2163 | |
| 2164 | if bazel: |
| 2165 | # Normalize path under bazel to make sure it isn't absolute |
| 2166 | path = normpath(path, manager.options) |
| 2167 | |
| 2168 | st = manager.get_stat(path) |
| 2169 | if st is None: |
| 2170 | return None |
| 2171 | if not stat.S_ISDIR(st.st_mode) and not stat.S_ISREG(st.st_mode): |
| 2172 | manager.log(f"Metadata abandoned for {id}: file or directory {path} does not exist") |
| 2173 | return None |
| 2174 | |
| 2175 | if manager.stats_enabled: |
| 2176 | manager.add_stats(validate_stat_time=time.time() - t0) |
| 2177 | |
| 2178 | # When we are using a fine-grained cache, we want our initial |
| 2179 | # build() to load all of the cache information and then do a |
| 2180 | # fine-grained incremental update to catch anything that has |
| 2181 | # changed since the cache was generated. We *don't* want to do a |
| 2182 | # coarse-grained incremental rebuild, so we accept the cache |
| 2183 | # metadata even if it doesn't match the source file. |
no test coverage detected
searching dependent graphs…