Example #1
0
def generate_dds_idl(generator_arguments_file, subfolders,
                     extension_module_name, additional_service_templates):
    mapping = {'idl.idl.em': os.path.join(*subfolders, '%s_.idl')}
    additional_context = {
        'additional_service_templates': additional_service_templates,
        'subfolders': subfolders,
        'get_post_struct_lines': get_post_struct_lines,
        'idl_typename': idl_typename,
        'idl_literal': idl_literal,
    }
    # Look for extensions for additional context
    if extension_module_name is not None:
        pkg = __import__(extension_module_name)
        module_name = extension_module_name.rsplit('.', 1)[1]
        if hasattr(pkg, module_name):
            module = getattr(pkg, module_name)
            for entity_name in additional_context.keys():
                if hasattr(module, entity_name):
                    additional_context[entity_name] = \
                        getattr(module, entity_name)
    generate_files(generator_arguments_file,
                   mapping,
                   additional_context,
                   keep_case=True)
    return 0
Example #2
0
def generate_cpp(generator_arguments_file, type_supports):
    mapping = {
        'idl__type_support.cpp.em': '%s__type_support.cpp',
    }
    generate_files(generator_arguments_file,
                   mapping,
                   additional_context={'type_supports': type_supports})
Example #3
0
def generate_idl(arguments_file):
    mapping = {
        'idl__rosidl_typesupport_opendds_cpp.idl.em':
        'dds_opendds/%s__RequestResponse.idl'
    }
    generate_files(arguments_file, mapping, None, True)
    return 0
Example #4
0
def generate_cpp(generator_arguments_file):
    mapping = {
        'idl.hpp.em': '%s.hpp',
        'idl__struct.hpp.em': '%s__struct.hpp',
        'idl__traits.hpp.em': '%s__traits.hpp',
    }
    generate_files(generator_arguments_file, mapping)
Example #5
0
def generate_cpp(generator_arguments_file):
    mapping = {
        'idl.hpp.em': '%s.hpp',
        'idl__struct.hpp.em': '%s__struct.hpp',
        'idl__traits.hpp.em': '%s__traits.hpp',
    }
    generate_files(generator_arguments_file, mapping)
def generate_typesupport_fastrtps_c(generator_arguments_file):
    mapping = {
        'idl__rosidl_typesupport_fastrtps_c.h.em':
        '%s__rosidl_typesupport_fastrtps_c.h',
        'idl__type_support_c.cpp.em': '%s__type_support_c.cpp',
    }
    generate_files(generator_arguments_file, mapping)
Example #7
0
def generate_cpp(generator_arguments_file):
    mapping = {
        'idl__rosidl_typesupport_introspection_cpp.hpp.em':
        'detail/%s__rosidl_typesupport_introspection_cpp.hpp',
        'idl__type_support.cpp.em': 'detail/%s__type_support.cpp',
    }
    generate_files(generator_arguments_file, mapping)
Example #8
0
def generate_c(generator_arguments_file):
    mapping = {
        'idl__rosidl_typesupport_introspection_c.h.em':
        '%s__rosidl_typesupport_introspection_c.h',
        'idl__type_support.c.em': '%s__type_support.c',
    }
    generate_files(generator_arguments_file, mapping)
Example #9
0
def generate_dds_idl(
    generator_arguments_file, subfolders, extension_module_name,
    additional_service_templates
):
    mapping = {
        'idl.idl.em': os.path.join(*subfolders, '%s_.idl')
    }
    additional_context = {
      'additional_service_templates': additional_service_templates,
      'subfolders': subfolders,
      'get_post_struct_lines': get_post_struct_lines,
      'idl_typename': idl_typename,
      'idl_literal': idl_literal,
    }
    # Look for extensions for additional context
    if extension_module_name is not None:
        pkg = __import__(extension_module_name)
        module_name = extension_module_name.rsplit('.', 1)[1]
        if hasattr(pkg, module_name):
            module = getattr(pkg, module_name)
            for entity_name in additional_context.keys():
                if hasattr(module, entity_name):
                    additional_context[entity_name] = \
                        getattr(module, entity_name)
    generate_files(generator_arguments_file, mapping, additional_context, keep_case=True)
    return 0
Example #10
0
def generate_typesupport_opensplice_cpp(arguments_file):
    mapping = {
       'idl__rosidl_typesupport_opensplice_cpp.hpp.em':  # noqa
           '%s__rosidl_typesupport_opensplice_cpp.hpp',
       'idl__dds_opensplice__type_support.cpp.em': 'dds_opensplice/%s__type_support.cpp',
    }

    generate_files(arguments_file, mapping)
Example #11
0
def generate_dotnet(generator_arguments_file, typesupport_impls):
    mapping = {
        'idl.cs.em': '%s.cs',
        'idl.c.em': '%s.c',
        'idl.h.em': 'rcldotnet_%s.h'
    }
    generate_files(generator_arguments_file, mapping)
    return 0
Example #12
0
def generate_cpp(generator_arguments_file):
    mapping = {
        "idl__rosidl_typesupport_protobuf_cpp.hpp.em":
        "%s__rosidl_typesupport_protobuf_cpp.hpp",
        "idl__type_support.cpp.em": "detail/%s__type_support.cpp",
    }
    generate_files(generator_arguments_file, mapping)
    return 0
Example #13
0
def generate_cpp(generator_arguments_file):
    mapping = {
        'idl__rosidl_typesupport_fastrtps_cpp.hpp.em':
        'detail/%s__rosidl_typesupport_fastrtps_cpp.hpp',
        'idl__type_support.cpp.em': 'detail/dds_fastrtps/%s__type_support.cpp',
    }
    generate_files(generator_arguments_file, mapping)
    return 0
Example #14
0
def generate_c(generator_arguments_file):
    mapping = {
        'idl.h.em': '%s.h',
        'idl__functions.c.em': '%s__functions.c',
        'idl__functions.h.em': '%s__functions.h',
        'idl__struct.h.em': '%s__struct.h',
        'idl__type_support.h.em': '%s__type_support.h',
    }
    generate_files(generator_arguments_file, mapping)
Example #15
0
def generate_c(generator_arguments_file):
    mapping = {
        'idl.h.em': '%s.h',
        'idl__functions.c.em': '%s__functions.c',
        'idl__functions.h.em': '%s__functions.h',
        'idl__struct.h.em': '%s__struct.h',
        'idl__type_support.h.em': '%s__type_support.h',
    }
    generate_files(generator_arguments_file, mapping)
Example #16
0
def generate_cpp(generator_arguments_file):
    mapping = {
        'idl.hpp.em': '%s.hpp',
        'idl__struct.hpp.em': '%s__struct.hpp',
        'idl__traits.hpp.em': '%s__traits.hpp',
    }
    generate_files(
        generator_arguments_file, mapping,
        post_process_callback=prefix_with_bom_if_necessary)
def generate_typesupport_opensplice_c(arguments_file):
    mapping = {
        'idl__rosidl_typesupport_opensplice_c.h.em':
        '%s__rosidl_typesupport_opensplice_c.h',
        'idl__dds_opensplice__type_support.c.em':
        'dds_opensplice_c/%s__type_support_c.cpp',
    }

    generate_files(arguments_file, mapping)
Example #18
0
def generate_cpp(arguments_file):
    mapping = {
        'idl__rosidl_typesupport_coredx_cpp.hpp.em':
        '%s__rosidl_typesupport_coredx_cpp.hpp',
        'idl__dds_coredx__type_support.cpp.em':
        'dds_coredx/%s__type_support.cpp'
    }
    generate_files(arguments_file, mapping)
    return 0
Example #19
0
def generate_typesupport_coredds_c(generator_arguments_file):
    mapping = {
        'idl__rosidl_typesupport_coredds_c.h.em':
        '%s__rosidl_typesupport_coredds_c.h',
        'idl__dds_coredds__type_support_c.cpp.em':
        'dds_coredds/%s__type_support_c.cpp',
    }
    generate_files(generator_arguments_file, mapping)
    return 0
def generate_typesupport_opendds_c(arguments_file):
    mapping = {
        'idl__rosidl_typesupport_opendds_c.h.em':
        '%s__rosidl_typesupport_opendds_c.h',
        'idl__dds_opendds__type_support_c.cpp.em':
        'dds_opendds/%s__type_support_c.cpp'
    }
    generate_files(arguments_file, mapping)
    return 0
Example #21
0
def generate_dotnet(generator_arguments_file, typesupport_impls):
    mapping = {'idl.cs.em': '%s.cs', 'idl.h.em': 'rcldotnet_%s.h'}
    generate_files(generator_arguments_file, mapping)

    typesupport_impls = typesupport_impls.split(';')
    for impl in typesupport_impls:
        typesupport_mapping = {'idl.c.em': '%s.ep.{0}.c'.format(impl)}
        generate_files(generator_arguments_file, typesupport_mapping)

    return 0
Example #22
0
def generate_c(generator_arguments_file):
    mapping = {
        'idl.h.em': '%s.h',
        'idl__functions.c.em': 'detail/%s__functions.c',
        'idl__functions.h.em': 'detail/%s__functions.h',
        'idl__struct.h.em': 'detail/%s__struct.h',
        'idl__type_support.h.em': 'detail/%s__type_support.h',
    }
    generate_files(generator_arguments_file,
                   mapping,
                   post_process_callback=prefix_with_bom_if_necessary)
Example #23
0
def generate_c(generator_arguments_file, type_supports):
    """
    Generate the C type support to handle ROS messages.

    :param generator_arguments_file: Path location of the file containing the generator arguments
    :param type_support: List of type supports to be used
    """
    mapping = {
        'idl__type_support.cpp.em': '%s__type_support.cpp',
    }
    generate_files(generator_arguments_file,
                   mapping,
                   additional_context={'type_supports': type_supports})
Example #24
0
def generate_typesupport_connext_c(arguments_file):
    mapping = {
        'idl__rosidl_typesupport_connext_c.h.em':
        '%s__rosidl_typesupport_connext_c.h',
        'idl__dds_connext__type_support_c.cpp.em':
        'dds_connext/%s__type_support_c.cpp'
    }
    return generate_files(arguments_file, mapping)
def generate_cs(generator_arguments_file, typesupport_impls):
    type_support_impl_by_filename = {
        '%s.ep.{0}.c'.format(impl): impl
        for impl in typesupport_impls
    }

    mapping = {'idl.cs.em': '%s.cs', 'idl.c.em': '%s_s.c'}

    #print("Type_support mapping " + str(type_support_impl_by_filename), file=sys.stderr)
    additional_context = {
        'get_field_name': get_field_name,
        'get_dotnet_type': get_dotnet_type,
        'constant_value_to_dotnet': constant_value_to_dotnet,
        'get_c_type': get_c_type,
        'get_marshal_type': get_marshal_type,
        'get_marshal_array_type': get_marshal_array_type
    }

    generate_files(generator_arguments_file, mapping, additional_context)
    for type_support in type_support_impl_by_filename.keys():
        typemapping = {'idl_typesupport.c.em': type_support}
        generate_files(generator_arguments_file, typemapping)
Example #26
0
def generate_swift(generator_arguments_file, typesupport_impls):
    mapping = {
        'idl.swift.em': '%s.swift',
        'idl.c.em': '%s.c',
        'idl.h.em': 'rclswift_%s.h',
    }
    
    generated_files = generate_files(generator_arguments_file, mapping)
    header_files = list(filter(lambda file: os.path.splitext(file)[1] == '.h', generated_files))
    args = read_generator_arguments(generator_arguments_file)
    data = {
        'package_name': args['package_name'],
        'headers': header_files,
    }
    template_basepath = pathlib.Path(args['template_dir'])
    generated_file = os.path.join(
                    args['output_dir'], 'module.modulemap')
    latest_target_timestamp = get_newest_modification_time(args['target_dependencies'])
    expand_template(os.path.basename('idl.modulemap.em'), data, generated_file, minimum_timestamp=latest_target_timestamp, template_basepath=template_basepath)
    return 0
Example #27
0
def generate(generator_arguments_file: str) -> List[str]:
    mapping = {
        "_idl.pyi.em": "_%s.pyi",
    }
    generated_files: List[str] = generate_files(generator_arguments_file,
                                                mapping)

    args = read_generator_arguments(generator_arguments_file)
    package_name = args["package_name"]

    # For __init__.pyi, it is required to output the exact same contents as
    # rosidl_python does.
    modules: Dict[str, Set[str]] = {}
    idl_content = IdlContent()
    for idl_tuple in args.get("idl_tuples", []):
        idl_parts = idl_tuple.rsplit(":", 1)
        assert len(idl_parts) == 2

        idl_rel_path = pathlib.Path(idl_parts[1])
        idl_stems = modules.setdefault(str(idl_rel_path.parent), set())
        idl_stems.add(idl_rel_path.stem)

        locator = IdlLocator(*idl_parts)
        idl_file = parse_idl_file(locator)
        idl_content.elements += idl_file.content.elements

    for subfolder in modules.keys():
        with open(os.path.join(args["output_dir"], subfolder, "__init__.pyi"),
                  "w") as f:
            for idl_stem in sorted(modules[subfolder]):
                module_name = "_{}".format(
                    convert_camel_case_to_lower_case_underscore(idl_stem))
                f.write(
                    f"from {package_name}.{subfolder}.{module_name} import "
                    f"{idl_stem} as {idl_stem}  # noqa: F401\n")

    return generated_files
def generate_py(generator_arguments_file, typesupport_impls):
    mapping = {
        '_idl.py.em': '_%s.py',
        '_idl_support.c.em': '_%s_s.c',
    }
    generate_files(generator_arguments_file, mapping)

    args = read_generator_arguments(generator_arguments_file)
    package_name = args['package_name']

    # expand init modules for each directory
    modules = {}
    idl_content = IdlContent()
    for idl_tuple in args.get('idl_tuples', []):
        idl_parts = idl_tuple.rsplit(':', 1)
        assert len(idl_parts) == 2

        idl_rel_path = pathlib.Path(idl_parts[1])
        idl_stems = modules.setdefault(str(idl_rel_path.parent), set())
        idl_stems.add(idl_rel_path.stem)

        locator = IdlLocator(*idl_parts)
        idl_file = parse_idl_file(locator)
        idl_content.elements += idl_file.content.elements

    # NOTE(sam): remove when a language specific name mangling is implemented

    def print_warning_if_reserved_keyword(member_name, interface_type,
                                          interface_name):
        if (keyword.iskeyword(member.name)):
            print("Member name '{}' in the {} '{}' is a "
                  'reserved keyword in Python and is not supported '
                  'at the moment. Please use a different name.'.format(
                      member_name, interface_type, interface_name),
                  file=sys.stderr)

    for message in idl_content.get_elements_of_type(Message):
        for member in message.structure.members:
            print_warning_if_reserved_keyword(
                member.name, 'message', message.structure.namespaced_type.name)

    for service in idl_content.get_elements_of_type(Service):
        for member in service.request_message.structure.members:
            print_warning_if_reserved_keyword(member.name, 'service request',
                                              service.namespaced_type.name)
        for member in service.response_message.structure.members:
            print_warning_if_reserved_keyword(member.name, 'service response',
                                              service.namespaced_type.name)

    for action in idl_content.get_elements_of_type(Action):
        for member in action.goal.structure.members:
            print_warning_if_reserved_keyword(member.name, 'action goal',
                                              action.namespaced_type.name)
        for member in action.feedback.structure.members:
            print_warning_if_reserved_keyword(member.name, 'action feedback',
                                              action.namespaced_type.name)
        for member in action.result.structure.members:
            print_warning_if_reserved_keyword(member.name, 'action result',
                                              action.namespaced_type.name)

    for subfolder in modules.keys():
        with open(os.path.join(args['output_dir'], subfolder, '__init__.py'),
                  'w') as f:
            for idl_stem in sorted(modules[subfolder]):
                module_name = '_' + \
                    convert_camel_case_to_lower_case_underscore(idl_stem)
                f.write(
                    f'from {package_name}.{subfolder}.{module_name} import '
                    f'{idl_stem}  # noqa: F401\n')

    # expand templates per available typesupport implementation
    template_dir = args['template_dir']
    type_support_impl_by_filename = {
        '_%s_s.ep.{0}.c'.format(impl): impl
        for impl in typesupport_impls
    }
    mapping_msg_pkg_extension = {
        os.path.join(template_dir, '_idl_pkg_typesupport_entry_point.c.em'):
        type_support_impl_by_filename.keys(),
    }

    for template_file in mapping_msg_pkg_extension.keys():
        assert os.path.exists(
            template_file), 'Could not find template: ' + template_file

    latest_target_timestamp = get_newest_modification_time(
        args['target_dependencies'])

    for template_file, generated_filenames in mapping_msg_pkg_extension.items(
    ):
        for generated_filename in generated_filenames:
            package_name = args['package_name']
            data = {
                'package_name':
                args['package_name'],
                'content':
                idl_content,
                'typesupport_impl':
                type_support_impl_by_filename.get(generated_filename, ''),
            }
            generated_file = os.path.join(args['output_dir'],
                                          generated_filename % package_name)
            expand_template(template_file,
                            data,
                            generated_file,
                            minimum_timestamp=latest_target_timestamp)

    return 0
Example #29
0
def generate_py(generator_arguments_file, typesupport_impls):
    mapping = {
        '_idl.py.em': '_%s.py',
        '_idl_support.c.em': '_%s_s.c',
    }
    generate_files(generator_arguments_file, mapping)

    args = read_generator_arguments(generator_arguments_file)
    package_name = args['package_name']

    # expand init modules for each directory
    modules = {}
    idl_content = IdlContent()
    for idl_tuple in args.get('idl_tuples', []):
        idl_parts = idl_tuple.rsplit(':', 1)
        assert len(idl_parts) == 2

        idl_rel_path = pathlib.Path(idl_parts[1])
        idl_stems = modules.setdefault(str(idl_rel_path.parent), set())
        idl_stems.add(idl_rel_path.stem)

        locator = IdlLocator(*idl_parts)
        idl_file = parse_idl_file(locator)
        idl_content.elements += idl_file.content.elements

    for subfolder in modules.keys():
        with open(os.path.join(args['output_dir'], subfolder, '__init__.py'),
                  'w') as f:
            for idl_stem in sorted(modules[subfolder]):
                module_name = '_' + \
                    convert_camel_case_to_lower_case_underscore(idl_stem)
                f.write('from {package_name}.{subfolder}.{module_name} import '
                        '{idl_stem}  # noqa: F401\n'.format_map(locals()))

    # expand templates per available typesupport implementation
    template_dir = args['template_dir']
    type_support_impl_by_filename = {
        '_%s_s.ep.{0}.c'.format(impl): impl
        for impl in typesupport_impls
    }
    mapping_msg_pkg_extension = {
        os.path.join(template_dir, '_idl_pkg_typesupport_entry_point.c.em'):
        type_support_impl_by_filename.keys(),
    }

    for template_file in mapping_msg_pkg_extension.keys():
        assert os.path.exists(
            template_file), 'Could not find template: ' + template_file

    latest_target_timestamp = get_newest_modification_time(
        args['target_dependencies'])

    for template_file, generated_filenames in mapping_msg_pkg_extension.items(
    ):
        for generated_filename in generated_filenames:
            package_name = args['package_name']
            data = {
                'package_name':
                args['package_name'],
                'content':
                idl_content,
                'typesupport_impl':
                type_support_impl_by_filename.get(generated_filename, ''),
            }
            generated_file = os.path.join(args['output_dir'],
                                          generated_filename % package_name)
            expand_template(template_file,
                            data,
                            generated_file,
                            minimum_timestamp=latest_target_timestamp)

    return 0
def generate_proto(generator_arguments_file):
    mapping = {
        'idl.proto.em': '%s.proto',
    }
    generate_files(generator_arguments_file, mapping, keep_case=True)
    return 0
def generate_typesupport_protobuf_c(generator_arguments_file):
    mapping = {
        'idl__rosidl_typesupport_protobuf_c.hpp.em': '%s__rosidl_typesupport_protobuf_c.hpp',
        'idl__type_support.cpp.em': 'detail/%s__type_support.cpp',
    }
    generate_files(generator_arguments_file, mapping)