Skip to content

Commit a22d31a

Browse files
committed
Expose C code generation via rosidl generate CLI.
Signed-off-by: Michel Hidalgo <[email protected]>
1 parent f7a9d3a commit a22d31a

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

rosidl_generator_c/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
<build_export_depend>rosidl_typesupport_interface</build_export_depend>
2020

21+
<exec_depend>rosidl_cli</exec_depend>
2122
<exec_depend>rosidl_parser</exec_depend>
2223

2324
<test_depend>ament_cmake_gtest</test_depend>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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)

rosidl_generator_c/setup.cfg

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.type_extensions =
3+
c = rosidl_generator_c.cli:GenerateC

0 commit comments

Comments
 (0)