def __init__(self, result: BuildResult) -> None: """Initialize fine-grained build based on a batch build. Args: result: Result from the initialized build. The manager and graph will be taken over by this class. manager: State of the build (mutated by this class) graph: Additional state of the build (mutated by this class) """ manager = result.manager self.manager = manager self.graph = result.graph self.previous_modules = get_module_to_path_map(self.graph) self.deps = manager.fg_deps # Merge in any root dependencies that may not have been loaded merge_dependencies(manager.load_fine_grained_deps(FAKE_ROOT_MODULE), self.deps) self.previous_targets_with_errors = manager.errors.targets() self.previous_messages = result.errors[:] # Module, if any, that had blocking errors in the last run as (id, path) tuple. self.blocking_error = None # type: Optional[Tuple[str, str]] # Module that we haven't processed yet but that are known to be stale. self.stale = [] # type: List[Tuple[str, str]] # Disable the cache so that load_graph doesn't try going back to disk # for the cache. self.manager.cache_enabled = False # Some hints to the test suite about what is going on: # Active triggers during the last update self.triggered = [] # type: List[str] # Modules passed to update during the last update self.changed_modules = [] # type: List[Tuple[str, str]] # Modules processed during the last update self.updated_modules = [] # type: List[str] # Targets processed during last update (for testing only). self.processed_targets = [] # type: List[str]
def ensure_deps_loaded(module: str, deps: Dict[str, Set[str]], graph: Dict[str, State]) -> None: """Ensure that the dependencies on a module are loaded. Dependencies are loaded into the 'deps' dictionary. This also requires loading dependencies from any parent modules, since dependencies will get stored with parent modules when a module doesn't exist. """ if module in graph and graph[module].fine_grained_deps_loaded: return parts = module.split('.') for i in range(len(parts)): base = '.'.join(parts[:i + 1]) if base in graph and not graph[base].fine_grained_deps_loaded: merge_dependencies(graph[base].load_fine_grained_deps(), deps) graph[base].fine_grained_deps_loaded = True
def fix_fg_dependencies(manager: BuildManager, deps: Dict[str, Set[str]]) -> None: """Populate the dependencies with stuff that build may have missed""" # This means the root module and typestate merge_dependencies(manager.load_fine_grained_deps(FAKE_ROOT_MODULE), deps)