Exemplo n.º 1
0
def get_toolchain(args):
    """
    Get the toolchain to use.
    If we are inside a build worktree, return the default toolchain is this worktree.
    """
    if args.toolchain_name:
        return qitoolchain.get_toolchain(args.toolchain_name)
    config = args.config
    if not config:
        try:
            build_worktree = qibuild.parsers.get_build_worktree(args)
            active_build_config = build_worktree.build_config.active_build_config
            if active_build_config:
                config = active_build_config.toolchain
            else:
                config = None
        except qisys.worktree.NotInWorkTree:
            config = None
    if not config:
        mess = "Could not find which config to use.\n"
        mess += "(not in a work tree or no default config in "
        mess += "current worktree configuration)\n"
        mess += "Please specify a configuration with -c, --config \n"
        mess += "or a toolchain name with -t, --toolchain"
        raise Exception(mess)
    qibuild_cfg = qibuild.config.QiBuildConfig()
    qibuild_cfg.read()
    build_config = qibuild_cfg.configs.get(config)
    if not build_config:
        raise Exception("No such config: %s" % config)
    tc_name = build_config.toolchain
    if not tc_name:
        raise Exception("config %s has no toolchain" % config)
    return qitoolchain.get_toolchain(tc_name)
Exemplo n.º 2
0
def do(args):
    """Main entry point"""

    worktree = args.worktree
    if not worktree:
        worktree = os.getcwd()

    if args.config:
        # Just make sure the user choose a valid default toolchain
        qitoolchain.get_toolchain(args.config)

    worktree = qibuild.sh.to_native_path(worktree)
    parent_worktree = qisrc.worktree.guess_worktree(worktree)
    if parent_worktree:
        if parent_worktree != worktree:
            # Refuse to create nested worktrees
            ui.error("""A qi worktree already exists in {parent_worktree}
Refusing to create a nested worktree in {worktree}
Use:
    qibuild init -f -w {parent_worktree}
If you want to re-initialize the worktree in {parent_worktree}
""".format(worktree=worktree, parent_worktree=parent_worktree))
            sys.exit(1)
        else:
            # Refuse to re-initalize the worktree unless "-f" is given
            if not args.force:
                ui.warning("There is already a worktree in", worktree, "\n"
                           "Use --force if you want to re-initialize this worktree")
                return

    qibuild.toc.create(worktree, force=args.force)
    # User maybe re-running qibuild init because it has a
    # bad default exception ...
    try:
        toc = qibuild.toc.toc_open(worktree)
    except qibuild.toc.WrongDefaultException:
        pass

    toc_cfg_path = os.path.join(worktree, ".qi", "qibuild.xml")
    qibuild_cfg = qibuild.config.QiBuildConfig()
    qibuild_cfg.read()
    qibuild_cfg.read_local_config(toc_cfg_path)
    qibuild_cfg.local.defaults.config = args.config
    qibuild_cfg.write_local_config(toc_cfg_path)

    # Safe to be called now that we've created it
    # and that we know we don't have a wrong defaut config:
    toc = qibuild.toc.toc_open(worktree)

    if not args.interactive:
        return

    qibuild.wizard.run_config_wizard(toc)
Exemplo n.º 3
0
def do(args):
    """Main entry point

    """
    feed = args.feed
    tc_name = args.name
    if tc_name:
        toolchain = qitoolchain.get_toolchain(tc_name)
        if not feed:
            feed = toolchain.feed_url
            if not feed:
                mess  = "Could not find feed for toolchain %s\n" % tc_name
                mess += "Please check configuration or " \
                        "specifiy a feed on the command line\n"
                raise Exception(mess)
        toolchain.update(feed)
    else:
        tc_names = qitoolchain.get_tc_names()
        for i, tc_name in enumerate(tc_names, start=1):
            toolchain = qitoolchain.toolchain.Toolchain(tc_name)
            tc_feed = toolchain.feed_url
            if not tc_feed:
                ui.warning("No feed found for %s, skipping" % tc_name)
                continue
            ui.info(ui.green, "*", ui.reset, "(%i/%i)" % (i, len(tc_names)),
                    ui.green, "Updating", ui.blue, tc_name)
            toolchain.update(tc_feed)
Exemplo n.º 4
0
def do(args):
    """Main entry point

    """
    feed = args.feed
    tc_name = args.name
    dry_run = args.dry_run
    if tc_name:
        toolchain = qitoolchain.get_toolchain(tc_name)
        if not feed:
            feed = qitoolchain.toolchain.get_tc_feed(tc_name)
            if not feed:
                mess  = "Could not find feed for toolchain %s\n" % tc_name
                mess += "Pleas check configuration or specifiy a feed on the command line\n"
                raise Exception(mess)
        ui.info(ui.green, "Updating toolchain", tc_name, "with", feed)
        toolchain.parse_feed(feed, dry_run=dry_run)
    else:
        tc_names = qitoolchain.get_tc_names()
        i = 0
        for tc_name in tc_names:
            i += 1
            tc_feed = qitoolchain.toolchain.get_tc_feed(tc_name)
            ui.info(ui.green, "*", ui.reset, "(%i/%i)" % (i, len(tc_names)),
                    ui.green, "Updating", ui.blue, tc_name)
            if not tc_feed:
                ui.warning("No feed found for %s, skipping" % tc_name)
                continue
            ui.info(ui.green, "Reading", tc_feed)
            toolchain = qitoolchain.Toolchain(tc_name)
            toolchain.parse_feed(tc_feed, dry_run=dry_run)
Exemplo n.º 5
0
def get_toolchain_binary_paths(build_config):
    """ Get the toolchain of the build_config and return the PATH of every bin packages as a string """
    bins = []
    if build_config:
        toolchain = None
        try:
            if hasattr(build_config, 'toolchain'):
                toolchain = build_config.toolchain
            else:
                # When called from qibuildfarm.release.functions (ie: build_config is the build_config name as string)
                from qibuild.config import QiBuildConfig
                from qitoolchain import get_toolchain
                qibuild_cfg = QiBuildConfig()
                qibuild_cfg.read()
                qibuild_config = qibuild_cfg.configs.get(build_config)
                if qibuild_config:
                    toolchain = get_toolchain(qibuild_config.toolchain)
            if toolchain:
                for pkg in toolchain.packages:
                    bin_dir = os.path.join(pkg.path, 'bin')
                    if os.path.isdir(bin_dir):
                        bins.append(bin_dir)
        except Exception:
            pass
    return os.pathsep.join(bins)
Exemplo n.º 6
0
def do(args):
    """ Main entry point """
    feed = args.feed
    tc_name = args.name
    if tc_name:
        toolchain = qitoolchain.get_toolchain(tc_name)
        if not feed:
            feed = toolchain.feed_url
            if not feed:
                mess = "Could not find feed for toolchain %s\n" % tc_name
                mess += "Please check configuration or " \
                        "specifiy a feed on the command line\n"
                raise Exception(mess)
        toolchain.update(feed, branch=args.branch, name=args.feed_name)
    else:
        tc_names = qitoolchain.get_tc_names()
        tc_with_feed = [x for x in tc_names if qitoolchain.toolchain.Toolchain(x).feed_url]
        tc_without_feed = list(set(tc_names) - set(tc_with_feed))
        for i, tc_name in enumerate(tc_with_feed, start=1):
            toolchain = qitoolchain.toolchain.Toolchain(tc_name)
            tc_feed = toolchain.feed_url
            ui.info(ui.green, "*", ui.reset, "(%i/%i)" % (i, len(tc_with_feed)),
                    ui.green, "Updating", ui.blue, tc_name, ui.reset, "with", ui.green,
                    tc_feed)
            toolchain.update(tc_feed)
        if tc_without_feed:
            ui.info("These toolchains will be skipped because they have no feed:", ", ".join(tc_without_feed))
Exemplo n.º 7
0
def do(args):
    """ Main entry point

    """
    dry_run = args.dry_run
    tc = qitoolchain.get_toolchain(args.name)
    tc.clean_cache(dry_run=dry_run)
Exemplo n.º 8
0
def do(args):
    """ Main entry point  """
    force_rm = args.force_remove
    tc = qitoolchain.get_toolchain(args.name)
    ui.info(ui.green, "Removing toolchain", ui.blue, tc.name)
    tc.remove(force_remove=force_rm)
    ui.info(ui.green, "done")
Exemplo n.º 9
0
 def add_package(self, name, package_name, package_version="r1"):
     toolchain = qitoolchain.get_toolchain(name)
     package_path = self.tmp.mkdir(package_name)
     package = qitoolchain.qipackage.QiPackage(package_name, package_version)
     package.path = package_path.strpath
     toolchain.add_package(package)
     return package
Exemplo n.º 10
0
def do(args):
    """ Main entry point """
    toolchain = qitoolchain.get_toolchain(args.name)
    svn_packages = list()
    for package in toolchain.packages:
        svn_dir = os.path.join(package.path, ".svn")
        if os.path.exists(svn_dir):
            svn_packages.append(package)
    not_clean = list()
    for i, svn_package in enumerate(svn_packages, start=1):
        to_write = "Checking (%d/%d) " % (i, len(svn_packages))
        sys.stdout.write(to_write + "\r")
        sys.stdout.flush()
        svn = qisrc.svn.Svn(svn_package.path)
        _rc, out = svn.call("status", raises=False)
        if out:
            not_clean.append((svn_package.name, out))
    if not not_clean:
        ui.info("\n", ui.green, "All OK")
        sys.exit(0)
    ui.warning("Some svn packages are not clean")
    for name, message in not_clean:
        ui.info(ui.green, "*", ui.reset, ui.blue, name)
        ui.info(message)
    sys.exit(1)
def test_simple(qitoolchain_action):
    qitoolchain_action("create", "foo")
    word_package = qitoolchain_action.get_test_package("world")
    qitoolchain_action("add-package", "-c", "foo",  word_package)
    tc = qitoolchain.get_toolchain("foo")
    world_package = tc.packages[0]
    assert world_package.name == "world"
    assert world_package.path
Exemplo n.º 12
0
    def toolchain(self):
        """ The current toolchain, either set by the user from the command
        line or read from the local qibuild settings

        """
        if self.active_config:
            return qitoolchain.get_toolchain(self.active_config)
        return None
Exemplo n.º 13
0
def do(args):
    """ Main method """
    if args.name:
        tc_names = [args.name]
    else:
        tc_names = qitoolchain.get_tc_names()
    for tc_name in tc_names:
        toolchain = qitoolchain.get_toolchain(tc_name)
        ui.info(str(toolchain))
Exemplo n.º 14
0
def do(args):
    """ Main entry point  """
    tc = qitoolchain.get_toolchain(args.name)
    if args.force:
        ui.info(ui.green, "Removing toolchain", ui.blue, tc.name)
        tc.remove()
        ui.info(ui.green, "done")
    else:
        ui.info("Would remove toolchain", ui.blue, tc.name)
def test_simple(qitoolchain_action):
    """ Test Simple """
    qitoolchain_action("create", "foo")
    qibuild.config.add_build_config("foo", toolchain="foo")
    word_package = qitoolchain_action.get_test_package("world")
    qitoolchain_action("add-package", "-c", "foo", word_package)
    tc = qitoolchain.get_toolchain("foo")
    world_package = tc.packages[0]
    assert world_package.name == "world"
    assert world_package.path
Exemplo n.º 16
0
def do(args):
    """ Main method """
    tc_names = qitoolchain.get_tc_names()
    tc_name = args.name
    if tc_name:
        toolchain = qitoolchain.get_toolchain(tc_name)
        print toolchain
    else:
        for tc_name in tc_names:
            toolchain = qitoolchain.Toolchain(tc_name)
            print toolchain
            print
Exemplo n.º 17
0
def test_legacy_happy_path(tmpdir, qitoolchain_action):
    qitoolchain_action("create", "foo")
    qibuild.config.add_build_config("foo", toolchain="foo")
    world = tmpdir.mkdir("world")
    world.ensure("include", "world.h", file=True)
    world.ensure("lib", "libworld.so", file=True)
    archive = qisys.archive.compress(world.strpath)
    qitoolchain_action("add-package", "-c", "foo", "--name", "world", archive)
    tc = qitoolchain.get_toolchain("foo")
    world_package = tc.get_package("world")
    assert os.path.exists(os.path.join(world_package.path, "include", "world.h"))
    assert os.path.exists(os.path.join(world_package.path, "lib", "libworld.so"))
Exemplo n.º 18
0
def do(args):
    """ Remove a project from a toolchain

    - Check that there is a current toolchain
    - Remove the package from the toolchain

    """
    package_name = args.package_name
    tc = qitoolchain.get_toolchain(args)

    LOGGER.info("Removing package %s from toolchain %s", package_name, tc.name)
    tc.remove_package(package_name)
Exemplo n.º 19
0
def do(args):
    """ Remove a project from a toolchain

    - Check that there is a current toolchain
    - Remove the package from the toolchain

    """
    package_name = args.package_name
    tc_name = qitoolchain.toolchain_name_from_args(args)
    tc = qitoolchain.get_toolchain(tc_name)
    ui.info(ui.green, "Removing package", ui.blue, package_name,
            ui.green, "from toolchain", ui.blue, tc.name)
    tc.remove_package(package_name)
def test_simple(qitoolchain_action, tmpdir, toolchains):
    this_dir = os.path.dirname(__file__)
    json_c_bz2_path_src = os.path.join(this_dir, "packages", "json-c-0.9.tbz2")
    json_c_bz2_path = tmpdir.join("json-c-0.9.tbz2").strpath
    qisys.sh.install(json_c_bz2_path_src, json_c_bz2_path)

    res = qitoolchain_action("convert-package",
                             "--name", "json-c",
                             "--batch", json_c_bz2_path)
    qitoolchain_action("create", "test")
    qitoolchain_action("add-package", "--config", "test", res)
    toolchain = qitoolchain.get_toolchain("test")
    assert toolchain.get_package("json-c")
Exemplo n.º 21
0
    def read_local_settings(self):
        """ Read ``<worktree>/.qi/qibuild.xml`` """
        local_settings = qibuild.config.LocalSettings()
        tree = qisys.qixml.read(self.build_worktree.qibuild_xml)
        local_settings.parse(tree)
        default_config = local_settings.defaults.config
        if not default_config:
            return
        try:
            qitoolchain.get_toolchain(default_config)
        except Exception:
            mess = """ \
Incorrect config detected for worktree in {build_worktree.root}
Default config set in .qi/qibuild.xml is {default_config}
but this does not match any toolchain name
"""
            mess = mess.format(build_worktree=self.build_worktree,
                               default_config=default_config)
            raise Exception(mess)
        self._default_config = default_config
        self.qibuild_cfg.set_active_config(default_config)
        self.set_active_config(default_config)
Exemplo n.º 22
0
    def toolchain(self):
        """ The current toolchain, either set by the user from the command
        line or read from the local qibuild settings

        """
        if self._toolchain:
            return self._toolchain
        if self.active_build_config:
            toolchain_name = self.active_build_config.toolchain
            if toolchain_name:
                self._toolchain = qitoolchain.get_toolchain(toolchain_name)
            return self._toolchain
        else:
            return None
def test_legacy_happy_path(tmpdir, qitoolchain_action):
    qitoolchain_action("create", "foo")
    qibuild.config.add_build_config("foo", toolchain="foo")
    world = tmpdir.mkdir("world")
    world.ensure("include", "world.h", file=True)
    world.ensure("lib", "libworld.so", file=True)
    archive = qisys.archive.compress(world.strpath)
    qitoolchain_action("add-package", "-c", "foo", "--name", "world", archive)
    tc = qitoolchain.get_toolchain("foo")
    world_package = tc.get_package("world")
    assert os.path.exists(
        os.path.join(world_package.path, "include", "world.h"))
    assert os.path.exists(
        os.path.join(world_package.path, "lib", "libworld.so"))
Exemplo n.º 24
0
    def toolchain(self):
        """ The current toolchain, either set by the user from the command
        line or read from the local qibuild settings

        """
        if self._toolchain:
            return self._toolchain
        if self.active_build_config:
            toolchain_name = self.active_build_config.toolchain
            if toolchain_name:
                self._toolchain = qitoolchain.get_toolchain(toolchain_name)
            return self._toolchain
        else:
            return None
Exemplo n.º 25
0
def do(args):
    """ Main entry point  """
    tc = qitoolchain.get_toolchain(args.name, args.ignore)
    if tc:
        if args.force:
            ui.info(ui.green, "Removing toolchain", ui.blue, tc.name)
            tc.remove()
            ui.info(ui.green, "done")
        else:
            ui.info("Would remove toolchain", ui.blue, tc.name)
            ui.info("Use --force to actually remove it.")
            return
    else:
        ui.info("Would remove toolchain", ui.blue, args.name)
        ui.info("This toolchain does not exists.")
        return
Exemplo n.º 26
0
def do(args):
    """ Main entry point  """
    try:
        tc = qitoolchain.get_toolchain(args.name)
    except Exception:
        if args.force:
            return
        else:
            raise
    if args.force:
        ui.info(ui.green, "Removing toolchain", ui.blue, tc.name)
        tc.remove()
        ui.info(ui.green, "done")
    else:
        ui.info("Would remove toolchain", ui.blue, tc.name)
        ui.info("Use --force to actually remove it.")
Exemplo n.º 27
0
def do(args):
    """ Main entry point  """
    tc = qitoolchain.get_toolchain(args.name, args.ignore)
    if tc:
        if args.force:
            ui.info(ui.green, "Removing toolchain", ui.blue, tc.name)
            tc.remove()
            ui.info(ui.green, "done")
        else:
            ui.info("Would remove toolchain", ui.blue, tc.name)
            ui.info("Use --force to actually remove it.")
            return
    else:
        ui.info("Would remove toolchain", ui.blue, args.name)
        ui.info("This toolchain does not exists.")
        return
def test_simple(qitoolchain_action, tmpdir, toolchains):
    """ Test Simple """
    this_dir = os.path.dirname(__file__)
    json_c_bz2_path_src = os.path.join(this_dir, "packages", "json-c-0.9.tbz2")
    json_c_bz2_path = tmpdir.join("json-c-0.9.tbz2").strpath
    qisys.sh.install(json_c_bz2_path_src, json_c_bz2_path)
    res = qitoolchain_action(
        "convert-package",
        "--name",
        "json-c",
        "--batch",
        json_c_bz2_path
    )
    qitoolchain_action("create", "test")
    qibuild.config.add_build_config("test", toolchain="test")
    qitoolchain_action("add-package", "--config", "test", res)
    toolchain = qitoolchain.get_toolchain("test")
    assert toolchain.get_package("json-c")
def test_flags_package(tmpdir, qitoolchain_action):
    """ Test Flags Package """
    qitoolchain_action("create", "foo")
    c11_flags = tmpdir.mkdir("c++11-flags")
    c11_flags.join("config.cmake").write("""\nset(CMAKE_CXX_FLAGS "-std=gnu++11")\n""")
    c11_flags.join("package.xml").write("""\n<package name="c++11-flags" toolchain_file="config.cmake" />\n""")
    flags_package = tmpdir.join("c++11-flags.zip")
    qisys.archive.compress(c11_flags.strpath, output=flags_package.strpath, flat=True)
    qitoolchain_action("add-package", "--toolchain", "foo", flags_package.strpath)
    foo_toolchain = qitoolchain.get_toolchain("foo")
    tc_file = foo_toolchain.toolchain_file
    with open(tc_file, "r") as fp:
        contents = fp.read()
    included_file = None
    for line in contents.splitlines():
        match = re.match(r'include\("(.*)"\)', line)
        if match:
            included_file = match.groups()[0]
    assert os.path.exists(included_file)
Exemplo n.º 30
0
def do(args):
    """ Main entry point  """
    tc = qitoolchain.get_toolchain(args.name)
    if args.force:
        ui.info(ui.green, "Removing toolchain", ui.blue, tc.name)
        tc.remove()
        ui.info(ui.green, "done")
    else:
        ui.info("Would remove toolchain", ui.blue, tc.name)
        ui.info("Use --force to actually remove it.")
        return

    qibuild_cfg = qibuild.config.QiBuildConfig()
    qibuild_cfg.read()
    build_configs = qibuild_cfg.configs.values()
    for build_config in build_configs:
        if build_config.toolchain == tc.name:
            build_config.toolchain = None
    qibuild_cfg.write()
Exemplo n.º 31
0
 def add_package(self, name, package_name, package_version="r1",
                 build_depends=None, run_depends=None, test_depends=None):
     """ Add a Package """
     toolchain = qitoolchain.get_toolchain(name)
     package_path = self.tmp.mkdir(package_name)
     package = qitoolchain.qipackage.QiPackage(package_name, package_version)
     package.path = package_path.strpath
     package.build_depends = build_depends
     package.run_depends = run_depends
     package.test_depends = test_depends
     package_xml = self.tmp.join(package_name, "package.xml")
     xml_elem = qisys.qixml.etree.Element("package")
     xml_elem.set("name", package_name)
     if package_version:
         xml_elem.set("version", package_version)
     qibuild.deps.dump_deps_to_xml(package, xml_elem)
     qisys.qixml.write(xml_elem, package_xml.strpath)
     toolchain.add_package(package)
     return package
Exemplo n.º 32
0
def do(args):
    """ Main entry point  """
    tc = qitoolchain.get_toolchain(args.name)
    if args.force:
        ui.info(ui.green, "Removing toolchain", ui.blue, tc.name)
        tc.remove()
        ui.info(ui.green, "done")
    else:
        ui.info("Would remove toolchain", ui.blue, tc.name)
        ui.info("Use --force to actually remove it.")
        return

    qibuild_cfg = qibuild.config.QiBuildConfig()
    qibuild_cfg.read()
    build_configs = qibuild_cfg.configs.values()
    for build_config in build_configs:
        if build_config.toolchain == tc.name:
            build_config.toolchain = None
    qibuild_cfg.write()
Exemplo n.º 33
0
    def add_package(self, name, package_name, package_version="r1",
                    build_depends=None, run_depends=None, test_depends=None,
                    host_depends=None):
        toolchain = qitoolchain.get_toolchain(name)
        package_path = self.tmp.mkdir(package_name)
        package = qitoolchain.qipackage.QiPackage(package_name, package_version)
        package.path = package_path.strpath

        # Make sure self.*_depends are sets
        for dep_type in ["build", "run", "test", "host"]:
            attr_name = "%s_depends" % dep_type
            value = locals()[attr_name]
            if value:
                setattr(package, attr_name, set(value))
            else:
                setattr(package, attr_name, set())

        package.write_package_xml()
        toolchain.add_package(package)
        return package
Exemplo n.º 34
0
def test_path_conf_contains_toolchain_paths(qibuild_action, toolchains):
    toolchains.create("foo")
    qibuild.config.add_build_config("foo", toolchain="foo")
    toolchains.add_package("foo", "bar")
    foo_tc = qitoolchain.get_toolchain("foo")
    bar_path = foo_tc.get_package("bar").path
    qibuild_action.add_test_project("hello")
    qibuild_action.add_test_project("world")
    build_woktree = TestBuildWorkTree()
    build_woktree.build_config.set_active_config("foo")
    qibuild_action("configure", "hello", "--config", "foo")
    world_proj = build_woktree.get_build_project("world")
    hello_proj = build_woktree.get_build_project("hello")
    path_conf = os.path.join(hello_proj.sdk_directory, "share", "qi", "path.conf")
    with open(path_conf, "r") as fp:
        contents = fp.readlines()
    sdk_dirs = [x.strip() for x in contents]
    assert hello_proj.sdk_directory in sdk_dirs
    assert world_proj.sdk_directory in sdk_dirs
    assert bar_path in sdk_dirs
Exemplo n.º 35
0
def test_path_conf_contains_toolchain_paths(qibuild_action, toolchains):
    toolchains.create("foo")
    qibuild.config.add_build_config("foo", toolchain="foo")
    toolchains.add_package("foo", "bar")
    foo_tc = qitoolchain.get_toolchain("foo")
    bar_path = foo_tc.get_package("bar").path
    qibuild_action.add_test_project("hello")
    qibuild_action.add_test_project("world")
    build_woktree = TestBuildWorkTree()
    build_woktree.build_config.set_active_config("foo")
    qibuild_action("configure", "hello", "--config", "foo")
    world_proj = build_woktree.get_build_project("world")
    hello_proj = build_woktree.get_build_project("hello")
    path_conf = os.path.join(hello_proj.sdk_directory, "share", "qi", "path.conf")
    with open(path_conf, "r") as fp:
        contents = fp.readlines()
    sdk_dirs = [x.strip() for x in contents]
    assert hello_proj.sdk_directory in sdk_dirs
    assert world_proj.sdk_directory in sdk_dirs
    assert bar_path in sdk_dirs
Exemplo n.º 36
0
def do(args):
    """ Add a package to a toolchain

    - Check that there is a current toolchain
    - Add the package to the cache
    - Add the package from cache to toolchain

    """
    package_name = args.package_name
    package_path = args.package_path
    tc = qitoolchain.get_toolchain(args)
    # extract it to the default packages path of the toolchain
    tc_packages_path = qitoolchain.toolchain.get_default_packages_path(tc.name)
    dest = os.path.join(tc_packages_path, package_name)
    qibuild.sh.rm(dest)
    with qibuild.sh.TempDir() as tmp:
        extracted = qibuild.archive.extract(package_path, tmp)
        qibuild.sh.install(extracted, dest, quiet=True)

    package = qitoolchain.Package(package_name, dest)
    tc.add_package(package)
Exemplo n.º 37
0
def get_toolchain(args):
    """ Get the toolchain to use.
    If we are inside a build worktree, return the default
    toolchain is this worktree

    """
    config = args.config
    if not config:
        try:
            build_worktree = qibuild.parsers.get_build_worktree(args)
            config = build_worktree.build_config.active_config
        except qisys.worktree.NotInWorkTree:
            config = None

    if not config:
        mess  = "Could not find which config to use.\n"
        mess += "(not in a work tree or no default config in "
        mess += "current worktree configuration)\n"
        mess += "Please specify a configuration with -c \n"
        raise Exception(mess)

    return qitoolchain.get_toolchain(config)
Exemplo n.º 38
0
def do(args):
    """ Add a package to a toolchain

    - Check that there is a current toolchain
    - Add the package to the cache
    - Add the package from cache to toolchain

    """
    package_name = args.package_name
    package_path = args.package_path
    tc_name = qitoolchain.toolchain_name_from_args(args)
    tc = qitoolchain.get_toolchain(tc_name)
    # extract it to the default packages path of the toolchain
    tc_packages_path = qitoolchain.toolchain.get_default_packages_path(tc.name)
    dest = os.path.join(tc_packages_path, package_name)
    qisys.sh.rm(dest)
    with qisys.sh.TempDir() as tmp:
        extracted = qisys.archive.extract(package_path, tmp)
        qisys.sh.install(extracted, dest, quiet=True)

    package = qitoolchain.Package(package_name, dest)
    tc.add_package(package)
def test_flags_package(tmpdir, qitoolchain_action):
    """ Test Flags Package """
    qitoolchain_action("create", "foo")
    c11_flags = tmpdir.mkdir("c++11-flags")
    c11_flags.join("config.cmake").write(
        """\nset(CMAKE_CXX_FLAGS "-std=gnu++11")\n""")
    c11_flags.join("package.xml").write(
        """\n<package name="c++11-flags" toolchain_file="config.cmake" />\n""")
    flags_package = tmpdir.join("c++11-flags.zip")
    qisys.archive.compress(c11_flags.strpath,
                           output=flags_package.strpath,
                           flat=True)
    qitoolchain_action("add-package", "--toolchain", "foo",
                       flags_package.strpath)
    foo_toolchain = qitoolchain.get_toolchain("foo")
    tc_file = foo_toolchain.toolchain_file
    with open(tc_file, "r") as fp:
        contents = fp.read()
    included_file = None
    for line in contents.splitlines():
        match = re.match(r'include\("(.*)"\)', line)
        if match:
            included_file = match.groups()[0]
    assert os.path.exists(included_file)
Exemplo n.º 40
0
def do(args):
    """ Main entry point

    """
    dry_run = args.dry_run
    tc = qitoolchain.get_toolchain(args.name)
    tc_cache = tc.cache

    dirs_to_rm = os.listdir(tc_cache)
    dirs_to_rm = [os.path.join(tc_cache, x) for x in dirs_to_rm]
    dirs_to_rm = [x for x in dirs_to_rm if os.path.isdir(x)]

    num_dirs = len(dirs_to_rm)
    ui.info(ui.green, "Cleaning cache for", ui.blue, tc.name)
    if dry_run:
        print "Would remove %i packages" % num_dirs
        print "Use -f to proceed"
        return

    for (i, dir_to_rm) in enumerate(dirs_to_rm):
        sys.stdout.write("Removing package %i / %i\r" % ((i + 1), num_dirs))
        sys.stdout.flush()
        qisys.sh.rm(dir_to_rm)
    ui.info(ui.green, "done")
Exemplo n.º 41
0
def do(args):
    """ Main entry point

    """
    tc = qitoolchain.get_toolchain(args.name)
    tc.clean_cache()
Exemplo n.º 42
0
def configure(workspace, build_config, build_type="Release"):
    build_dir = os.path.join(workspace, "build-%s" % build_type)
    qisys.sh.mkdir(build_dir, recursive=True)
    platform = get_platform(build_config)
    toolchain = qitoolchain.get_toolchain(build_config.toolchain)
    toolchain.update()
    ui.info(str(toolchain))
    toolchain_path = toolchain.db.db_path
    cmake_args = list()

    cmake_args.append("-Wno-dev")
    cmake_args.append("-DCMAKE_BUILD_TYPE=%s" % build_type)

    # Find Boost in toolchain
    boost_path = toolchain.get_package("boost", raises=True).path
    boost_root = qisys.sh.to_posix_path(boost_path)
    cmake_args.append("-DBOOST_ROOT=%s" % boost_root)
    # our boost package assumes boost libs are shared:
    cmake_args.append("-DBoost_USE_STATIC_LIBS=OFF")

    # Find Eigen3 in toolchain
    eigen_path = toolchain.get_package("eigen3", raises=True).path
    eigen_root = qisys.sh.to_posix_path(eigen_path)
    cmake_args.append("-DEIGEN_ROOT=%s" % eigen_root)

    # Find console_bridge in toolchain
    console_bridge_path = toolchain.get_package("console_bridge",
                                                raises=True).path
    console_bridge_dir = os.path.join(console_bridge_path, "share", "cmake",
                                      "console_bridge")
    console_bridge_dir = qisys.sh.to_posix_path(console_bridge_dir)
    cmake_args.append("-Dconsole_bridge_DIR=%s" % console_bridge_dir)

    # Need an absolute, non-empty path for CMAKE_INSTALL_PREFIX
    cmake_args.append("-DCMAKE_INSTALL_PREFIX=/prefix")

    # Don't bother building tests:
    cmake_args.append("-DCATKIN_ENABLE_TESTING=OFF")

    if platform == "linux":
        cmake_include_path = list()
        cmake_lib_path = list()
        # Need to find lz4 and bz2 (deps of rosbag) in toolchain:
        for dep in ["bzip2", "lz4"]:
            package_path = toolchain.get_package(dep, raises=True).path
            include_path = os.path.join(package_path, "include")
            lib_path = os.path.join(package_path, "lib")
            cmake_include_path.append(include_path)
            cmake_lib_path.append(lib_path)
        cmake_args.append("-DCMAKE_INCLUDE_PATH=%s" %
                          ";".join(cmake_include_path))
        cmake_args.append("-DCMAKE_LIBRARY_PATH=%s" % ";".join(cmake_lib_path))

    cmake_args.append("-DCMAKE_CXX_FLAGS=-std=gnu++11")

    if platform == "windows":
        cmake_args.append("-DCMAKE_DEBUG_POSTFIX=_d")
        cmake_flags = (
            # our boost package assumes boost libs are shared:
            ("BOOST_ALL_DYN_LINK", "1"),
            # ros/time.h uses #ifdef WIN32 instead of #ifdef _WIN32 ...
            ("WIN32", "1"),
        )

        cmake_flags_arg = "-DCMAKE_CXX_FLAGS="
        for key, value in cmake_flags:
            cmake_flags_arg += "/D%s=%s " % (key, value)

        # re-add some flags
        # (they get removed when we set CMAKE_CXX_FLAGS
        # for some reason)
        # /EHsc is required for exceptions, and
        # /MD for linking with the 'dynamic' runtime
        cmake_flags_arg += "/EHsc /MD"
        cmake_args.append(cmake_flags_arg)

    if platform != "linux":
        # Ninja may not work on linux ...
        cmake_args.append("-GNinja")

    cmake_args.append("../src")

    build_env = get_build_env(build_config)
    qisys.command.call(["cmake"] + cmake_args, env=build_env, cwd=build_dir)