|
| 1 | +# Copyright 2021 Open Source Robotics Foundation, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import pathlib |
| 16 | + |
| 17 | +from ament_index_python import get_package_share_directory |
| 18 | +from rosidl_cli.command.helpers import legacy_generator_arguments_file |
| 19 | +from rosidl_cli.command.translate.extensions import TranslateCommandExtension |
| 20 | + |
| 21 | +from rosidl_generator_dds_idl import generate_dds_idl |
| 22 | + |
| 23 | + |
| 24 | +class TranslateIDLToDDSIDL(TranslateCommandExtension): |
| 25 | + |
| 26 | + input_format = 'idl' |
| 27 | + output_format = 'dds_idl' |
| 28 | + |
| 29 | + def translate( |
| 30 | + self, |
| 31 | + package_name, |
| 32 | + interface_files, |
| 33 | + include_paths, |
| 34 | + output_path |
| 35 | + ): |
| 36 | + package_share_path = pathlib.Path( |
| 37 | + get_package_share_directory('rosidl_generator_dds_idl')) |
| 38 | + templates_path = package_share_path / 'resource' |
| 39 | + |
| 40 | + with legacy_generator_arguments_file( |
| 41 | + package_name=package_name, |
| 42 | + interface_files=interface_files, |
| 43 | + include_paths=include_paths, |
| 44 | + templates_path=templates_path, |
| 45 | + output_path=output_path |
| 46 | + ) as path_to_arguments_file: |
| 47 | + generated_files = generate_dds_idl( |
| 48 | + path_to_arguments_file, |
| 49 | + subfolders=[], |
| 50 | + extension_module_name=None, |
| 51 | + additional_service_templates=[] |
| 52 | + ) |
| 53 | + translated_interface_files = [] |
| 54 | + for path in generated_files: |
| 55 | + path = pathlib.Path(path) |
| 56 | + relative_path = path.relative_to(output_path) |
| 57 | + translated_interface_files.append( |
| 58 | + f'{output_path}:{relative_path.as_posix()}' |
| 59 | + ) |
| 60 | + return translated_interface_files |
0 commit comments