diff --git a/rosidl_typesupport_connext_cpp/cmake/rosidl_typesupport_connext_cpp_generate_interfaces.cmake b/rosidl_typesupport_connext_cpp/cmake/rosidl_typesupport_connext_cpp_generate_interfaces.cmake index 64eefc1..75259b9 100644 --- a/rosidl_typesupport_connext_cpp/cmake/rosidl_typesupport_connext_cpp_generate_interfaces.cmake +++ b/rosidl_typesupport_connext_cpp/cmake/rosidl_typesupport_connext_cpp_generate_interfaces.cmake @@ -13,7 +13,14 @@ # limitations under the License. set(_output_path "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_connext_cpp/${PROJECT_NAME}") -set(_connext_idl_base_path "${CMAKE_CURRENT_BINARY_DIR}/rosidl_typesupport_connext_idl") +set(_dds_idl_base_path "${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_dds_idl") + +rosidl_generate_dds_interfaces( + ${rosidl_generate_interfaces_TARGET}__dds_connext_idl + IDL_TUPLES ${rosidl_generate_interfaces_IDL_TUPLES} + DEPENDENCY_PACKAGE_NAMES ${rosidl_generate_interfaces_DEPENDENCY_PACKAGE_NAMES} + OUTPUT_SUBFOLDERS "dds_connext" +) set(_dds_idl_files "") set(_generated_files "") @@ -33,7 +40,7 @@ foreach(_idl_tuple ${rosidl_generate_interfaces_IDL_TUPLES}) list(APPEND _generated_external_files "${_output_path}/${_parent_folder}/dds_connext/${_idl_name}_Support.cxx") list(APPEND _generated_files "${_output_path}/${_parent_folder}/${_header_name}__rosidl_typesupport_connext_cpp.hpp") list(APPEND _generated_files "${_output_path}/${_parent_folder}/dds_connext/${_header_name}__type_support.cpp") - list(APPEND _dds_idl_files "${_abs_idl_file}") + list(APPEND _dds_idl_files "${_dds_idl_base_path}/${PROJECT_NAME}/${_parent_folder}/dds_connext/${_idl_name}_.idl") endforeach() # If not on Windows, disable some warnings with Connext's generated code @@ -112,7 +119,7 @@ add_custom_command( OUTPUT ${_generated_files} ${_generated_external_files} COMMAND ${PYTHON_EXECUTABLE} ${rosidl_typesupport_connext_cpp_BIN} --generator-arguments-file "${generator_arguments_file}" - --idl-base-path "${_connext_idl_base_path}" + --dds-interface-base-path "${_dds_idl_base_path}" --idl-pp "${_idl_pp}" DEPENDS ${target_dependencies} ${_dds_idl_files} COMMENT "Generating C++ type support for RTI Connext (using '${_idl_pp}')" @@ -203,6 +210,10 @@ add_dependencies( ${rosidl_generate_interfaces_TARGET}${_target_suffix} ${rosidl_generate_interfaces_TARGET}__cpp ) +add_dependencies( + ${rosidl_generate_interfaces_TARGET}__dds_connext_idl + ${rosidl_generate_interfaces_TARGET}${_target_suffix} +) if(NOT rosidl_generate_interfaces_SKIP_INSTALL) install( diff --git a/rosidl_typesupport_connext_cpp/rosidl_typesupport_connext_cpp/__init__.py b/rosidl_typesupport_connext_cpp/rosidl_typesupport_connext_cpp/__init__.py index d15ba1b..4071340 100644 --- a/rosidl_typesupport_connext_cpp/rosidl_typesupport_connext_cpp/__init__.py +++ b/rosidl_typesupport_connext_cpp/rosidl_typesupport_connext_cpp/__init__.py @@ -17,25 +17,33 @@ import sys from rosidl_cmake import generate_files -from .convert_to_connext_idl import convert_to_connext_idl -def generate_dds_connext_cpp(pkg_name, dds_interface_files, - dds_interface_base_path, - output_basepath, idl_pp): - converted_dds_interface_files = [] +def generate_dds_connext_cpp( + pkg_name, dds_interface_files, dds_interface_base_path, deps, + output_basepath, idl_pp): + + include_dirs = [dds_interface_base_path] + for dep in deps: + # Only take the first : for separation, as Windows follows with a C:\ + dep_parts = dep.split(':', 1) + assert len(dep_parts) == 2, "The dependency '%s' must contain a double colon" % dep + idl_path = dep_parts[1] + idl_base_path = os.path.dirname( + os.path.dirname(os.path.dirname(os.path.normpath(idl_path)))) + if idl_base_path not in include_dirs: + include_dirs.append(idl_base_path) + for idl_file in dds_interface_files: assert os.path.exists(idl_file), 'Could not find IDL file: ' + idl_file - converted_dds_interface_files.append( - convert_to_connext_idl(idl_file, dds_interface_base_path) - ) - include_dirs = [dds_interface_base_path] - for idl_file in converted_dds_interface_files: - idl_file_folder = os.path.basename(os.path.dirname(idl_file)) + # get two level of parent folders for idl file + folder = os.path.dirname(idl_file) + parent_folder = os.path.dirname(folder) output_path = os.path.join( - output_basepath, idl_file_folder, 'dds_connext' - ) + output_basepath, + os.path.basename(parent_folder), + os.path.basename(folder)) try: os.makedirs(output_path) except FileExistsError: @@ -58,7 +66,6 @@ def generate_dds_connext_cpp(pkg_name, dds_interface_files, msg_name = os.path.splitext(os.path.basename(idl_file))[0] count = 1 max_count = 5 - print(' '.join(cmd)) while True: subprocess.check_call(cmd) diff --git a/rosidl_typesupport_connext_cpp/rosidl_typesupport_connext_cpp/convert_to_connext_idl.py b/rosidl_typesupport_connext_cpp/rosidl_typesupport_connext_cpp/convert_to_connext_idl.py deleted file mode 100644 index 2ef9863..0000000 --- a/rosidl_typesupport_connext_cpp/rosidl_typesupport_connext_cpp/convert_to_connext_idl.py +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright 2018 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. -import os -import re - - -def convert_to_connext_idl(input_idl_file_path, output_basepath): - """ - Convert a generic IDL file to a new IDL file compatible with RTI Connext. - The new IDL file is created with the same base name as the input file. - A file with the same name in the output path wil be overwritten. - :param: input_idl_file_path The path to the input IDL file. - :param: output_basepath The output path where the new IDL file is written. - """ - # Get two level of parent folders for idl file - folder = os.path.dirname(input_idl_file_path) - parent_folder = os.path.dirname(folder) - output_idl_file_path = os.path.join( - output_basepath, - os.path.basename(parent_folder), - os.path.basename(folder), - os.path.basename(input_idl_file_path) - ) - try: - os.makedirs(os.path.dirname(output_idl_file_path)) - except FileExistsError: - pass - - # Regexes for find and replace - regex_substitutions = [] - # Replace unsupported types - regex_substitutions.append((re.compile(r'([<>,\s])int8([<>,\s])'), r'\1octet\2')) - regex_substitutions.append((re.compile(r'([<>,\s])uint8([<>,\s])'), r'\1octet\2')) - regex_substitutions.append((re.compile(r'([<>,\s])int16([<>,\s])'), r'\1short\2')) - regex_substitutions.append((re.compile(r'([<>,\s])uint16([<>,\s])'), r'\1unsigned short\2')) - regex_substitutions.append((re.compile(r'([<>,\s])int32([<>,\s])'), r'\1long\2')) - regex_substitutions.append((re.compile(r'([<>,\s])uint32([<>,\s])'), r'\1unsigned long\2')) - regex_substitutions.append((re.compile(r'([<>,\s])int64([<>,\s])'), r'\1long long\2')) - regex_substitutions.append((re.compile(r'([<>,\s])uint64([<>,\s])'), r'\1unsigned long long\2')) - with open(output_idl_file_path, 'w') as output_idl: - with open(input_idl_file_path, 'r') as input_idl: - for line in input_idl: - # Replace unsupported types - for regex, substitution in regex_substitutions: - line = regex.sub(substitution, line) - output_idl.write(line) - return output_idl_file_path