Skip to content

Support running ros2_bag binary from any directory #96

@kgreenek

Description

@kgreenek

I ran into another potential snag. I created a bag target like so:

load("@com_github_mvukov_rules_ros2//ros2:bag.bzl", "ros2_bag")

ros2_bag(
    name = "bag",
    idl_deps = [
        "@ros2_common_interfaces//:nav_msgs",
        "@ros2_common_interfaces//:sensor_msgs",
        "@ros2_common_interfaces//:std_msgs",
        "@ros2_rcl_interfaces//:rcl_interfaces",
        "@ros2_rosbag2//:rosbag2_interfaces",
    ],
)

When I run it using bazel, it works as expected. However, when I run it directly from bazel-bin, I get the following error:

$ ./bazel-bin/romalcpp/examples/ros2/bag info [path-to-bagfile]
Traceback (most recent call last):
  File "/home/kgk/src/romalorg/romalcpp/./bazel-bin/romalcpp/examples/ros2/bag.runfiles/__main__/romalcpp/examples/ros2/bag_launch.py", line 25, in <module>
    sys.exit(ros2cli.cli.main(extension=extension))
  File "/home/kgk/src/romalorg/romalcpp/bazel-bin/romalcpp/examples/ros2/bag.runfiles/ros2cli/ros2cli/ros2cli/cli.py", line 46, in main
    extension.add_arguments(parser, script_name)
  File "/home/kgk/src/romalorg/romalcpp/bazel-bin/romalcpp/examples/ros2/bag.runfiles/com_github_mvukov_rules_ros2/ros2/ros2_cmd.py", line 104, in add_arguments
    add_subparsers(parser,
  File "/home/kgk/src/romalorg/romalcpp/bazel-bin/romalcpp/examples/ros2/bag.runfiles/com_github_mvukov_rules_ros2/ros2/ros2_cmd.py", line 86, in add_subparsers
    extension.add_arguments(command_parser, f'{cli_name} {name}')
  File "/home/kgk/src/romalorg/romalcpp/bazel-bin/romalcpp/examples/ros2/bag.runfiles/ros2_rosbag2/ros2bag/ros2bag/verb/info.py", line 24, in add_arguments
    add_standard_reader_args(parser)
  File "/home/kgk/src/romalorg/romalcpp/bazel-bin/romalcpp/examples/ros2/bag.runfiles/ros2_rosbag2/ros2bag/ros2bag/api/__init__.py", line 125, in add_standard_reader_args
    reader_choices = rosbag2_py.get_registered_readers()
RuntimeError: package 'rosbag2_storage' not found, searching: []

Here is the example repository I have been using if that it helpful:
https://github.com/romalorg/romalcpp

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions