Skip to content
Open
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
8 changes: 8 additions & 0 deletions examples/chatter/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -77,6 +78,13 @@ ros2_topic(
],
)

ros2_interface(
name = "interface",
deps = [
"@ros2_common_interfaces//:py_std_msgs",
],
)

ros2_bag(
name = "bag",
idl_deps = [
Expand Down
2 changes: 2 additions & 0 deletions ros2/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exports_files([
"bag.bzl",
"bag.py.tpl",
"cc_defs.bzl",
"interface.bzl",
"interfaces.bzl",
"launch.bzl",
"launch_exec.py.tpl",
Expand All @@ -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",
Expand Down
44 changes: 44 additions & 0 deletions ros2/interface.bzl
Original file line number Diff line number Diff line change
@@ -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
)
33 changes: 33 additions & 0 deletions ros2/ros2_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Licensed under the Apache License, Version 2.0 (the "License");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Add yourself as a copyright holder in relevant files.

# 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))
Loading