Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions rosidl_generator_cpp/bin/rosidl_generator_cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ def main(argv=sys.argv[1:]):
help='The location of the file containing the generator arguments')
args = parser.parse_args(argv)

return generate_cpp(
args.generator_arguments_file,
)
generate_cpp(args.generator_arguments_file)


if __name__ == '__main__':
Expand Down
2 changes: 2 additions & 0 deletions rosidl_generator_cpp/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<!-- This is needed for the rosidl_message_type_support_t struct and visibility macros -->
<build_export_depend>rosidl_generator_c</build_export_depend>

<exec_depend>ament_index_python</exec_depend>
<exec_depend>rosidl_cli</exec_depend>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include ament_index_python as a <exec_depend>

<exec_depend>rosidl_parser</exec_depend>

<test_depend>ament_cmake_gtest</test_depend>
Expand Down
2 changes: 1 addition & 1 deletion rosidl_generator_cpp/rosidl_generator_cpp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def generate_cpp(generator_arguments_file):
'idl__struct.hpp.em': 'detail/%s__struct.hpp',
'idl__traits.hpp.em': 'detail/%s__traits.hpp',
}
generate_files(
return generate_files(
generator_arguments_file, mapping,
post_process_callback=prefix_with_bom_if_necessary)

Expand Down
63 changes: 63 additions & 0 deletions rosidl_generator_cpp/rosidl_generator_cpp/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright 2021 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pathlib

from ament_index_python import get_package_share_directory
from rosidl_cli.command.generate.extensions import GenerateCommandExtension
from rosidl_cli.command.helpers import legacy_generator_arguments_file
from rosidl_cli.command.translate.api import translate

from rosidl_generator_cpp import generate_cpp


class GenerateCpp(GenerateCommandExtension):

def generate(
self,
package_name,
interface_files,
include_paths,
output_path
):
package_share_path = \
pathlib.Path(get_package_share_directory('rosidl_generator_cpp'))
templates_path = package_share_path / 'resource'

# Normalize interface definition format to .idl
idl_interface_files = []
non_idl_interface_files = []
for path in interface_files:
if not path.endswith('.idl'):
non_idl_interface_files.append(path)
else:
idl_interface_files.append(path)
if non_idl_interface_files:
idl_interface_files.extend(translate(
package_name=package_name,
interface_files=non_idl_interface_files,
include_paths=include_paths,
output_format='idl',
output_path=output_path / 'tmp',
))

# Generate code
with legacy_generator_arguments_file(
package_name=package_name,
interface_files=idl_interface_files,
include_paths=include_paths,
templates_path=templates_path,
output_path=output_path
) as path_to_arguments_file:
return generate_cpp(path_to_arguments_file)
3 changes: 3 additions & 0 deletions rosidl_generator_cpp/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[options.entry_points]
rosidl_cli.command.generate.type_extensions =
cpp = rosidl_generator_cpp.cli:GenerateCpp