Beispiel #1
0
def list_platforms():
    console.pretty_println("\n********************************* Platform List **********************************", console.bold)
    platforms = get_toolchains_or_platforms(os.path.join(os.path.dirname(__file__), 'platforms'))
    console.pretty_println("Official:", console.bold)
    for family in platforms:
        for platform in platforms[family]:
            console.pretty_print(" -- %s/" % family, console.cyan)
            console.pretty_println("%s" % platform, console.yellow)
    console.pretty_println("Custom:", console.bold)
    platforms = get_toolchains_or_platforms(os.path.join(settings.yujin_tools_home(), 'platforms'))
    if platforms:
        for family in platforms:
            for platform in platforms[family]:
                console.pretty_print(" -- %s/" % family, console.cyan)
                console.pretty_println("%s" % platform, console.yellow)
    else:
        console.pretty_println(" -- ", console.cyan)
    console.pretty_println("**********************************************************************************\n", console.bold)
Beispiel #2
0
def list_platforms():
    console.pretty_println(
        "\n********************************* Platform List **********************************",
        console.bold)
    platforms = get_toolchains_or_platforms(
        os.path.join(os.path.dirname(__file__), 'platforms'))
    console.pretty_println("Official:", console.bold)
    for family in platforms:
        for platform in platforms[family]:
            console.pretty_print(" -- %s/" % family, console.cyan)
            console.pretty_println("%s" % platform, console.yellow)
    console.pretty_println("Custom:", console.bold)
    platforms = get_toolchains_or_platforms(
        os.path.join(settings.yujin_tools_home(), 'platforms'))
    if platforms:
        for family in platforms:
            for platform in platforms[family]:
                console.pretty_print(" -- %s/" % family, console.cyan)
                console.pretty_println("%s" % platform, console.yellow)
    else:
        console.pretty_println(" -- ", console.cyan)
    console.pretty_println(
        "**********************************************************************************\n",
        console.bold)
Beispiel #3
0
def init_configured_build(build_dir_="./", source_dir_="./src", underlays_="/opt/ros/groovy", install_prefix_="./install", release_=False, toolchain_="", platform_=""):
    '''
      This one is used with pre-configured parameters. Note that
      init_build generates parameters parsed from the command line and then
      calls this function.
    '''
    # Help us build the name for the eclipse workspace...usually we call in the workspace itself.
    workspace_dir = os.getcwd()

    ##########################
    # Build directory
    ##########################
    if os.path.isabs(build_dir_):
        build_dir = build_dir_
    else:
        if build_dir_ == "." or build_dir_ == "./":
            build_dir = os.getcwd()
        else:
            build_dir = os.path.join(os.getcwd(), build_dir_)
    if not os.path.isfile(os.path.join(build_dir, "Makefile")):
        if not os.path.isdir(build_dir):  # remember ./ is a valid build dir, even if it's not populated yet
            os.mkdir(build_dir)
    else:
        raise RuntimeError("This build directory is already initialised")

    ##########################
    # Source directory
    ##########################
    source_dir = os.path.abspath(source_dir_)
    build_source_dir = os.path.join(build_dir, 'src')
    if not os.path.isdir(source_dir):
        raise RuntimeError("Specified source space does not exist [" + source_dir + "]")
    if not os.path.isfile(os.path.join(source_dir, ".rosinstall")):
        raise RuntimeError("Could not find a valid source folder (must contain a .rosinstall file therein)'")
    if os.path.exists(build_source_dir):
        if not source_dir == build_source_dir:
            raise RuntimeError("The build directory already has a ./src directory which doesn't match the desired source directory [%s]" % source_dir)
    else:
        os.mkdir(build_source_dir)
        source_subdirectories = os.walk(source_dir).next()[1]
        for d in source_subdirectories:
            common.create_symlink(os.path.join(source_dir, d), os.path.join(build_source_dir, d))

    ##########################
    # Underlays
    ##########################
    try:
        env_underlays = os.environ['CMAKE_PREFIX_PATH']
    except KeyError:
        env_underlays = ""
    underlays_list = [underlay for underlay in underlays_.split(';') if underlay]
    env_underlays_list = [underlay for underlay in env_underlays.split(':') if underlay]
    for underlay in env_underlays_list:
        if underlay not in underlays_list:
            underlays_list.append(underlay)

    ##########################
    # Locate Catkin
    ##########################
    catkin_toplevel = None
    if os.path.isfile(os.path.join(source_dir, 'catkin', 'cmake', 'toplevel.cmake')):
        catkin_toplevel = os.path.join(source_dir, 'catkin', 'cmake', 'toplevel.cmake')
    else:
        catkin_toplevel, unused_catkin_python_path, unused_catkin_cmake_path = common.find_catkin(underlays_list)

    ##########################
    # Add toplevel if exists
    ##########################
    if not catkin_toplevel:
        # Add the default track underlay
        default_track = settings.get_default_track()
        if os.path.isfile(os.path.join("/opt/ros/%s" % default_track, 'share', 'catkin', 'cmake', 'toplevel.cmake')):
            catkin_toplevel = os.path.join("/opt/ros/%s" % default_track, 'share', 'catkin', 'cmake', 'toplevel.cmake')
            unused_catkin_python_path = os.path.join("/opt/ros/%s" % default_track, 'lib', 'python2.7', 'dist-packages')
            console.pretty_println("No catkin found, adding the default track underlay (use yujin_tools_settings to change) [/opt/ros/%s]" % default_track, console.cyan)
            underlays_list.append("/opt/ros/%s" % default_track)
        else:
            raise RuntimeError("Could not find an underlying catkin installation.")
    common.create_symlink(catkin_toplevel, os.path.join(build_source_dir, "CMakeLists.txt"))
    underlays = ';'.join(underlays_list)

    ##########################
    # Other Args
    ##########################
    if install_prefix_ == "/not_set_directory":
        install_prefix = os.path.join(build_dir, "install")
    else:
        install_prefix = install_prefix_
    if release_:
        build_type = "Release"
    else:
        build_type = "DebugWithRelSymbols"
    name = os.path.basename(workspace_dir) + "_" + os.path.basename(build_dir)

    print_build_details(build_dir, source_dir, install_prefix, build_type, underlays, name, toolchain_, platform_)
    os.chdir(build_dir)

    ##########################
    # Toolchain
    ##########################
    if not toolchain_ == "":
        toolchains_dir = os.path.join(os.path.dirname(__file__), 'toolchains')
        custom_toolchains_dir = os.path.join(settings.yujin_tools_home(), 'toolchains')
        tmp_list = toolchain_.split('/')
        if len(tmp_list) != 2:
            raise RuntimeError("Toolchain specification invalid, must be <family>/<tuple> [%s]" % toolchain_)
        family = tmp_list[0]
        toolchain_tuple = tmp_list[1]
        toolchains = get_toolchains_or_platforms(toolchains_dir)
        custom_toolchains = get_toolchains_or_platforms(custom_toolchains_dir)
        if not family in toolchains and not family in custom_toolchains:
            raise RuntimeError("No toolchains available for family %s" % family)
        if family in toolchains and toolchain_tuple in toolchains[family]:
            toolchain_file = os.path.join(toolchains_dir, family, toolchain_tuple + ".cmake")
        elif family in custom_toolchains and toolchain_tuple in custom_toolchains[family]:
            toolchain_file = os.path.join(custom_toolchains_dir, family, toolchain_tuple + ".cmake")
        else:
            raise RuntimeError("Platform %s for family %s not available." % (family, toolchain_tuple))
        if os.path.isfile(toolchain_file):
            shutil.copy(toolchain_file, os.path.join(build_dir, "toolchain.cmake"))
        else:
            raise RuntimeError("Toolchain module not available [%s]" % toolchain_file)

    ##########################
    # Platform
    ##########################
    platform_content = ""
    platforms_dir = os.path.join(os.path.dirname(__file__), 'platforms')
    custom_platforms_dir = os.path.join(settings.yujin_tools_home(), 'platforms')
    if not platform_ == "default":
        tmp_list = platform_.split('/')
        if len(tmp_list) != 2:
            raise RuntimeError("Platform specification invalid, must be <family>/<platform type> [%s]" % platform_)
        family = tmp_list[0]
        platform = tmp_list[1]
        platforms = get_toolchains_or_platforms(platforms_dir)
        custom_platforms = get_toolchains_or_platforms(custom_platforms_dir)
        if not family in platforms and not family in custom_platforms:
            raise RuntimeError("No platforms available for family %s" % family)
        if family in platforms and platform in platforms[family]:
            platform_file = os.path.join(platforms_dir, family, platform + ".cmake")
        elif family in custom_platforms and platform in custom_platforms[family]:
            platform_file = os.path.join(custom_platforms_dir, family, platform + ".cmake")
        else:
            raise RuntimeError("Platform %s for family %s not available." % (family, platform))
    else:
        platform_file = os.path.join(platforms_dir, 'default.cmake')
    if os.path.isfile(platform_file):
        f = open(platform_file, 'r')
        try:
            platform_content = f.read()
        finally:
            f.close()
    else:
        raise RuntimeError("Platform configuration not available [%s]" % platform_)

    ##########################
    # Cache
    ##########################
    instantiate_config_cmake(platform_content, build_dir, build_type, install_prefix, underlays)

    ##########################
    # Templates
    ##########################
    instantiate_template('.bashrc', name, build_dir)
    instantiate_template('konsole', name, build_dir)
    instantiate_template('gnome-terminal', name, build_dir)
    instantiate_template('eclipse', name, build_dir)
Beispiel #4
0
def init_configured_build(default_underlay,
                          build_dir_="./",
                          source_dir_="./src",
                          underlays_="/opt/ros/groovy",
                          install_prefix_="./install",
                          doc_prefix_="./doc",
                          release_=False,
                          toolchain_="",
                          platform_=""):
    '''
      This one is used with pre-configured parameters. Note that
      init_build generates parameters parsed from the command line and then
      calls this function.
    '''
    # Help us build the name for the eclipse workspace...usually we call in the workspace itself.
    workspace_dir = os.getcwd()

    ##########################
    # Build directory
    ##########################
    if os.path.isabs(build_dir_):
        build_dir = build_dir_
    else:
        if build_dir_ == "." or build_dir_ == "./":
            build_dir = os.getcwd()
        else:
            build_dir = os.path.join(os.getcwd(), build_dir_)
    if not os.path.isfile(os.path.join(build_dir, "Makefile")):
        if not os.path.isdir(
                build_dir
        ):  # remember ./ is a valid build dir, even if it's not populated yet
            os.mkdir(build_dir)
    else:
        raise RuntimeError("This build directory is already initialised")

    ##########################
    # Source directory
    ##########################
    source_dir = os.path.abspath(source_dir_)
    build_source_dir = os.path.join(build_dir, 'src')
    if not os.path.isdir(source_dir):
        raise RuntimeError("Specified source space does not exist [" +
                           source_dir + "]")
    if not os.path.isfile(os.path.join(source_dir, ".rosinstall")):
        raise RuntimeError(
            "Could not find a valid source folder (must contain a .rosinstall file therein)'"
        )
    if os.path.exists(build_source_dir):
        if not source_dir == build_source_dir:
            raise RuntimeError(
                "The build directory already has a ./src directory which doesn't match the desired source directory [%s]"
                % source_dir)
    else:
        os.mkdir(build_source_dir)
        source_subdirectories = os.walk(source_dir).next()[1]
        for d in source_subdirectories:
            common.create_symlink(os.path.join(source_dir, d),
                                  os.path.join(build_source_dir, d))
    write_yujin_init_build_configuration(build_source_dir, source_dir)

    ##########################
    # Underlays
    ##########################
    try:
        env_underlays = os.environ['CMAKE_PREFIX_PATH']
    except KeyError:
        env_underlays = ""
    underlays_list = [
        underlay for underlay in underlays_.split(';') if underlay
    ]
    env_underlays_list = [
        underlay for underlay in env_underlays.split(':') if underlay
    ]
    for underlay in env_underlays_list:
        if underlay not in underlays_list:
            underlays_list.append(underlay)

    ##########################
    # Locate Catkin
    ##########################
    catkin_toplevel = None
    if os.path.isfile(
            os.path.join(source_dir, 'catkin', 'cmake', 'toplevel.cmake')):
        catkin_toplevel = os.path.join(source_dir, 'catkin', 'cmake',
                                       'toplevel.cmake')
    else:
        catkin_toplevel, unused_catkin_python_path, unused_catkin_cmake_path = common.find_catkin(
            build_dir, underlays_list)

    ##########################
    # Add toplevel if exists
    ##########################
    if not catkin_toplevel:
        # Add the default underlay
        if default_underlay is not None and os.path.isfile(
                os.path.join("/opt/ros/%s" % default_underlay, 'share',
                             'catkin', 'cmake', 'toplevel.cmake')):
            catkin_toplevel = os.path.join("/opt/ros/%s" % default_underlay,
                                           'share', 'catkin', 'cmake',
                                           'toplevel.cmake')
            unused_catkin_python_path = os.path.join(
                "/opt/ros/%s" % default_underlay, 'lib', 'python2.7',
                'dist-packages')
            console.pretty_println(
                "No catkin found, adding the default underlay (use yujin_tools_settings to change) [/opt/ros/%s]"
                % default_underlay, console.cyan)
            underlays_list.append("/opt/ros/%s" % default_underlay)
        else:
            raise RuntimeError(
                "Could not find an underlying catkin installation.")
    common.create_symlink(catkin_toplevel,
                          os.path.join(build_source_dir, "CMakeLists.txt"))
    underlays = ';'.join(underlays_list)

    ##########################
    # Other Args
    ##########################
    if install_prefix_ == "/not_set_directory":
        install_prefix = os.path.join(build_dir, "install")
    else:
        install_prefix = install_prefix_

    if doc_prefix_ == "/not_set_directory":
        doc_prefix = os.path.join(build_dir, "doc")
    else:
        doc_prefix = doc_prefix_

    if release_:
        build_type = "Release"
    else:
        build_type = "RelWithDebInfo"
    name = os.path.basename(workspace_dir) + "_" + os.path.basename(build_dir)

    print_build_details(build_dir, source_dir, install_prefix, doc_prefix,
                        build_type, underlays, name, toolchain_, platform_)
    os.chdir(build_dir)

    ##########################
    # Toolchain
    ##########################
    if not toolchain_ == "":
        toolchains_dir = os.path.join(os.path.dirname(__file__), 'toolchains')
        custom_toolchains_dir = os.path.join(settings.yujin_tools_home(),
                                             'toolchains')
        tmp_list = toolchain_.split('/')
        if len(tmp_list) != 2:
            raise RuntimeError(
                "Toolchain specification invalid, must be <family>/<tuple> [%s]"
                % toolchain_)
        family = tmp_list[0]
        toolchain_tuple = tmp_list[1]
        toolchains = get_toolchains_or_platforms(toolchains_dir)
        custom_toolchains = get_toolchains_or_platforms(custom_toolchains_dir)
        if not family in toolchains and not family in custom_toolchains:
            raise RuntimeError("No toolchains available for family %s" %
                               family)
        if family in custom_toolchains and toolchain_tuple in custom_toolchains[
                family]:
            toolchain_file = os.path.join(custom_toolchains_dir, family,
                                          toolchain_tuple + ".cmake")
        elif family in toolchains and toolchain_tuple in toolchains[family]:
            toolchain_file = os.path.join(toolchains_dir, family,
                                          toolchain_tuple + ".cmake")
        else:
            raise RuntimeError("Platform %s for family %s not available." %
                               (family, toolchain_tuple))
        if os.path.isfile(toolchain_file):
            shutil.copy(toolchain_file,
                        os.path.join(build_dir, "toolchain.cmake"))
        else:
            raise RuntimeError("Toolchain module not available [%s]" %
                               toolchain_file)

    ##########################
    # Platform
    ##########################
    platform_content = ""
    platforms_dir = os.path.join(os.path.dirname(__file__), 'platforms')
    custom_platforms_dir = os.path.join(settings.yujin_tools_home(),
                                        'platforms')
    if not platform_ == "default":
        tmp_list = platform_.split('/')
        if len(tmp_list) != 2:
            raise RuntimeError(
                "Platform specification invalid, must be <family>/<platform type> [%s]"
                % platform_)
        family = tmp_list[0]
        platform = tmp_list[1]
        platforms = get_toolchains_or_platforms(platforms_dir)
        custom_platforms = get_toolchains_or_platforms(custom_platforms_dir)
        if not family in platforms and not family in custom_platforms:
            raise RuntimeError("No platforms available for family %s" % family)
        if family in custom_platforms and platform in custom_platforms[family]:
            platform_file = os.path.join(custom_platforms_dir, family,
                                         platform + ".cmake")
        elif family in platforms and platform in platforms[family]:
            platform_file = os.path.join(platforms_dir, family,
                                         platform + ".cmake")
        else:
            raise RuntimeError("Platform %s for family %s not available." %
                               (family, platform))
    else:
        platform_file = os.path.join(platforms_dir, 'default.cmake')

    if os.path.isfile(platform_file):
        f = open(platform_file, 'r')
        try:
            platform_content = f.read()
        finally:
            f.close()
    else:
        raise RuntimeError("Platform configuration not available [%s]" %
                           platform_)

    ##########################
    # Cache
    ##########################
    instantiate_config_cmake(platform_content, build_dir, build_type,
                             install_prefix, doc_prefix, underlays)

    ##########################
    # Templates
    ##########################
    instantiate_template('.bashrc', name, build_dir)
    instantiate_template('konsole', name, build_dir)
    instantiate_template('gnome-terminal', name, build_dir)
    instantiate_template('eclipse', name, build_dir)
    instantiate_template('android-studio', name, build_dir)