示例#1
0
def expand_package_level_setup_files(context, environment_hooks, environment_hooks_path):
    destinations = []

    for name in get_package_level_template_names():
        assert name.endswith('.in')

        local_environment_hooks = []
        if os.path.splitext(name[:-3])[1] in ['.sh', '.bat']:
            local_environment_hooks.extend(environment_hooks)

        # check if any data files are environment hooks (Python only)
        for data_file in context.get('setup.py', {}).get('data_files', {}).values():
            if not data_file.startswith(environment_hooks_path):
                continue
            # ignore data files with different extensions
            if os.path.splitext(data_file)[1] != os.path.splitext(name[:-3])[1]:
                continue
            local_environment_hooks.append(data_file)

        template_path = get_package_level_template_path(name)
        variables = {'CMAKE_INSTALL_PREFIX': context.install_space}
        if name[:-3].endswith('.bat'):
            variables['PROJECT_NAME'] = context.package_manifest.name
        if local_environment_hooks:
            if name[:-3].endswith('.bat'):
                t = 'call:ament_append_value AMENT_ENVIRONMENT_HOOKS[%s] "%s"\n'
                variables['ENVIRONMENT_HOOKS'] = t % (
                    context.package_manifest.name,
                    ';'.join([
                        os.path.join('%AMENT_CURRENT_PREFIX%', environment_hook)
                        for environment_hook in local_environment_hooks
                    ])
                )
            else:
                variables['ENVIRONMENT_HOOKS'] = \
                    'ament_append_value AMENT_ENVIRONMENT_HOOKS "%s"\n' % \
                    ':'.join([
                        os.path.join('$AMENT_CURRENT_PREFIX', environment_hook)
                        for environment_hook in local_environment_hooks
                    ])
        content = configure_file(template_path, variables)
        destination_path = os.path.join(
            context.build_space,
            'share', context.package_manifest.name,
            name[:-3])
        destination_dir = os.path.dirname(destination_path)
        if not os.path.exists(destination_dir):
            os.makedirs(destination_dir)
        destinations.append(destination_path)
        with open(destination_path, 'w') as h:
            h.write(content)

    return destinations
示例#2
0
    def _build_action(self, context):
        ext = '.sh' if not IS_WINDOWS else '.bat'
        path_environment_hook = os.path.join(
            'share', context.package_manifest.name, 'environment', 'path' + ext)
        # expand environment hook for PYTHONPATH
        ext = '.sh.in' if not IS_WINDOWS else '.bat.in'
        template_path = get_environment_hook_template_path('pythonpath' + ext)
        content = configure_file(template_path, {
            'PYTHON_INSTALL_DIR': self._get_python_lib(context),
        })
        pythonpath_environment_hook = os.path.join(
            'share', context.package_manifest.name, 'environment',
            os.path.basename(template_path)[:-3])
        destination_path = os.path.join(
            context.build_space, pythonpath_environment_hook)
        destination_dir = os.path.dirname(destination_path)
        if not os.path.exists(destination_dir):
            os.makedirs(destination_dir)
        with open(destination_path, 'w') as h:
            h.write(content)

        # expand package-level setup files
        for name in get_package_level_template_names():
            assert name.endswith('.in')
            template_path = get_package_level_template_path(name)
            variables = {'CMAKE_INSTALL_PREFIX': context.install_space}
            if name[:-3].endswith('.sh'):
                variables['ENVIRONMENT_HOOKS'] = \
                    'ament_append_value AMENT_ENVIRONMENT_HOOKS "%s"\n' % \
                    ':'.join([
                        os.path.join('$AMENT_CURRENT_PREFIX', path_environment_hook),
                        os.path.join('$AMENT_CURRENT_PREFIX', pythonpath_environment_hook),
                    ])
            elif name[:-3].endswith('.bat'):
                t = 'call:ament_append_value AMENT_ENVIRONMENT_HOOKS[%s] "%s"\n'
                variables['ENVIRONMENT_HOOKS'] = t % (
                    context.package_manifest.name,
                    ';'.join([
                        os.path.join('%AMENT_CURRENT_PREFIX%', path_environment_hook),
                        os.path.join('%AMENT_CURRENT_PREFIX%', pythonpath_environment_hook),
                    ])
                )
                variables['PROJECT_NAME'] = context.package_manifest.name
            content = configure_file(template_path, variables)
            destination_path = os.path.join(
                context.build_space,
                'share', context.package_manifest.name,
                name[:-3])
            with open(destination_path, 'w') as h:
                h.write(content)
示例#3
0
def generate_cmake_code():
    """
    Return a list of CMake set() commands containing the template information.

    :returns: list of str
    """
    variables = []

    if not IS_WINDOWS:
        variables.append((
            'ENVIRONMENT_HOOK_LIBRARY_PATH',
            '"%s"' % get_environment_hook_template_path('library_path.sh')))
    else:
        variables.append(('ENVIRONMENT_HOOK_LIBRARY_PATH', ''))

    ext = '.bat.in' if IS_WINDOWS else '.sh.in'
    variables.append((
        'ENVIRONMENT_HOOK_PYTHONPATH',
        '"%s"' % get_environment_hook_template_path('pythonpath' + ext)))

    templates = []
    for name in get_package_level_template_names():
        templates.append('"%s"' % get_package_level_template_path(name))
    variables.append((
        'PACKAGE_LEVEL',
        templates))

    templates = []
    for name in get_prefix_level_template_names():
        templates.append('"%s"' % get_prefix_level_template_path(name))
    variables.append((
        'PREFIX_LEVEL',
        templates))

    lines = []
    for (k, v) in variables:
        if isinstance(v, list):
            lines.append('set(ament_cmake_package_templates_%s "")' % k)
            for vv in v:
                lines.append('list(APPEND ament_cmake_package_templates_%s %s)'
                             % (k, vv))
        else:
            lines.append('set(ament_cmake_package_templates_%s %s)' % (k, v))
    # Ensure backslashes are replaced with forward slashes because CMake cannot
    # parse files with backslashes in it.
    return [l.replace('\\', '/') for l in lines]