Skip to content

Commit

Permalink
Expose .msg/.srv/.action to .idl conversion via rosidl translate CLI
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
  • Loading branch information
hidmic committed Mar 1, 2021
1 parent 369f252 commit 26e2bd0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
1 change: 1 addition & 0 deletions rosidl_adapter/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<build_depend>ament_cmake</build_depend>

<exec_depend>python3-empy</exec_depend>
<exec_depend>rosidl_cli</exec_depend>

<test_depend>ament_cmake_pytest</test_depend>
<test_depend>ament_lint_common</test_depend>
Expand Down
59 changes: 58 additions & 1 deletion rosidl_adapter/rosidl_adapter/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018 Open Source Robotics Foundation, Inc.
# Copyright 2018-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.
Expand All @@ -19,6 +19,9 @@
from catkin_pkg.package import package_exists_at
from catkin_pkg.package import parse_package

from rosidl_cli.command.helpers import interface_path_as_tuple
from rosidl_cli.command.translate.extensions import TranslateCommandExtension


def convert_files_to_idl(extension, conversion_function, argv=sys.argv[1:]):
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -48,3 +51,57 @@ def convert_files_to_idl(extension, conversion_function, argv=sys.argv[1:]):
package_dir, pkg.name,
interface_file.absolute().relative_to(package_dir),
interface_file.parent)


class TranslateToIDL(TranslateCommandExtension):

output_format = 'idl'

def translate(
self,
package_name,
interface_files,
include_paths,
output_path
):
translated_interface_files = []
for interface_file in interface_files:
prefix, interface_file = interface_path_as_tuple(interface_file)
output_dir = output_path / interface_file.parent
translated_interface_file = self.conversion_function(
prefix, package_name, interface_file, output_dir)
translated_interface_file = \
translated_interface_file.relative_to(output_path)
translated_interface_files.append(
f'{output_path}:{translated_interface_file}'
)
return translated_interface_files


class TranslateMsgToIDL(TranslateToIDL):

input_format = 'msg'

@property
def conversion_function(self):
from rosidl_adapter.msg import convert_msg_to_idl
return convert_msg_to_idl


class TranslateSrvToIDL(TranslateToIDL):

input_format = 'srv'

@property
def conversion_function(self):
from rosidl_adapter.srv import convert_srv_to_idl
return convert_srv_to_idl


class TranslateActionToIDL(TranslateToIDL):
input_format = 'action'

@property
def conversion_function(self):
from rosidl_adapter.action import convert_action_to_idl
return convert_action_to_idl
5 changes: 5 additions & 0 deletions rosidl_adapter/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[options.entry_points]
rosidl_cli.command.translate.extensions =
msg2idl = rosidl_adapter.cli:TranslateMsgToIDL
srv2idl = rosidl_adapter.cli:TranslateSrvToIDL
action2idl = rosidl_adapter.cli:TranslateActionToIDL

0 comments on commit 26e2bd0

Please sign in to comment.