|  | 
|  | 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 | + | 
|  | 19 | +from rosidl_cli.command.generate.extensions import GenerateCommandExtension | 
|  | 20 | +from rosidl_cli.command.helpers import legacy_generator_arguments_file | 
|  | 21 | +from rosidl_cli.command.translate.api import translate | 
|  | 22 | + | 
|  | 23 | +from rosidl_typesupport_introspection_cpp import generate_cpp | 
|  | 24 | + | 
|  | 25 | + | 
|  | 26 | +class GenerateIntrospectionCppTypesupport(GenerateCommandExtension): | 
|  | 27 | + | 
|  | 28 | +    def generate( | 
|  | 29 | +        self, | 
|  | 30 | +        package_name, | 
|  | 31 | +        interface_files, | 
|  | 32 | +        include_paths, | 
|  | 33 | +        output_path | 
|  | 34 | +    ): | 
|  | 35 | +        package_share_path = pathlib.Path( | 
|  | 36 | +            get_package_share_directory('rosidl_typesupport_introspection_cpp')) | 
|  | 37 | + | 
|  | 38 | +        templates_path = package_share_path / 'resource' | 
|  | 39 | + | 
|  | 40 | +        # Normalize interface definition format to .idl | 
|  | 41 | +        idl_interface_files = [] | 
|  | 42 | +        non_idl_interface_files = [] | 
|  | 43 | +        for path in interface_files: | 
|  | 44 | +            if not path.endswith('.idl'): | 
|  | 45 | +                non_idl_interface_files.append(path) | 
|  | 46 | +            else: | 
|  | 47 | +                idl_interface_files.append(path) | 
|  | 48 | +        if non_idl_interface_files: | 
|  | 49 | +            idl_interface_files.extend(translate( | 
|  | 50 | +                package_name=package_name, | 
|  | 51 | +                interface_files=non_idl_interface_files, | 
|  | 52 | +                include_paths=include_paths, | 
|  | 53 | +                output_format='idl', | 
|  | 54 | +                output_path=output_path / 'tmp', | 
|  | 55 | +            )) | 
|  | 56 | + | 
|  | 57 | +        # Generate typesupport code | 
|  | 58 | +        with legacy_generator_arguments_file( | 
|  | 59 | +            package_name=package_name, | 
|  | 60 | +            interface_files=idl_interface_files, | 
|  | 61 | +            include_paths=include_paths, | 
|  | 62 | +            templates_path=templates_path, | 
|  | 63 | +            output_path=output_path | 
|  | 64 | +        ) as path_to_arguments_file: | 
|  | 65 | +            return generate_cpp(path_to_arguments_file) | 
0 commit comments