diff --git a/examples/chatter/BUILD.bazel b/examples/chatter/BUILD.bazel index 6e220507..c8c74c6a 100644 --- a/examples/chatter/BUILD.bazel +++ b/examples/chatter/BUILD.bazel @@ -1,5 +1,6 @@ load("@com_github_mvukov_rules_ros2//ros2:bag.bzl", "ros2_bag") load("@com_github_mvukov_rules_ros2//ros2:cc_defs.bzl", "ros2_cpp_binary") +load("@com_github_mvukov_rules_ros2//ros2:interface.bzl", "ros2_interface") load("@com_github_mvukov_rules_ros2//ros2:launch.bzl", "ros2_launch") load("@com_github_mvukov_rules_ros2//ros2:rust_interfaces.bzl", "rust_ros2_interface_library") load("@com_github_mvukov_rules_ros2//ros2:test.bzl", "ros2_test") @@ -77,6 +78,13 @@ ros2_topic( ], ) +ros2_interface( + name = "interface", + deps = [ + "@ros2_common_interfaces//:py_std_msgs", + ], +) + ros2_bag( name = "bag", idl_deps = [ diff --git a/ros2/BUILD.bazel b/ros2/BUILD.bazel index 78e9f11f..459aa397 100644 --- a/ros2/BUILD.bazel +++ b/ros2/BUILD.bazel @@ -14,6 +14,7 @@ exports_files([ "bag.bzl", "bag.py.tpl", "cc_defs.bzl", + "interface.bzl", "interfaces.bzl", "launch.bzl", "launch_exec.py.tpl", @@ -22,6 +23,7 @@ exports_files([ "py_defs.bzl", "pytest_wrapper.py.tpl", "ros2_action.py", + "ros2_interface.py", "ros2_launch.py.tpl", "ros2_service.py", "ros2_topic.py", diff --git a/ros2/interface.bzl b/ros2/interface.bzl new file mode 100644 index 00000000..6151caf3 --- /dev/null +++ b/ros2/interface.bzl @@ -0,0 +1,44 @@ +# 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. + +""" Implements a macro for setting up a ROS 2 interface app. +""" + +load("//ros2:py_defs.bzl", "ros2_py_binary") + + +def ros2_interface(name, deps, **kwargs): + """ Defines a ROS 2 interface app for a set of deps. + + Args: + name: A unique target name. + deps: A list of Python targets: typically IDL libraries + (py_ros2_interface_library targets) used by the topic app. + **kwargs: https://bazel.build/reference/be/common-definitions#common-attributes-binaries + """ + + ros2_py_binary( + name = name, + srcs = ["@com_github_mvukov_rules_ros2//ros2:ros2_interface.py"], + main = "@com_github_mvukov_rules_ros2//ros2:ros2_interface.py", + deps = [ + "@com_github_mvukov_rules_ros2//ros2:ros2_cmd", + "@ros2_rcl_interfaces//:py_action_msgs", + "@ros2_rcl_interfaces//:py_builtin_interfaces", + "@ros2_rcl_interfaces//:py_rcl_interfaces", + "@ros2cli", + "@ros2cli//:ros2interface", + "@ros2_rosidl//:rosidl_adapter_lib", + ] + deps, + set_up_ament = True, + **kwargs + ) diff --git a/ros2/ros2_interface.py b/ros2/ros2_interface.py new file mode 100644 index 00000000..74760b1d --- /dev/null +++ b/ros2/ros2_interface.py @@ -0,0 +1,33 @@ +# 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 sys + +import ros2cli.cli +import ros2interface.verb.list +import ros2interface.verb.package +import ros2interface.verb.packages +import ros2interface.verb.proto +import ros2interface.verb.show + +import ros2.ros2_cmd + +COMMAND_EXTENSIONS = { + 'list': ros2interface.verb.list.ListVerb(), + 'package': ros2interface.verb.package.PackageVerb(), + 'packages': ros2interface.verb.packages.PackagesVerb(), + 'proto': ros2interface.verb.proto.ProtoVerb(), + 'show': ros2interface.verb.show.ShowVerb(), +} + +extension = ros2.ros2_cmd.Ros2CommandExtension(COMMAND_EXTENSIONS) +sys.exit(ros2cli.cli.main(argv=sys.argv[1:], extension=extension))