Skip to content

Commit 15129b4

Browse files
committed
Expose C++ introspection typesupport generation via rosidl generate CLI
Signed-off-by: Michel Hidalgo <[email protected]>
1 parent 2c20f0f commit 15129b4

File tree

5 files changed

+71
-2
lines changed

5 files changed

+71
-2
lines changed

rosidl_typesupport_introspection_cpp/bin/rosidl_typesupport_introspection_cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def main(argv=sys.argv[1:]):
1616
help='The location of the file containing the generator arguments')
1717
args = parser.parse_args(argv)
1818

19-
return generate_cpp(args.generator_arguments_file)
19+
generate_cpp(args.generator_arguments_file)
2020

2121

2222
if __name__ == '__main__':

rosidl_typesupport_introspection_cpp/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<build_depend>rosidl_runtime_cpp</build_depend>
2323
<build_depend>rosidl_typesupport_introspection_c</build_depend>
2424

25+
<exec_depend>rosidl_cli</exec_depend>
2526
<exec_depend>rosidl_cmake</exec_depend>
2627
<exec_depend>rosidl_parser</exec_depend>
2728
<exec_depend>rosidl_typesupport_interface</exec_depend>

rosidl_typesupport_introspection_cpp/rosidl_typesupport_introspection_cpp/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ def generate_cpp(generator_arguments_file):
2121
'detail/%s__rosidl_typesupport_introspection_cpp.hpp',
2222
'idl__type_support.cpp.em': 'detail/%s__type_support.cpp',
2323
}
24-
generate_files(generator_arguments_file, mapping)
24+
return generate_files(generator_arguments_file, mapping)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[options.entry_points]
2+
rosidl_cli.command.generate.typesupport_extensions =
3+
introspection_cpp = rosidl_typesupport_introspection_cpp.cli:GenerateIntrospectionCppTypesupport

0 commit comments

Comments
 (0)