예제 #1
0
파일: make.py 프로젝트: zaxrok/yujin_tools
def install_rosdeps(base_path, source_path, rosdistro, no_color):
    # -r continue even with errors
    cmd = ['rosdep', 'install'
           ]  # if you want it to continue installing despite errors, '-r']
    underlays = config_cache.get_underlays_list_from_config_cmake(base_path)
    print("Rosdep Search Paths")
    for underlay in underlays:
        underlay_path = underlay
        underlay_source_path = os.path.abspath(
            os.path.join(underlay, os.pardir, "src"))
        if os.path.isdir(underlay_source_path):
            underlay_path = underlay_source_path
        if os.path.isdir(underlay_path):
            cmd += ['--from-paths', underlay_path]
            print(" - adding underlay '%s'" % underlay_path)
        else:
            print(" - not adding underlay '%s' [not found]" % underlay_path)
    cmd += [
        '--from-paths', source_path, '--ignore-src', '--rosdistro', rosdistro,
        '-y'
    ]
    env = os.environ.copy()
    try:
        builder.print_command_banner(cmd, source_path, color=not no_color)
        if no_color:
            builder.run_command(cmd, source_path, env=env)
        else:
            builder.run_command_colorized(cmd, source_path, env=env)
    except subprocess.CalledProcessError:
        return 1  # rosdep will already have provided its own error message, no need to regurgitate
    return 0
예제 #2
0
def install_rosdeps(base_path, source_path, rosdistro, no_color):
    # -r continue even with errors
    cmd = ['rosdep', 'install']  # if you want it to continue installing despite errors, '-r']
    underlays = config_cache.get_underlays_list_from_config_cmake(base_path)
    print("Rosdep Search Paths")
    for underlay in underlays:
        underlay_path = underlay
        underlay_source_path = os.path.abspath(os.path.join(underlay, os.pardir, "src"))
        if os.path.isdir(underlay_source_path):
	    underlay_path = underlay_source_path
        if os.path.isdir(underlay_path):
            cmd += ['--from-paths', underlay_path]
	    print(" - adding underlay '%s'" % underlay_path)
        else:
	    print(" - not adding underlay '%s' [not found]" % underlay_path)
    cmd += ['--from-paths', source_path, '--ignore-src', '--rosdistro', rosdistro, '-y']
    env = os.environ.copy()
    try:
        builder.print_command_banner(cmd, source_path, color=not no_color)
        if no_color:
            builder.run_command(cmd, source_path, env=env)
        else:
            builder.run_command_colorized(cmd, source_path, env=env)
    except subprocess.CalledProcessError:
        return 1  # rosdep will already have provided its own error message, no need to regurgitate
    return 0
예제 #3
0
def generate_pkg_config_path(base_path):
    '''
      Generate a list of pkg_config_paths from the underlays

      @param base_path : used to find the config.cmake which lists the underlays
      @return list of paths
    '''
    underlays_list = config_cache.get_underlays_list_from_config_cmake(base_path)
    pkg_config_path = []
    for underlay in underlays_list:
        if os.path.isdir(os.path.join(underlay, 'lib', 'pkgconfig')):
            pkg_config_path.append(os.path.join(underlay, 'lib', 'pkgconfig'))
    return pkg_config_path
예제 #4
0
def generate_pkg_config_path(base_path):
    '''
      Generate a list of pkg_config_paths from the underlays

      @param base_path : used to find the config.cmake which lists the underlays
      @return list of paths
    '''
    underlays_list = config_cache.get_underlays_list_from_config_cmake(
        base_path)
    pkg_config_path = []
    for underlay in underlays_list:
        if os.path.isdir(os.path.join(underlay, 'lib', 'pkgconfig')):
            pkg_config_path.append(os.path.join(underlay, 'lib', 'pkgconfig'))
    return pkg_config_path
예제 #5
0
def generate_underlay_environment(base_path):
    '''
      Parse all the underlay environment scripts to setup an initial environment for us to work in. This
      should be easier than manually crafting everything. We do maintain some more complexity than
      catkin_make though as we support a pyramid of underlays, not a linear chain.

      UNUSED and UNTESTED!
    '''
    underlays_list = config_cache.get_underlays_list_from_config_cmake(
        base_path)
    env = os.environ.copy()
    for underlay in reversed(underlays_list):
        print("\nUnderlay: %s" % underlay)
        env_script = os.path.join(underlay, 'env.sh')
        # Should validate that the script exists
        python_code = 'import os; print(dict(os.environ))'
        print[env_script, sys.executable, '-c', python_code]
        output = subprocess.check_output(
            [env_script, sys.executable, '-c', python_code])
        print output
        # Not really positive what's going on here - this is what is in catkin.environment_cache.generate_environment_scripot
        # I think it just safely decodes strings in the dictionary.
        if hasattr(sys.stdout, 'encoding') and sys.stdout.encoding:
            output = output.decode(sys.stdout.encoding)
        env_after = ast.literal_eval(output)
        # calculate added and modified environment variables
        modified = {}
        for key, value in env_after.items():
            if key not in env:
                env[key] = value
            elif env[key] != value:
                # Need to be careful here - we are dealing with paths that will need to be merged.
                modified[key] = [env[key], value]
        # Deal with modified keys
        for key in sorted(modified.keys()):
            (old_value, new_value) = modified[key]
            if (key.contains('PATH') or old_value.contains(os.pathsep)
                    or new_value.contains(os.pathsep)):
                # Merge paths
                old_elements = os.pathsep.split(old_value)
                new_elements = os.pathsep.split(new_value)
                for element in new_elements:
                    if not old_elements.contains(element):
                        env[key] = env[key] + os.pathsep + element
            else:
                # it's a regular variable - take the latest value assigned to it (not we're sorting underlays in the correct (reverse) order of priority
                env[key] = new_value
    return env
예제 #6
0
def install_rosdeps(base_path, source_path, rosdistro, no_color):
    # -r continue even with errors
    cmd = ['rosdep', 'install', '-r']
    underlays = config_cache.get_underlays_list_from_config_cmake(base_path)
    for underlay in underlays:
        cmd += ['--from-paths', underlay]
    cmd += ['--from-paths', source_path, '--ignore-src', '--rosdistro', rosdistro, '-y']
    env = os.environ.copy()
    try:
        builder.print_command_banner(cmd, source_path, color=not no_color)
        if no_color:
            builder.run_command(cmd, source_path, env=env)
        else:
            builder.run_command_colorized(cmd, source_path, env=env)
    except subprocess.CalledProcessError:
        return fmt('@{rf}Invoking @{boldon}"rosdep install failed')
예제 #7
0
def find_catkin(base_path, underlays_list=None):
    '''
      Search the underlays looking for catkin's toplevel.cmake and python module.
    '''
    if underlays_list is None:
        underlays_list = config_cache.get_underlays_list_from_config_cmake(base_path)
    catkin_toplevel = None
    catkin_python_path = None
    catkin_cmake_path = None
    for underlay in underlays_list:
        if os.path.isfile(os.path.join(underlay, 'share', 'catkin', 'cmake', 'toplevel.cmake')):
            catkin_cmake_path = os.path.join(underlay, 'share', 'catkin', 'cmake')
            catkin_toplevel = os.path.join(underlay, 'share', 'catkin', 'cmake', 'toplevel.cmake')
            if os.path.isfile(os.path.join(underlay, python_setup.get_global_python_destination(), 'catkin', 'builder.py')):
                catkin_python_path = os.path.join(underlay, python_setup.get_global_python_destination())
            break
    return catkin_toplevel, catkin_python_path, catkin_cmake_path
예제 #8
0
def generate_underlay_environment(base_path):
    '''
      Parse all the underlay environment scripts to setup an initial environment for us to work in. This
      should be easier than manually crafting everything. We do maintain some more complexity than
      catkin_make though as we support a pyramid of underlays, not a linear chain.

      UNUSED and UNTESTED!
    '''
    underlays_list = config_cache.get_underlays_list_from_config_cmake(base_path)
    env = os.environ.copy()
    for underlay in reversed(underlays_list):
        print("\nUnderlay: %s" % underlay)
        env_script = os.path.join(underlay, 'env.sh')
        # Should validate that the script exists
        python_code = 'import os; print(dict(os.environ))'
        print [env_script, sys.executable, '-c', python_code]
        output = subprocess.check_output([env_script, sys.executable, '-c', python_code])
        print output
        # Not really positive what's going on here - this is what is in catkin.environment_cache.generate_environment_scripot
        # I think it just safely decodes strings in the dictionary.
        if hasattr(sys.stdout, 'encoding') and sys.stdout.encoding:
            output = output.decode(sys.stdout.encoding)
        env_after = ast.literal_eval(output)
        # calculate added and modified environment variables
        modified = {}
        for key, value in env_after.items():
            if key not in env:
                env[key] = value
            elif env[key] != value:
                # Need to be careful here - we are dealing with paths that will need to be merged.
                modified[key] = [env[key], value]
        # Deal with modified keys
        for key in sorted(modified.keys()):
            (old_value, new_value) = modified[key]
            if(key.contains('PATH') or old_value.contains(os.pathsep) or new_value.contains(os.pathsep)):
                # Merge paths
                old_elements = os.pathsep.split(old_value)
                new_elements = os.pathsep.split(new_value)
                for element in new_elements:
                    if not old_elements.contains(element):
                        env[key] = env[key] + os.pathsep + element
            else:
                # it's a regular variable - take the latest value assigned to it (not we're sorting underlays in the correct (reverse) order of priority
                env[key] = new_value
    return env
예제 #9
0
def find_catkin(base_path, underlays_list=None):
    '''
      Search the underlays looking for catkin's toplevel.cmake and python module.
    '''
    if underlays_list is None:
        underlays_list = config_cache.get_underlays_list_from_config_cmake(base_path)
    catkin_toplevel = None
    catkin_python_path = None
    catkin_cmake_path = None
    for underlay in underlays_list:
        if os.path.isfile(os.path.join(underlay, 'share', 'catkin', 'cmake', 'toplevel.cmake')):
            # it is in an underlay's install space
            catkin_cmake_path = os.path.join(underlay, 'share', 'catkin', 'cmake')
            catkin_toplevel = os.path.join(underlay, 'share', 'catkin', 'cmake', 'toplevel.cmake')
            if os.path.isfile(os.path.join(underlay, python_setup.get_global_python_destination(), 'catkin', 'builder.py')):
                catkin_python_path = os.path.join(underlay, python_setup.get_global_python_destination())
            break
        elif os.path.isfile(os.path.join(underlay, python_setup.get_global_python_destination(), 'catkin', '__init__.py')):
            # it's probably a devel space
            console.error('Error: catkin seems to be buried in a chained devel space - not yet supporting this')
            # catkin_python_path = os.path.join(underlay, python_setup.get_global_python_destination())
            break
    return catkin_toplevel, catkin_python_path, catkin_cmake_path
예제 #10
0
def find_catkin(base_path, underlays_list=None):
    '''
      Search the underlays looking for catkin's toplevel.cmake and python module.
    '''
    if underlays_list is None:
        underlays_list = config_cache.get_underlays_list_from_config_cmake(
            base_path)
    catkin_toplevel = None
    catkin_python_path = None
    catkin_cmake_path = None
    for underlay in underlays_list:
        if os.path.isfile(
                os.path.join(underlay, 'share', 'catkin', 'cmake',
                             'toplevel.cmake')):
            # it is in an underlay's install space
            catkin_cmake_path = os.path.join(underlay, 'share', 'catkin',
                                             'cmake')
            catkin_toplevel = os.path.join(underlay, 'share', 'catkin',
                                           'cmake', 'toplevel.cmake')
            if os.path.isfile(
                    os.path.join(underlay,
                                 python_setup.get_global_python_destination(),
                                 'catkin', 'builder.py')):
                catkin_python_path = os.path.join(
                    underlay, python_setup.get_global_python_destination())
            break
        elif os.path.isfile(
                os.path.join(underlay,
                             python_setup.get_global_python_destination(),
                             'catkin', '__init__.py')):
            # it's probably a devel space
            console.error(
                'Error: catkin seems to be buried in a chained devel space - not yet supporting this'
            )
            # catkin_python_path = os.path.join(underlay, python_setup.get_global_python_destination())
            break
    return catkin_toplevel, catkin_python_path, catkin_cmake_path