예제 #1
0
    def _uninstall_action_files(self, context):
        files = [
            # package manifest
            os.path.join('share', context.package_manifest.name, 'package.xml'),
            # marker file
            os.path.join(
                'share', 'ament_index', 'resource_index', 'packages',
                context.package_manifest.name),
        ]
        # environment hooks
        for env_hook_name in ['path', 'pythonpath']:
            deploy_file = env_hook_name + ('.sh' if not IS_WINDOWS else '.bat')
            files.append(
                os.path.join('share', context.package_manifest.name, 'environment', deploy_file))
        # package-level setup files
        for name in get_package_level_template_names():
            assert name.endswith('.in')
            files.append(os.path.join('share', context.package_manifest.name, name[:-3]))

        # remove all files
        for rel_path in files:
            abs_path = os.path.join(context.install_space, rel_path)
            if os.path.exists(abs_path):
                os.remove(abs_path)
                self._remove_empty_directories(context, os.path.dirname(abs_path))
예제 #2
0
    def _uninstall_action_files(self, context):
        files = [
            # package manifest
            os.path.join('share', context.package_manifest.name,
                         'package.xml'),
            # marker file
            os.path.join('share', 'ament_index', 'resource_index', 'packages',
                         context.package_manifest.name),
        ]
        # environment hooks
        for env_hook_name in ['path', 'pythonpath']:
            deploy_file = env_hook_name + ('.sh' if not IS_WINDOWS else '.bat')
            files.append(
                os.path.join('share', context.package_manifest.name,
                             'environment', deploy_file))
        # package-level setup files
        for name in get_package_level_template_names():
            assert name.endswith('.in')
            files.append(
                os.path.join('share', context.package_manifest.name,
                             name[:-3]))

        # remove all files
        for rel_path in files:
            abs_path = os.path.join(context.install_space, rel_path)
            if os.path.exists(abs_path):
                os.remove(abs_path)
                self._remove_empty_directories(context,
                                               os.path.dirname(abs_path))
예제 #3
0
    def on_install(self, context):
        # deploy package manifest
        deploy_file(context,
                    context.source_space,
                    'package.xml',
                    dst_subfolder=os.path.join('share',
                                               context.package_manifest.name))

        # create marker file
        marker_file = os.path.join(context.install_space, 'share',
                                   'ament_index', 'resource_index', 'packages',
                                   context.package_manifest.name)
        if not os.path.exists(marker_file):
            marker_dir = os.path.dirname(marker_file)
            if not os.path.exists(marker_dir):
                os.makedirs(marker_dir)
            with open(marker_file, 'w'):  # "touching" the file
                pass

        ext = '.sh' if not IS_WINDOWS else '.bat'
        # deploy AMENT_PREFIX_PATH environment hook
        app_template_path = get_environment_hook_template_path(
            'ament_prefix_path' + ext)
        deploy_file(context,
                    os.path.dirname(app_template_path),
                    os.path.basename(app_template_path),
                    dst_subfolder=os.path.join('share',
                                               context.package_manifest.name,
                                               'environment'))

        # deploy PATH environment hook
        path_template_path = get_environment_hook_template_path('path' + ext)
        deploy_file(context,
                    os.path.dirname(path_template_path),
                    os.path.basename(path_template_path),
                    dst_subfolder=os.path.join('share',
                                               context.package_manifest.name,
                                               'environment'))

        # deploy CLASSPATH environment hook
        destination_file = 'classpath' + ('.sh' if not IS_WINDOWS else '.bat')
        deploy_file(
            context, context.build_space,
            os.path.join('share', context.package_manifest.name, 'environment',
                         destination_file))

        # deploy package-level setup files
        for name in get_package_level_template_names():
            assert name.endswith('.in')
            deploy_file(
                context, context.build_space,
                os.path.join('share', context.package_manifest.name,
                             name[:-3]))

        yield BuildAction(self._prepare_cmd(context, gradle_task='assemble'),
                          cwd=context.build_space)
예제 #4
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
예제 #5
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)
예제 #6
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)
예제 #7
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]
예제 #8
0
    def _install_action_files(self, context):
        # deploy package manifest
        deploy_file(context,
                    context.source_space,
                    'package.xml',
                    dst_subfolder=os.path.join('share',
                                               context.package_manifest.name))

        # create marker file
        marker_file = os.path.join(context.install_space, 'share',
                                   'ament_index', 'resource_index', 'packages',
                                   context.package_manifest.name)
        if not os.path.exists(marker_file):
            marker_dir = os.path.dirname(marker_file)
            if not os.path.exists(marker_dir):
                os.makedirs(marker_dir)
            with open(marker_file, 'w'):  # "touching" the file
                pass

        # deploy PATH environment hook
        ext = '.sh' if not IS_WINDOWS else '.bat'
        template_path = get_environment_hook_template_path('path' + ext)
        deploy_file(context,
                    os.path.dirname(template_path),
                    os.path.basename(template_path),
                    dst_subfolder=os.path.join('share',
                                               context.package_manifest.name,
                                               'environment'),
                    executable=True)

        # deploy PYTHONPATH environment hook
        destination_file = 'pythonpath' + ('.sh' if not IS_WINDOWS else '.bat')
        deploy_file(context,
                    context.build_space,
                    os.path.join('share', context.package_manifest.name,
                                 'environment', destination_file),
                    executable=True)

        # deploy package-level setup files
        for name in get_package_level_template_names():
            assert name.endswith('.in')
            deploy_file(context,
                        context.build_space,
                        os.path.join('share', context.package_manifest.name,
                                     name[:-3]),
                        executable=True)
예제 #9
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]
예제 #10
0
    def _install_action_files(self, context):
        # deploy package manifest
        deploy_file(
            context, context.source_space, 'package.xml',
            dst_subfolder=os.path.join('share', context.package_manifest.name))

        # create marker file
        marker_file = os.path.join(
            context.install_space,
            'share', 'ament_index', 'resource_index', 'packages',
            context.package_manifest.name)
        if not os.path.exists(marker_file):
            marker_dir = os.path.dirname(marker_file)
            os.makedirs(marker_dir, exist_ok=True)
            with open(marker_file, 'w'):  # "touching" the file
                pass

        ext = '.sh' if not IS_WINDOWS else '.bat'
        # deploy AMENT_PREFIX_PATH environment hook
        app_template_path = get_environment_hook_template_path('ament_prefix_path' + ext)
        deploy_file(
            context, os.path.dirname(app_template_path), os.path.basename(app_template_path),
            dst_subfolder=os.path.join('share', context.package_manifest.name, 'environment'))

        # deploy PATH environment hook
        path_template_path = get_environment_hook_template_path('path' + ext)
        deploy_file(
            context, os.path.dirname(path_template_path), os.path.basename(path_template_path),
            dst_subfolder=os.path.join('share', context.package_manifest.name, 'environment'))

        # deploy PYTHONPATH environment hook
        destination_file = 'pythonpath' + ('.sh' if not IS_WINDOWS else '.bat')
        deploy_file(
            context, context.build_space,
            os.path.join(
                'share', context.package_manifest.name, 'environment',
                destination_file))

        # deploy package-level setup files
        for name in get_package_level_template_names():
            assert name.endswith('.in')
            deploy_file(
                context, context.build_space,
                os.path.join(
                    'share', context.package_manifest.name, name[:-3]))
예제 #11
0
    def on_install(self, context):
        # deploy PATH environment hook
        ext = '.sh' if not IS_WINDOWS else '.bat'
        template_path = get_environment_hook_template_path('path' + ext)
        deploy_file(context,
                    os.path.dirname(template_path),
                    os.path.basename(template_path),
                    dst_subfolder=os.path.join('share',
                                               context.package_manifest.name,
                                               'environment'))

        # deploy JAVAPATH environment hook
        destination_file = 'javapath' + ('.sh' if not IS_WINDOWS else '.bat')
        deploy_file(
            context, context.build_space,
            os.path.join('share', context.package_manifest.name, 'environment',
                         destination_file))

        # create marker file
        marker_file = os.path.join(context.install_space, 'share',
                                   'ament_index', 'resource_index', 'packages',
                                   context.package_manifest.name)
        if not os.path.exists(marker_file):
            marker_dir = os.path.dirname(marker_file)
            if not os.path.exists(marker_dir):
                os.makedirs(marker_dir)
            with open(marker_file, 'w'):  # "touching" the file
                pass

        for name in get_package_level_template_names():
            assert name.endswith('.in')
            deploy_file(
                context, context.build_space,
                os.path.join('share', context.package_manifest.name,
                             name[:-3]))

        cmd_args = [
            '-Pament.build_space=' + context.build_space,
            '-Pament.install_space=' + context.install_space,
            '-Pament.dependencies=' + ':'.join(context.build_dependencies),
            '-Pament.build_tests=' + str(context.build_tests),
        ]

        cmd_args += context.ament_gradle_args

        cmd = [get_gradle_executable(context)]
        cmd += cmd_args
        cmd += ['assemble']

        yield BuildAction(cmd, cwd=context.source_space)

        #Deploy libs dependencies
        filesDir = os.path.join(context.build_space, 'lib', 'java')
        if os.path.exists(filesDir):
            for filename in os.listdir(filesDir):
                deploy_file(
                    context, context.build_space,
                    os.path.join('lib', 'java', os.path.basename(filename)))

        #Deploy share files
        self.deploy_files(
            context,
            os.path.join('share', context.package_manifest.name, 'java'))

        #Deploy scripts
        filesDir = os.path.join(context.build_space, 'bin')
        if os.path.exists(filesDir):
            for filename in os.listdir(filesDir):
                deploy_file(context, context.build_space,
                            os.path.join('bin', os.path.basename(filename)))