Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose C typesupport generation via rosidl generate CLI #105

Merged
merged 3 commits into from
Mar 10, 2021
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
2 changes: 1 addition & 1 deletion rosidl_typesupport_c/bin/rosidl_typesupport_c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def main(argv=sys.argv[1:]):
help='The typesupports to be used')
args = parser.parse_args(argv)

return generate_c(args.generator_arguments_file, args.typesupports)
generate_c(args.generator_arguments_file, args.typesupports)


if __name__ == '__main__':
Expand Down
2 changes: 2 additions & 0 deletions rosidl_typesupport_c/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<buildtool_export_depend>ament_cmake_core</buildtool_export_depend>
<build_export_depend>rosidl_runtime_c</build_export_depend>

<exec_depend>ament_index_python</exec_depend>
<exec_depend>rosidl_cli</exec_depend>
<exec_depend>rosidl_typesupport_interface</exec_depend>

<test_depend>ament_lint_auto</test_depend>
Expand Down
2 changes: 1 addition & 1 deletion rosidl_typesupport_c/rosidl_typesupport_c/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ def generate_c(generator_arguments_file, type_supports):
mapping = {
'idl__type_support.cpp.em': '%s__type_support.cpp',
}
generate_files(
return generate_files(
generator_arguments_file, mapping,
additional_context={'type_supports': type_supports})
94 changes: 94 additions & 0 deletions rosidl_typesupport_c/rosidl_typesupport_c/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# 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 os

from ament_index_python import get_package_share_directory
from ament_index_python import get_resources

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

from rosidl_typesupport_c import generate_c


class GenerateCTypesupport(GenerateCommandExtension):

def generate(
self,
package_name,
interface_files,
include_paths,
output_path
):
generated_files = []

package_share_path = \
get_package_share_directory('rosidl_typesupport_c')

templates_path = os.path.join(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 visibility control file
visibility_control_file_template_path = \
'rosidl_typesupport_c__visibility_control.h.in'
visibility_control_file_template_path = \
templates_path / visibility_control_file_template_path
visibility_control_file_path = \
'rosidl_typesupport_c__visibility_control.h'
visibility_control_file_path = \
output_path / 'msg' / visibility_control_file_path

generate_visibility_control_file(
package_name=package_name,
template_path=visibility_control_file_template_path,
output_path=visibility_control_file_path
)
generated_files.append(visibility_control_file_path)

# Generate typesupport code
typesupport_implementations = list(
get_resources('rosidl_typesupport_c'))

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:
generated_files.extend(generate_c(
path_to_arguments_file,
typesupport_implementations
))

return generated_files
3 changes: 3 additions & 0 deletions rosidl_typesupport_c/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[options.entry_points]
rosidl_cli.command.generate.typesupport_extensions =
c = rosidl_typesupport_c.cli:GenerateCTypesupport