Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds streamline file generation #23

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 17 additions & 24 deletions rosidl_typesupport_protobuf/rosidl_typesupport_protobuf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,8 @@
# A postfix for the protobuf package name / the c++ namespace
PROTO_PACKAGE_POSTFIX = 'pb'

_TYPE_SUPPORT_NAME = ''
_NAMESPACE_DELIMETER = ''


def set_type_support_name(val):
global _TYPE_SUPPORT_NAME
_TYPE_SUPPORT_NAME = val


def set_namespace_delimeter(val):
global _NAMESPACE_DELIMETER
_NAMESPACE_DELIMETER = val
Expand Down Expand Up @@ -85,56 +78,56 @@ def protobuf_message_header(package_name, interface_path):
return '/'.join(include_parts + [include_prefix + '.pb.h'])


def typesupport_header(package_name, interface_path):
def typesupport_header(package_name, interface_path, typesupport_name):
include_parts = [package_name] + list(interface_path.parents[0].parts) + \
[convert_camel_case_to_lower_case_underscore(interface_path.stem)]
include_base = '/'.join(include_parts)

return f'{include_base}__{_TYPE_SUPPORT_NAME}.hpp'
return f'{include_base}__{typesupport_name}.hpp'


def visibility_control_header(package_name):
return f'{package_name}/{_TYPE_SUPPORT_NAME}__visibility_control.h'
def visibility_control_header(package_name, typesupport_name):
return f'{package_name}/{typesupport_name}__visibility_control.h'


def adapter_visibility_control_header(package_name):
return f'{package_name}/rosidl_adapter_proto__visibility_control.h'


def ros_type_namespace(package_name, interface_path):
return _NAMESPACE_DELIMETER.join([package_name] + list(interface_path.parents[0].parts))
def ros_type_namespace(package_name, interface_path, namespace_delimiter):
return namespace_delimiter.join([package_name] + list(interface_path.parents[0].parts))


def ros_type_name(message):
return message.structure.namespaced_type.name


def ros_type(package_name, interface_path, message):
ros_type_ns = ros_type_namespace(package_name, interface_path)
def ros_type(package_name, interface_path, message, namespace_delimiter):
ros_type_ns = ros_type_namespace(package_name, interface_path, namespace_delimiter)
ros_type_nm = ros_type_name(message)
return '::' + _NAMESPACE_DELIMETER.join([ros_type_ns, ros_type_nm])
return '::' + namespace_delimiter.join([ros_type_ns, ros_type_nm])


def ros_type_from_namespaced_type(namespaced_type):
return '::' + _NAMESPACE_DELIMETER.join(namespaced_type.namespaces + [namespaced_type.name])
def ros_type_from_namespaced_type(namespaced_type, namespace_delimiter):
return '::' + namespace_delimiter.join(namespaced_type.namespaces + [namespaced_type.name])


def ros_type_from_namespaced_type_c(namespaced_type):
return '::' + _NAMESPACE_DELIMETER.join(namespaced_type.namespaces + [namespaced_type.name])
return '::' + '__'.join(namespaced_type.namespaces + [namespaced_type.name])


def ros_service_namespace(package_name, interface_path):
return _NAMESPACE_DELIMETER.join([package_name] + list(interface_path.parents[0].parts))
def ros_service_namespace(package_name, interface_path, namespace_delimiter):
return namespace_delimiter.join([package_name] + list(interface_path.parents[0].parts))


def ros_service_name(service):
return service.namespaced_type.name


def ros_service_type(package_name, interface_path, service):
ros_type_ns = ros_service_namespace(package_name, interface_path)
def ros_service_type(package_name, interface_path, service, namespace_delimiter):
ros_type_ns = ros_service_namespace(package_name, interface_path, namespace_delimiter)
ros_type_nm = ros_service_name(service)
return '::' + _NAMESPACE_DELIMETER.join([ros_type_ns, ros_type_nm])
return '::' + namespace_delimiter.join([ros_type_ns, ros_type_nm])


def protobuf_type(package_name, interface_path, message):
Expand Down
5 changes: 0 additions & 5 deletions rosidl_typesupport_protobuf_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ ament_package(
CONFIG_EXTRAS "cmake/rosidl_typesupport_protobuf_c-extras.cmake.in"
)

install(
PROGRAMS bin/rosidl_typesupport_protobuf_c
DESTINATION lib/rosidl_typesupport_protobuf_c
)

install(
DIRECTORY cmake resource
DESTINATION share/${PROJECT_NAME}
Expand Down
54 changes: 0 additions & 54 deletions rosidl_typesupport_protobuf_c/bin/rosidl_typesupport_protobuf_c

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ if(NOT Protobuf_FOUND)
message(STATUS "Could not find Protobuf: skipping rosidl_typesupport_protobuf_c")
else()
find_package(ament_cmake_core QUIET REQUIRED)

ament_register_extension(
"rosidl_write_generator_arguments_extensions"
"rosidl_typesupport_protobuf_c"
"rosidl_typesupport_protobuf_c_write_arguments.cmake")

ament_register_extension(
"rosidl_generate_idl_interfaces"
"rosidl_typesupport_protobuf_c"
"rosidl_typesupport_protobuf_c_generate_interfaces.cmake")

set(rosidl_typesupport_protobuf_c_BIN
"${rosidl_typesupport_protobuf_c_DIR}/../../../lib/rosidl_typesupport_protobuf_c/rosidl_typesupport_protobuf_c")
normalize_path(rosidl_typesupport_protobuf_c_BIN
"${rosidl_typesupport_protobuf_c_BIN}")

set(rosidl_typesupport_protobuf_c_GENERATOR_FILES
"${rosidl_typesupport_protobuf_c_DIR}/../../../@PYTHON_INSTALL_DIR@/rosidl_typesupport_protobuf_c/__init__.py")
normalize_path(rosidl_typesupport_protobuf_c_GENERATOR_FILES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,51 +34,6 @@ foreach(_abs_idl_file ${rosidl_generate_interfaces_ABS_IDL_FILES})
)
endforeach()

set(_dependency_files "")
set(_dependencies "")
foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES})
foreach(_idl_file ${${_pkg_name}_IDL_FILES})
set(_abs_idl_file "${${_pkg_name}_DIR}/../${_idl_file}")
normalize_path(_abs_idl_file "${_abs_idl_file}")
list(APPEND _dependency_files "${_abs_idl_file}")
list(APPEND _dependencies "${_pkg_name}:${_abs_idl_file}")
endforeach()
endforeach()

set(target_dependencies
"${rosidl_typesupport_protobuf_c_BIN}"
${rosidl_typesupport_protobuf_c_GENERATOR_FILES}
"${rosidl_typesupport_protobuf_c_TEMPLATE_DIR}/idl__rosidl_typesupport_protobuf_c.hpp.em"
"${rosidl_typesupport_protobuf_c_TEMPLATE_DIR}/idl__type_support.cpp.em"
"${rosidl_typesupport_protobuf_c_TEMPLATE_DIR}/msg__rosidl_typesupport_protobuf_c.hpp.em"
"${rosidl_typesupport_protobuf_c_TEMPLATE_DIR}/msg__type_support.cpp.em"
"${rosidl_typesupport_protobuf_c_TEMPLATE_DIR}/srv__rosidl_typesupport_protobuf_c.hpp.em"
"${rosidl_typesupport_protobuf_c_TEMPLATE_DIR}/srv__type_support.cpp.em"
"${rosidl_typesupport_protobuf_c_TEMPLATE_DIR}/rosidl_typesupport_protobuf_c__visibility_control.h.in"
${rosidl_generate_interfaces_ABS_IDL_FILES}
${_dependency_files}
)

set(generator_arguments_file "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_protobuf_c__arguments.json")
rosidl_write_generator_arguments(
"${generator_arguments_file}"
PACKAGE_NAME "${PROJECT_NAME}"
IDL_TUPLES "${rosidl_generate_interfaces_IDL_TUPLES}"
ROS_INTERFACE_DEPENDENCIES "${_dependencies}"
OUTPUT_DIR "${_output_path}"
TEMPLATE_DIR "${rosidl_typesupport_protobuf_c_TEMPLATE_DIR}"
TARGET_DEPENDENCIES ${target_dependencies}
)

add_custom_command(
OUTPUT ${_generated_files}
COMMAND ${PYTHON_EXECUTABLE} ${rosidl_typesupport_protobuf_c_BIN}
--generator-arguments-file "${generator_arguments_file}"
DEPENDS ${target_dependencies}
COMMENT "Generating C type support for Protobuf"
VERBATIM
)

set(_target_suffix "__rosidl_typesupport_protobuf_c")

link_directories(${Protobuf_LIBRARY_DIRS})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2024 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set(_output_path
"${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_protobuf_c/${PROJECT_NAME}")
set(_generated_files "")

set(_dependency_files "")
set(_dependencies "")
foreach(_pkg_name ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES})
foreach(_idl_file ${${_pkg_name}_IDL_FILES})
set(_abs_idl_file "${${_pkg_name}_DIR}/../${_idl_file}")
normalize_path(_abs_idl_file "${_abs_idl_file}")
list(APPEND _dependency_files "${_abs_idl_file}")
list(APPEND _dependencies "${_pkg_name}:${_abs_idl_file}")
endforeach()
endforeach()

set(target_dependencies
"${rosidl_typesupport_protobuf_c_BIN}"
${rosidl_typesupport_protobuf_c_GENERATOR_FILES}
"${rosidl_typesupport_protobuf_c_TEMPLATE_DIR}/idl__rosidl_typesupport_protobuf_c.hpp.em"
"${rosidl_typesupport_protobuf_c_TEMPLATE_DIR}/idl__type_support.cpp.em"
"${rosidl_typesupport_protobuf_c_TEMPLATE_DIR}/msg__rosidl_typesupport_protobuf_c.hpp.em"
"${rosidl_typesupport_protobuf_c_TEMPLATE_DIR}/msg__type_support.cpp.em"
"${rosidl_typesupport_protobuf_c_TEMPLATE_DIR}/srv__rosidl_typesupport_protobuf_c.hpp.em"
"${rosidl_typesupport_protobuf_c_TEMPLATE_DIR}/srv__type_support.cpp.em"
"${rosidl_typesupport_protobuf_c_TEMPLATE_DIR}/rosidl_typesupport_protobuf_c__visibility_control.h.in"
${rosidl_generate_interfaces_ABS_IDL_FILES}
${_dependency_files}
)

set(generator_arguments_file "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_protobuf_c__arguments.json")
rosidl_write_generator_arguments(
"${generator_arguments_file}"
PACKAGE_NAME "${PROJECT_NAME}"
IDL_TUPLES "${rosidl_generate_interfaces_IDL_TUPLES}"
ROS_INTERFACE_DEPENDENCIES "${_dependencies}"
OUTPUT_DIR "${_output_path}"
TEMPLATE_DIR "${rosidl_typesupport_protobuf_c_TEMPLATE_DIR}"
TARGET_DEPENDENCIES ${target_dependencies}
GENERATOR_FILES "${rosidl_typesupport_protobuf_c_GENERATOR_FILES}"
)

list(APPEND rosidl_generator_arguments_files ${generator_arguments_file})
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
@# Context:
@# - package_name (string)
@# - interface_path (Path relative to the directory named after the package)
@# - typesupport
@# - content (IdlContent, list of elements, e.g. Messages or Services)
@#######################################################################
@
Expand All @@ -39,7 +40,7 @@ forward_declared_types = set()

system_header_files = []
header_files = [
typesupport_header(package_name, interface_path),
typesupport_header(package_name, interface_path, 'rosidl_typesupport_protobuf_c'),
ros_message_header_c(package_name, interface_path),
ros_message_functions_header_c(package_name, interface_path)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ header_files = [
"rosidl_typesupport_cpp/message_type_support.hpp",
ros_message_header_c(package_name, interface_path),
ros_message_header(package_name, interface_path),
visibility_control_header(package_name),
visibility_control_header(package_name, 'rosidl_typesupport_protobuf_c'),
"rosidl_typesupport_interface/macros.h",
protobuf_message_header(package_name, interface_path)
]

ros_type_ns = ros_type_namespace(package_name, interface_path)
ros_type_ns = ros_type_namespace(package_name, interface_path, '__')
ros_type_name = ros_type_name(message)
ros_type = ros_type(package_name, interface_path, message)
ros_type = ros_type(package_name, interface_path, message, '__')
proto_type = protobuf_type(package_name, interface_path, message)

}@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ from rosidl_cmake import convert_camel_case_to_lower_case_underscore
from rosidl_parser.definition import *
from rosidl_typesupport_protobuf import *

ros_type_ns = ros_type_namespace(package_name, interface_path)
ros_type_ns = ros_type_namespace(package_name, interface_path, '__')
ros_type_name = ros_type_name(message)
ros_type = ros_type(package_name, interface_path, message)
ros_type = ros_type(package_name, interface_path, message, '__')
proto_type = protobuf_type(package_name, interface_path, message)

system_header_files = [
Expand All @@ -36,7 +36,7 @@ system_header_files = [

header_files = [
'rosidl_typesupport_cpp/message_type_support.hpp',
visibility_control_header(package_name),
visibility_control_header(package_name, 'rosidl_typesupport_protobuf_c'),
'rosidl_typesupport_protobuf_c/identifier.hpp',
'rosidl_typesupport_protobuf_c/to_ros_c_string.hpp',
'rosidl_typesupport_protobuf_c/wstring_conversion.hpp',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ header_files = [
]

service_name = ros_service_name(service)
service_namespace = ros_service_namespace(package_name, interface_path)
service_type = ros_service_type(package_name, interface_path, service)
service_namespace = ros_service_namespace(package_name, interface_path, '__')
service_type = ros_service_type(package_name, interface_path, service, '__')

}@
@{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def isNamespacedArrayType(type_):

def isTypeAlreadyDeclared(type_, fw_declared_types):
from rosidl_typesupport_protobuf import ros_type_from_namespaced_type
return ros_type_from_namespaced_type(type_) in fw_declared_types
return ros_type_from_namespaced_type(type_, '__') in fw_declared_types

def registerDeclaredType(type_, fw_declared_types):
from rosidl_typesupport_protobuf import ros_type_from_namespaced_type
fw_declared_types.add(ros_type_from_namespaced_type(type_))
fw_declared_types.add(ros_type_from_namespaced_type(type_, '__'))

types_to_declare = list()
for member in message.structure.members:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from rosidl_cmake import generate_files
from rosidl_pycommon import generate_files


def generate_typesupport_protobuf_c(generator_arguments_file):
mapping = {
def get_template_mapping():
return {
'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)

def generate_typesupport_protobuf_c(generator_arguments_file):
"""
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 = get_template_mapping()

return generate_files(
generator_arguments_file, mapping)
Loading
Loading