From c6693685dfa79aef5ad940878d8289d990155ae6 Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Mon, 15 Feb 2021 16:54:14 -0300 Subject: [PATCH 1/3] Expose C typesupport generation via rosidl generate CLI Signed-off-by: Michel Hidalgo --- rosidl_typesupport_c/bin/rosidl_typesupport_c | 2 +- rosidl_typesupport_c/package.xml | 1 + .../rosidl_typesupport_c/__init__.py | 2 +- .../rosidl_typesupport_c/cli.py | 73 +++++++++++++++++++ rosidl_typesupport_c/setup.cfg | 3 + 5 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 rosidl_typesupport_c/rosidl_typesupport_c/cli.py create mode 100644 rosidl_typesupport_c/setup.cfg diff --git a/rosidl_typesupport_c/bin/rosidl_typesupport_c b/rosidl_typesupport_c/bin/rosidl_typesupport_c index d3e50bf0..7b6f80ef 100644 --- a/rosidl_typesupport_c/bin/rosidl_typesupport_c +++ b/rosidl_typesupport_c/bin/rosidl_typesupport_c @@ -21,7 +21,7 @@ def main(argv=sys.argv[1:]): help='The typesupports to be used') args = parser.parse_args(argv) - return generate_c(args.generator_arguments_file, args.typesupports) + generate_c(args.generator_arguments_file, args.typesupports) if __name__ == '__main__': diff --git a/rosidl_typesupport_c/package.xml b/rosidl_typesupport_c/package.xml index 80b19042..fcd4464a 100644 --- a/rosidl_typesupport_c/package.xml +++ b/rosidl_typesupport_c/package.xml @@ -26,6 +26,7 @@ ament_cmake_core rosidl_runtime_c + rosidl_cli rosidl_typesupport_interface ament_lint_auto diff --git a/rosidl_typesupport_c/rosidl_typesupport_c/__init__.py b/rosidl_typesupport_c/rosidl_typesupport_c/__init__.py index 2ac977e2..0839df47 100644 --- a/rosidl_typesupport_c/rosidl_typesupport_c/__init__.py +++ b/rosidl_typesupport_c/rosidl_typesupport_c/__init__.py @@ -25,6 +25,6 @@ def generate_c(generator_arguments_file, type_supports): mapping = { 'idl__type_support.cpp.em': '%s__type_support.cpp', } - generate_files( + return generate_files( generator_arguments_file, mapping, additional_context={'type_supports': type_supports}) diff --git a/rosidl_typesupport_c/rosidl_typesupport_c/cli.py b/rosidl_typesupport_c/rosidl_typesupport_c/cli.py new file mode 100644 index 00000000..bb576aa7 --- /dev/null +++ b/rosidl_typesupport_c/rosidl_typesupport_c/cli.py @@ -0,0 +1,73 @@ +# Copyright 2021 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 + +from ament_index_python import get_package_share_directory +from ament_index_python import get_resources + +from rosidl_cli.command.generate.extensions import GenerateCommandExtension +from rosidl_cli.command.helpers import generate_visibility_control_file +from rosidl_cli.command.helpers import legacy_generator_arguments_file +from rosidl_cli.command.translate.api import translate + +from rosidl_typesupport_c import generate_c + + +class GenerateCTypesupport(GenerateCommandExtension): + + def generate( + self, + package_name, + interface_files, + include_paths, + output_path + ): + package_share_path = \ + get_package_share_directory('rosidl_typesupport_c') + + templates_path = os.path.join(package_share_path, 'resource') + + # Normalize interface definition format to .idl + idl_interface_files = [] + non_idl_interface_files = [] + for path in interface_files: + if not path.endswith('.idl'): + non_idl_interface_files.append(path) + else: + idl_interface_files.append(path) + if non_idl_interface_files: + idl_interface_files.extend(translate( + package_name=package_name, + interface_files=non_idl_interface_files, + include_paths=include_paths, + output_format='idl', + output_path=output_path / 'tmp', + )) + + # Generate typesupport code + typesupport_implementations = list( + get_resources('rosidl_typesupport_c')) + + with legacy_generator_arguments_file( + package_name=package_name, + interface_files=idl_interface_files, + include_paths=include_paths, + templates_path=templates_path, + output_path=output_path + ) as path_to_arguments_file: + return generate_c( + path_to_arguments_file, + typesupport_implementations + ) diff --git a/rosidl_typesupport_c/setup.cfg b/rosidl_typesupport_c/setup.cfg new file mode 100644 index 00000000..1edc54c2 --- /dev/null +++ b/rosidl_typesupport_c/setup.cfg @@ -0,0 +1,3 @@ +[options.entry_points] +rosidl_cli.command.generate.typesupport_extensions = + c = rosidl_typesupport_c.cli:GenerateCTypesupport From 9cac0d434b223e1dbec513c6f500b8f38fb65215 Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Wed, 10 Mar 2021 10:56:51 -0300 Subject: [PATCH 2/3] Add ament_index_python as dependency Signed-off-by: Michel Hidalgo --- rosidl_typesupport_c/package.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/rosidl_typesupport_c/package.xml b/rosidl_typesupport_c/package.xml index fcd4464a..6f02083f 100644 --- a/rosidl_typesupport_c/package.xml +++ b/rosidl_typesupport_c/package.xml @@ -26,6 +26,7 @@ ament_cmake_core rosidl_runtime_c + ament_index_python rosidl_cli rosidl_typesupport_interface From e92753dfec6f13e7db82c16779b7f42a9432f5b6 Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Wed, 10 Mar 2021 11:10:05 -0300 Subject: [PATCH 3/3] Generate missing visibility control file. Signed-off-by: Michel Hidalgo --- .../rosidl_typesupport_c/cli.py | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/rosidl_typesupport_c/rosidl_typesupport_c/cli.py b/rosidl_typesupport_c/rosidl_typesupport_c/cli.py index bb576aa7..f566aa9e 100644 --- a/rosidl_typesupport_c/rosidl_typesupport_c/cli.py +++ b/rosidl_typesupport_c/rosidl_typesupport_c/cli.py @@ -34,6 +34,8 @@ def generate( include_paths, output_path ): + generated_files = [] + package_share_path = \ get_package_share_directory('rosidl_typesupport_c') @@ -56,6 +58,23 @@ def generate( output_path=output_path / 'tmp', )) + # Generate visibility control file + visibility_control_file_template_path = \ + 'rosidl_typesupport_c__visibility_control.h.in' + visibility_control_file_template_path = \ + templates_path / visibility_control_file_template_path + visibility_control_file_path = \ + 'rosidl_typesupport_c__visibility_control.h' + visibility_control_file_path = \ + output_path / 'msg' / visibility_control_file_path + + generate_visibility_control_file( + package_name=package_name, + template_path=visibility_control_file_template_path, + output_path=visibility_control_file_path + ) + generated_files.append(visibility_control_file_path) + # Generate typesupport code typesupport_implementations = list( get_resources('rosidl_typesupport_c')) @@ -67,7 +86,9 @@ def generate( templates_path=templates_path, output_path=output_path ) as path_to_arguments_file: - return generate_c( + generated_files.extend(generate_c( path_to_arguments_file, typesupport_implementations - ) + )) + + return generated_files