diff options
Diffstat (limited to 'methods.py')
-rw-r--r-- | methods.py | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/methods.py b/methods.py index b719395ae0..82c19f09e3 100644 --- a/methods.py +++ b/methods.py @@ -1,5 +1,6 @@ import os import re +import sys import glob import subprocess from collections import OrderedDict @@ -336,7 +337,20 @@ def disable_module(self): self.disabled_modules.append(self.current_module) -def module_check_dependencies(self, module, dependencies, silent=False): +def module_add_dependencies(self, module, dependencies, optional=False): + """ + Adds dependencies for a given module. + Meant to be used in module `can_build` methods. + """ + if module not in self.module_dependencies: + self.module_dependencies[module] = [[], []] + if optional: + self.module_dependencies[module][1].extend(dependencies) + else: + self.module_dependencies[module][0].extend(dependencies) + + +def module_check_dependencies(self, module): """ Checks if module dependencies are enabled for a given module, and prints a warning if they aren't. @@ -344,23 +358,41 @@ def module_check_dependencies(self, module, dependencies, silent=False): Returns a boolean (True if dependencies are satisfied). """ missing_deps = [] - for dep in dependencies: + required_deps = self.module_dependencies[module][0] if module in self.module_dependencies else [] + for dep in required_deps: opt = "module_{}_enabled".format(dep) if not opt in self or not self[opt]: missing_deps.append(dep) if missing_deps != []: - if not silent: - print( - "Disabling '{}' module as the following dependencies are not satisfied: {}".format( - module, ", ".join(missing_deps) - ) + print( + "Disabling '{}' module as the following dependencies are not satisfied: {}".format( + module, ", ".join(missing_deps) ) + ) return False else: return True +def sort_module_list(env): + out = OrderedDict() + deps = {k: v[0] + list(filter(lambda x: x in env.module_list, v[1])) for k, v in env.module_dependencies.items()} + + frontier = list(env.module_list.keys()) + explored = [] + while len(frontier): + cur = frontier.pop() + deps_list = deps[cur] if cur in deps else [] + if len(deps_list) and any([d not in explored for d in deps_list]): + # Will explore later, after its dependencies + frontier.insert(0, cur) + continue + explored.append(cur) + for k in explored: + env.module_list.move_to_end(k) + + def use_windows_spawn_fix(self, platform=None): if os.name != "nt": |