Skip to content

Commit 24e16a8

Browse files
authored
Expose C introspection typesupport generation via rosidl generate CLI (#572)
Signed-off-by: Michel Hidalgo <[email protected]>
1 parent 73cc689 commit 24e16a8

File tree

5 files changed

+94
-2
lines changed

5 files changed

+94
-2
lines changed

rosidl_typesupport_introspection_c/bin/rosidl_typesupport_introspection_c

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_c(args.generator_arguments_file)
19+
generate_c(args.generator_arguments_file)
2020

2121

2222
if __name__ == '__main__':

rosidl_typesupport_introspection_c/package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
<build_export_depend>rosidl_runtime_c</build_export_depend>
2020

21+
<exec_depend>ament_index_python</exec_depend>
22+
<exec_depend>rosidl_cli</exec_depend>
2123
<exec_depend>rosidl_cmake</exec_depend>
2224
<exec_depend>rosidl_parser</exec_depend>
2325

rosidl_typesupport_introspection_c/rosidl_typesupport_introspection_c/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ def generate_c(generator_arguments_file):
2121
'detail/%s__rosidl_typesupport_introspection_c.h',
2222
'idl__type_support.c.em': 'detail/%s__type_support.c',
2323
}
24-
generate_files(generator_arguments_file, mapping)
24+
return generate_files(generator_arguments_file, mapping)
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 generate_visibility_control_file
21+
from rosidl_cli.command.helpers import legacy_generator_arguments_file
22+
from rosidl_cli.command.translate.api import translate
23+
24+
from rosidl_typesupport_introspection_c import generate_c
25+
26+
27+
class GenerateIntrospectionCTypesupport(GenerateCommandExtension):
28+
29+
def generate(
30+
self,
31+
package_name,
32+
interface_files,
33+
include_paths,
34+
output_path
35+
):
36+
generated_files = []
37+
38+
package_share_path = pathlib.Path(
39+
get_package_share_directory('rosidl_typesupport_introspection_c'))
40+
41+
templates_path = package_share_path / 'resource'
42+
43+
# Normalize interface definition format to .idl
44+
idl_interface_files = []
45+
non_idl_interface_files = []
46+
for path in interface_files:
47+
if not path.endswith('.idl'):
48+
non_idl_interface_files.append(path)
49+
else:
50+
idl_interface_files.append(path)
51+
if non_idl_interface_files:
52+
idl_interface_files.extend(translate(
53+
package_name=package_name,
54+
interface_files=non_idl_interface_files,
55+
include_paths=include_paths,
56+
output_format='idl',
57+
output_path=output_path / 'tmp',
58+
))
59+
60+
# Generate visibility control file
61+
visibility_control_file_template_path = \
62+
'rosidl_typesupport_introspection_c__visibility_control.h.in'
63+
visibility_control_file_template_path = \
64+
templates_path / visibility_control_file_template_path
65+
visibility_control_file_path = \
66+
'rosidl_typesupport_introspection_c__visibility_control.h'
67+
visibility_control_file_path = \
68+
output_path / 'msg' / visibility_control_file_path
69+
70+
generate_visibility_control_file(
71+
package_name=package_name,
72+
template_path=visibility_control_file_template_path,
73+
output_path=visibility_control_file_path
74+
)
75+
generated_files.append(visibility_control_file_path)
76+
77+
# Generate typesupport code
78+
with legacy_generator_arguments_file(
79+
package_name=package_name,
80+
interface_files=idl_interface_files,
81+
include_paths=include_paths,
82+
templates_path=templates_path,
83+
output_path=output_path
84+
) as path_to_arguments_file:
85+
generated_files.extend(generate_c(path_to_arguments_file))
86+
87+
return generated_files
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_c = rosidl_typesupport_introspection_c.cli:GenerateIntrospectionCTypesupport

0 commit comments

Comments
 (0)