|
| 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 os |
| 16 | + |
| 17 | +from ament_index_python import get_package_share_directory |
| 18 | +from rosidl_cli.command.generate.extensions import GenerateCommandExtension |
| 19 | +from rosidl_cli.command.generate.helpers import generate_visibility_control_file |
| 20 | +from rosidl_cli.command.generate.helpers import legacy_generator_arguments_file |
| 21 | + |
| 22 | +from rosidl_generator_c import generate_c |
| 23 | + |
| 24 | + |
| 25 | +class GenerateC(GenerateCommandExtension): |
| 26 | + |
| 27 | + def generate( |
| 28 | + self, |
| 29 | + package_name, |
| 30 | + interface_files, |
| 31 | + include_paths, |
| 32 | + output_path |
| 33 | + ): |
| 34 | + package_share_path = \ |
| 35 | + get_package_share_directory( |
| 36 | + 'rosidl_generator_c' |
| 37 | + ) |
| 38 | + templates_path = os.path.join( |
| 39 | + package_share_path, 'resource' |
| 40 | + ) |
| 41 | + |
| 42 | + # Generate visibility control file |
| 43 | + visibility_control_file_template_path = os.path.join( |
| 44 | + templates_path, 'rosidl_generator_c__visibility_control.h.in') |
| 45 | + visibility_control_file_path = os.path.join( |
| 46 | + output_path, 'msg', 'rosidl_generator_c__visibility_control.h') |
| 47 | + |
| 48 | + generate_visibility_control_file( |
| 49 | + package_name=package_name, |
| 50 | + template_path=visibility_control_file_template_path, |
| 51 | + output_path=visibility_control_file_path |
| 52 | + ) |
| 53 | + |
| 54 | + # Generate code |
| 55 | + with legacy_generator_arguments_file( |
| 56 | + package_name=package_name, |
| 57 | + interface_files=interface_files, |
| 58 | + include_paths=include_paths, |
| 59 | + templates_path=templates_path, |
| 60 | + output_path=output_path |
| 61 | + ) as path_to_arguments_file: |
| 62 | + generate_c(path_to_arguments_file) |
0 commit comments