Example #1
0
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)
Example #2
0
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)
Example #3
0
    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
Example #4
0
def main():
    kb = KubosBuild()
    for project in kb.projects:
        check_changes(project)

    print "Create tags here"
    for _dir in create_tag:
        print "\t%s" % _dir

    print "Update tags here"
    for _dir in update_tag:
        print "\t%s" % _dir

    print "Leave tags alone"
    for _dir in leave_tag:
        print "\t%s" % _dir
Example #5
0
 def __init__(self):
     self.kb = KubosBuild()
Example #6
0
 def __init__(self):
     self.kb = KubosBuild()
     self.modules = self.kb.modules()
     self.targets = self.kb.targets()
Example #7
0
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
Example #8
0
import urlparse
import xml.dom.minidom as minidom

from kubos_build import KubosBuild

DEFAULT_REMOTE = 'openkosmosorg'
DEFAULT_REVISION = 'master'
DEFAULT_FETCH = 'https://github.com/openkosmosorg/'

Remote = namedtuple('Remote', ['name', 'fetch'])
Project = namedtuple('Project', ['name', 'path', 'remote', 'revision'])

xml_remotes = set([Remote(name=DEFAULT_REMOTE, fetch=DEFAULT_FETCH)])
xml_projects = set()

kb = KubosBuild()
for project in kb.projects:
    project_args = dict(name=project.name, path=project.relpath)
    if project.upstream:
        upstream_url = list(urlparse.urlparse(project.upstream['url']))
        upstream_url[2] = os.path.dirname(upstream_url[2]) + '/'
        xml_remotes.add(
            Remote(name=project.upstream['remote'],
                   fetch=urlparse.urlunparse(upstream_url)))
        project_args['remote'] = project.upstream['remote']
        project_args['revision'] = project.upstream['branch']
    else:
        project_args['remote'] = DEFAULT_REMOTE
        project_args['revision'] = project.commit

    xml_projects.add(Project(**project_args))