Skip to content

Commit 2fbf5c3

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

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

rosidl_generator_cpp/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<!-- This is needed for the rosidl_message_type_support_t struct and visibility macros -->
1818
<build_export_depend>rosidl_generator_c</build_export_depend>
1919

20+
<exec_depend>rosidl_cli</exec_depend>
2021
<exec_depend>rosidl_parser</exec_depend>
2122

2223
<test_depend>ament_cmake_gtest</test_depend>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 legacy_generator_arguments_file
20+
21+
from rosidl_generator_cpp import generate_cpp
22+
23+
24+
class GenerateCpp(GenerateCommandExtension):
25+
26+
def generate(
27+
self,
28+
package_name,
29+
interface_files,
30+
include_paths,
31+
output_path
32+
):
33+
package_share_path = \
34+
get_package_share_directory(
35+
'rosidl_generator_cpp'
36+
)
37+
templates_path = os.path.join(
38+
package_share_path, 'resource'
39+
)
40+
41+
# Generate code
42+
with legacy_generator_arguments_file(
43+
package_name=package_name,
44+
interface_files=interface_files,
45+
include_paths=include_paths,
46+
templates_path=templates_path,
47+
output_path=output_path
48+
) as path_to_arguments_file:
49+
generate_cpp(path_to_arguments_file)

rosidl_generator_cpp/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+
cpp = rosidl_generator_cpp.cli:GenerateCpp

0 commit comments

Comments
 (0)