Read and validate the fine-grained dependencies cache. See the write_deps_cache documentation for more information on the details of the cache. Returns None if the cache was invalid in some way.
(manager: BuildManager, graph: Graph)
| 1771 | |
| 1772 | |
| 1773 | def read_deps_cache(manager: BuildManager, graph: Graph) -> dict[str, FgDepMeta] | None: |
| 1774 | """Read and validate the fine-grained dependencies cache. |
| 1775 | |
| 1776 | See the write_deps_cache documentation for more information on |
| 1777 | the details of the cache. |
| 1778 | |
| 1779 | Returns None if the cache was invalid in some way. |
| 1780 | """ |
| 1781 | deps_meta = _load_json_file( |
| 1782 | DEPS_META_FILE, |
| 1783 | manager, |
| 1784 | log_success="Deps meta ", |
| 1785 | log_error="Could not load fine-grained dependency metadata: ", |
| 1786 | ) |
| 1787 | if deps_meta is None: |
| 1788 | return None |
| 1789 | meta_snapshot = deps_meta["snapshot"] |
| 1790 | # Take a snapshot of the source hashes from all the metas we found. |
| 1791 | # (Including the ones we rejected because they were out of date.) |
| 1792 | # We use this to verify that they match up with the proto_deps. |
| 1793 | current_meta_snapshot = { |
| 1794 | id: st.meta_source_hash for id, st in graph.items() if st.meta_source_hash is not None |
| 1795 | } |
| 1796 | |
| 1797 | common = set(meta_snapshot.keys()) & set(current_meta_snapshot.keys()) |
| 1798 | if any(meta_snapshot[id] != current_meta_snapshot[id] for id in common): |
| 1799 | # TODO: invalidate also if options changed (like --strict-optional)? |
| 1800 | manager.log("Fine-grained dependencies cache inconsistent, ignoring") |
| 1801 | return None |
| 1802 | |
| 1803 | module_deps_metas = deps_meta["deps_meta"] |
| 1804 | assert isinstance(module_deps_metas, dict) |
| 1805 | if not manager.options.skip_cache_mtime_checks: |
| 1806 | for meta in module_deps_metas.values(): |
| 1807 | try: |
| 1808 | matched = manager.getmtime(meta["path"]) == meta["mtime"] |
| 1809 | except FileNotFoundError: |
| 1810 | matched = False |
| 1811 | if not matched: |
| 1812 | manager.log(f"Invalid or missing fine-grained deps cache: {meta['path']}") |
| 1813 | return None |
| 1814 | |
| 1815 | return module_deps_metas |
| 1816 | |
| 1817 | |
| 1818 | def _load_ff_file( |
no test coverage detected
searching dependent graphs…