From ba42a2b79e19dcd281e45aee2194547a22dd5417 Mon Sep 17 00:00:00 2001 From: Aditya Pande Date: Thu, 24 Aug 2023 05:02:30 +0000 Subject: [PATCH] Supply launch_file as cmdline to the base script Signed-off-by: Aditya Pande --- bazel_ros2_rules/ros2/ros_py.bzl | 6 ++++++ bazel_ros2_rules/ros2/tools/roslaunch_base.py | 11 +++++++++-- .../ros2_example_apps/BUILD.bazel | 11 ++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/bazel_ros2_rules/ros2/ros_py.bzl b/bazel_ros2_rules/ros2/ros_py.bzl index cb69f46a..a54ec02d 100644 --- a/bazel_ros2_rules/ros2/ros_py.bzl +++ b/bazel_ros2_rules/ros2/ros_py.bzl @@ -130,6 +130,9 @@ def ros_py_binary( ) py_binary_rule(name = name, **kwargs) +def _impl_ros_launch(ctx): + pass + def ros_launch( name, main = "@bazel_ros2_rules//ros2:roslaunch_base.py", @@ -143,12 +146,15 @@ def ros_launch( kwargs["data"] = [] if "srcs" not in kwargs.keys(): kwargs["srcs"] = [] + if "args" not in kwargs.keys(): + kwargs["args"] = [] kwargs["deps"] += ["@ros2//:ros2"] kwargs["deps"] += ["@bazel_ros2_rules//ros2:roslaunch_base.py"] kwargs["srcs"] = ["@bazel_ros2_rules//ros2:roslaunch_base.py"] kwargs["data"] += [launch_file] + kwargs["args"] += [launch_file] ros_py_binary( name = name, diff --git a/bazel_ros2_rules/ros2/tools/roslaunch_base.py b/bazel_ros2_rules/ros2/tools/roslaunch_base.py index 19039d8a..8bfe01b7 100644 --- a/bazel_ros2_rules/ros2/tools/roslaunch_base.py +++ b/bazel_ros2_rules/ros2/tools/roslaunch_base.py @@ -1,6 +1,13 @@ import subprocess +import sys -print("Hello world from roslaunch_base") +print("ARGS: ", sys.argv[1:]) +launch_file_name = sys.argv[1] +launch_file_dir = "ros2_example_apps" -subprocess.run(["./external/ros2/ros2", "launch", "ros2_example_apps/eg_launch.py"]) +roslaunch_cli = "./external/ros2/ros2" +action = "launch" +launch_file = launch_file_dir + "/" + launch_file_name + +subprocess.run([roslaunch_cli, action, launch_file]) # subprocess.run(["/bin/bash"]) diff --git a/ros2_example_bazel_installed/ros2_example_apps/BUILD.bazel b/ros2_example_bazel_installed/ros2_example_apps/BUILD.bazel index 5f9b1c48..66cc4ceb 100644 --- a/ros2_example_bazel_installed/ros2_example_apps/BUILD.bazel +++ b/ros2_example_bazel_installed/ros2_example_apps/BUILD.bazel @@ -201,12 +201,17 @@ ros_py_binary( ], ) +# ROS launch example. +ros_py_binary( + name = "eg_talker", + srcs = ["eg_talker.py"], +) + ros_launch( name = "roslaunch_eg", launch_file = "eg_launch.py", - # Should contain executables to be run. - data = [ - "eg_talker.py", + deps = [ + ":eg_talker", ], )