@@ -80,6 +80,7 @@ class BuildResult:
80
80
manager: The build manager.
81
81
files: Dictionary from module name to related AST node.
82
82
types: Dictionary from parse tree node to its inferred type.
83
+ used_cache: Whether the build took advantage of a cache
83
84
errors: List of error messages.
84
85
"""
85
86
@@ -88,6 +89,7 @@ def __init__(self, manager: 'BuildManager', graph: Graph) -> None:
88
89
self .graph = graph
89
90
self .files = manager .modules
90
91
self .types = manager .all_types # Non-empty for tests only or if dumping deps
92
+ self .used_cache = manager .cache_enabled
91
93
self .errors = [] # type: List[str] # Filled in by build if desired
92
94
93
95
@@ -569,6 +571,7 @@ class BuildManager:
569
571
flush_errors: A function for processing errors after each SCC
570
572
saved_cache: Dict with saved cache state for coarse-grained dmypy
571
573
(read-write!)
574
+ cache_enabled: Whether cache usage is enabled
572
575
stats: Dict with various instrumentation numbers
573
576
"""
574
577
@@ -606,9 +609,13 @@ def __init__(self, data_dir: str,
606
609
self .rechecked_modules = set () # type: Set[str]
607
610
self .plugin = plugin
608
611
self .flush_errors = flush_errors
612
+ self .cache_enabled = options .incremental and options .cache_dir != os .devnull
609
613
self .saved_cache = saved_cache if saved_cache is not None else {} # type: SavedCache
610
614
self .stats = {} # type: Dict[str, Any] # Values are ints or floats
611
615
616
+ def use_fine_grained_cache (self ) -> bool :
617
+ return self .cache_enabled and self .options .use_fine_grained_cache
618
+
612
619
def maybe_swap_for_shadow_path (self , path : str ) -> str :
613
620
if (self .options .shadow_file and
614
621
os .path .samefile (self .options .shadow_file [0 ], path )):
@@ -1156,7 +1163,7 @@ def validate_meta(meta: Optional[CacheMeta], id: str, path: Optional[str],
1156
1163
# changed since the cache was generated. We *don't* want to do a
1157
1164
# coarse-grained incremental rebuild, so we accept the cache
1158
1165
# metadata even if it doesn't match the source file.
1159
- if manager .options . use_fine_grained_cache :
1166
+ if manager .use_fine_grained_cache () :
1160
1167
manager .log ('Using potentially stale metadata for {}' .format (id ))
1161
1168
return meta
1162
1169
@@ -1654,7 +1661,7 @@ def __init__(self,
1654
1661
self .path = path
1655
1662
self .xpath = path or '<string>'
1656
1663
self .source = source
1657
- if path and source is None and self .options . incremental :
1664
+ if path and source is None and self .manager . cache_enabled :
1658
1665
self .meta = find_cache_meta (self .id , path , manager )
1659
1666
# TODO: Get mtime if not cached.
1660
1667
if self .meta is not None :
@@ -1677,7 +1684,7 @@ def __init__(self,
1677
1684
# When doing a fine-grained cache load, pretend we only
1678
1685
# know about modules that have cache information and defer
1679
1686
# handling new modules until the fine-grained update.
1680
- if manager .options . use_fine_grained_cache :
1687
+ if manager .use_fine_grained_cache () :
1681
1688
manager .log ("Deferring module to fine-grained update %s (%s)" % (path , id ))
1682
1689
raise ModuleNotFound
1683
1690
@@ -1798,7 +1805,7 @@ def fix_cross_refs(self) -> None:
1798
1805
# cache load because we need to gracefully handle missing modules.
1799
1806
fixup_module_pass_one (self .tree , self .manager .modules ,
1800
1807
self .manager .options .quick_and_dirty or
1801
- self .manager .options . use_fine_grained_cache )
1808
+ self .manager .use_fine_grained_cache () )
1802
1809
1803
1810
def calculate_mros (self ) -> None :
1804
1811
assert self .tree is not None , "Internal error: method must be called on parsed file only"
@@ -2059,7 +2066,7 @@ def valid_references(self) -> Set[str]:
2059
2066
2060
2067
def write_cache (self ) -> None :
2061
2068
assert self .tree is not None , "Internal error: method must be called on parsed file only"
2062
- if not self .path or self .options . cache_dir == os . devnull :
2069
+ if not self .path or not self .manager . cache_enabled :
2063
2070
return
2064
2071
if self .manager .options .quick_and_dirty :
2065
2072
is_errors = self .manager .errors .is_errors_for_file (self .path )
@@ -2109,10 +2116,9 @@ def dispatch(sources: List[BuildSource], manager: BuildManager) -> Graph:
2109
2116
# In this case, we just turn the cache off entirely, so we don't need
2110
2117
# to worry about some files being loaded and some from cache and so
2111
2118
# that fine-grained mode never *writes* to the cache.
2112
- if manager .options . use_fine_grained_cache and len (graph ) < 0.50 * len (sources ):
2119
+ if manager .use_fine_grained_cache () and len (graph ) < 0.50 * len (sources ):
2113
2120
manager .log ("Redoing load_graph without cache because too much was missing" )
2114
- manager .options .use_fine_grained_cache = False
2115
- manager .options .cache_dir = os .devnull
2121
+ manager .cache_enabled = False
2116
2122
graph = load_graph (sources , manager )
2117
2123
2118
2124
t1 = time .time ()
@@ -2133,7 +2139,10 @@ def dispatch(sources: List[BuildSource], manager: BuildManager) -> Graph:
2133
2139
if manager .options .dump_graph :
2134
2140
dump_graph (graph )
2135
2141
return graph
2136
- if manager .options .use_fine_grained_cache :
2142
+ # If we are loading a fine-grained incremental mode cache, we
2143
+ # don't want to do a real incremental reprocess of the graph---we
2144
+ # just want to load in all of the cache information.
2145
+ if manager .use_fine_grained_cache ():
2137
2146
process_fine_grained_cache_graph (graph , manager )
2138
2147
else :
2139
2148
process_graph (graph , manager )
0 commit comments