class KubosLinker(object): def __init__(self): self.kb = KubosBuild() def get_module_deps(self, app_dir): module_json = json.load(open("%s/module.json" % app_dir)) if 'dependencies' in module_json: return module_json['dependencies'] else: return [] def link_sys(self, link_cmd): for module in self.kb.modules(include_bin=False): print '[module %s@%s]' % (module.yotta_name(), module.path) utils.cmd('kubos', link_cmd, cwd=module.path) for target in self.kb.targets(): print '[target %s@%s]' % (target.yotta_name(), target.path) utils.cmd('kubos', link_cmd + '-target', cwd=target.path) def link_app(self, app_dir, link_cmd): print '[app %s]' % app_dir app_modules = self.get_module_deps(app_dir) for module in self.kb.modules(include_bin=False): if module.yotta_name() in app_modules: utils.cmd('kubos', link_cmd, module.yotta_name(), cwd=app_dir) for target in self.kb.targets(): utils.cmd('kubos', link_cmd + '-target', target.yotta_name(), cwd=app_dir)
class KubosLinker(object): def __init__(self): self.kb = KubosBuild() def link_sys(self, link_cmd): for module in self.kb.modules(include_bin=False): print '[module %s@%s]' % (module.yotta_name(), module.path) utils.cmd('kubos', link_cmd, cwd=module.path) for target in self.kb.targets(): print '[target %s@%s]' % (target.yotta_name(), target.path) utils.cmd('kubos', link_cmd + '-target', cwd=target.path) def link_app(self, app_dir, link_cmd): print '[app %s]' % app_dir for module in self.kb.modules(include_bin=False): utils.cmd('kubos', link_cmd, module.yotta_name(), cwd=app_dir) for target in self.kb.targets(): utils.cmd('kubos', link_cmd + '-target', target.yotta_name(), cwd=app_dir)
class KubosBuilder(object): def __init__(self): self.kb = KubosBuild() self.modules = self.kb.modules() self.targets = self.kb.targets() def list_targets(self): for target in self.kb.targets(): if 'buildTarget' in target.yotta_data: print(target.yotta_name()) def list_modules(self): for module in self.kb.modules(): print(module.yotta_name()) def find_modules(self, path): path_list = path.split("/") modules = set() # Pop off file name for first directory path_list.pop() while len(path_list): new_path = "/".join(path_list) kubos_build = KubosBuild(kubos_dir=new_path) for p in kubos_build.projects: if p.type != "unknown": modules.add(p.yotta_name()) if len(modules): break path_list.pop() return modules def list_changed_modules(self, ref): try: git_output = subprocess.check_output( ["git", "diff", "--numstat", ref]) git_lines = [l for l in git_output.splitlines()] file_paths = [l.split()[2] for l in git_lines] modules = set() for path in file_paths: modules = modules | (self.find_modules(path)) if len(modules): print("Modules changed:") for m in modules: print(m) return 0 except subprocess.CalledProcessError: print("Error getting changed modules") return 1 def build(self, module_name="", target_name=""): module = next( (m for m in self.kb.modules() if m.yotta_name() == module_name), None) target = next( (t for t in self.kb.targets() if t.yotta_name() == target_name), None) if module and target: print('Building [module %s@%s] for [target %s] - ' % (module.yotta_name(), module.path, target_name), end="") utils.cmd('kubos', 'target', target_name, cwd=module.path, echo=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) utils.cmd('kubos', 'clean', cwd=module.path, echo=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) ret = utils.cmd('yt', 'build', cwd=module.path, echo=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) print('Result %d' % ret) return ret else: if module is None: print("Module %s was not found" % module_name) if target is None: print("Target %s was not found" % target_name) return 1 def build_all_targets(self, module_name=""): ret = 0 module = next( (m for m in self.kb.modules() if m.yotta_name() == module_name), None) if module: for target in self.kb.build_targets(): build_ret = self.build(module.yotta_name(), target.yotta_name()) if build_ret != 0: ret = build_ret return ret else: print("Module %s was not found" % module_name) return 1 def build_all_modules(self, target_name=""): ret = 0 target = next( (t for t in self.kb.targets() if t.yotta_name() == target_name), None) if target: for module in self.kb.modules(): build_ret = self.build(module.yotta_name(), target.yotta_name()) if build_ret != 0: ret = build_ret return ret else: print("Target %s was not found" % target_name) return 1 def build_all_combinations(self): ret = 0 for target in self.kb.targets(): for module in self.kb.modules(): build_ret = self.build(module.yotta_name(), target.yotta_name()) if build_ret != 0: ret = build_ret return ret