Write cache files for fine-grained dependencies. Serialize fine-grained dependencies map for fine-grained mode. Dependencies on some module 'm' is stored in the dependency cache file m.deps.json. This entails some spooky action at a distance: if module 'n' depends on 'm', that pro
(
rdeps: dict[str, dict[str, set[str]]], manager: BuildManager, graph: Graph
)
| 1601 | |
| 1602 | |
| 1603 | def write_deps_cache( |
| 1604 | rdeps: dict[str, dict[str, set[str]]], manager: BuildManager, graph: Graph |
| 1605 | ) -> None: |
| 1606 | """Write cache files for fine-grained dependencies. |
| 1607 | |
| 1608 | Serialize fine-grained dependencies map for fine-grained mode. |
| 1609 | |
| 1610 | Dependencies on some module 'm' is stored in the dependency cache |
| 1611 | file m.deps.json. This entails some spooky action at a distance: |
| 1612 | if module 'n' depends on 'm', that produces entries in m.deps.json. |
| 1613 | When there is a dependency on a module that does not exist in the |
| 1614 | build, it is stored with its first existing parent module. If no |
| 1615 | such module exists, it is stored with the fake module FAKE_ROOT_MODULE. |
| 1616 | |
| 1617 | This means that the validity of the fine-grained dependency caches |
| 1618 | are a global property, so we store validity checking information for |
| 1619 | fine-grained dependencies in a global cache file: |
| 1620 | * We take a snapshot of current sources to later check consistency |
| 1621 | between the fine-grained dependency cache and module cache metadata |
| 1622 | * We store the mtime of all the dependency files to verify they |
| 1623 | haven't changed |
| 1624 | """ |
| 1625 | metastore = manager.metastore |
| 1626 | |
| 1627 | error = False |
| 1628 | |
| 1629 | fg_deps_meta = manager.fg_deps_meta.copy() |
| 1630 | |
| 1631 | for id in rdeps: |
| 1632 | if id != FAKE_ROOT_MODULE: |
| 1633 | _, _, deps_json = get_cache_names(id, graph[id].xpath, manager.options) |
| 1634 | else: |
| 1635 | deps_json = DEPS_ROOT_FILE |
| 1636 | assert deps_json |
| 1637 | manager.log("Writing deps cache", deps_json) |
| 1638 | if not manager.metastore.write(deps_json, deps_to_json(rdeps[id])): |
| 1639 | manager.log(f"Error writing fine-grained deps JSON file {deps_json}") |
| 1640 | error = True |
| 1641 | else: |
| 1642 | fg_deps_meta[id] = {"path": deps_json, "mtime": manager.getmtime(deps_json)} |
| 1643 | |
| 1644 | meta_snapshot: dict[str, str] = {} |
| 1645 | for id, st in graph.items(): |
| 1646 | # If we didn't parse a file (so it doesn't have a |
| 1647 | # source_hash), then it must be a module with a fresh cache, |
| 1648 | # so use the hash from that. |
| 1649 | if st.source_hash: |
| 1650 | hash = st.source_hash |
| 1651 | else: |
| 1652 | if st.meta: |
| 1653 | hash = st.meta.hash |
| 1654 | else: |
| 1655 | hash = "" |
| 1656 | meta_snapshot[id] = hash |
| 1657 | |
| 1658 | meta = {"snapshot": meta_snapshot, "deps_meta": fg_deps_meta} |
| 1659 | |
| 1660 | if not metastore.write(DEPS_META_FILE, json_dumps(meta)): |
no test coverage detected
searching dependent graphs…