Skip to content

Commit

Permalink
Supply launch_file as cmdline to the base script
Browse files Browse the repository at this point in the history
Signed-off-by: Aditya Pande <[email protected]>
  • Loading branch information
adityapande-1995 committed Aug 24, 2023
1 parent 4276497 commit ba42a2b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
6 changes: 6 additions & 0 deletions bazel_ros2_rules/ros2/ros_py.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions bazel_ros2_rules/ros2/tools/roslaunch_base.py
Original file line number Diff line number Diff line change
@@ -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"])
11 changes: 8 additions & 3 deletions ros2_example_bazel_installed/ros2_example_apps/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down

0 comments on commit ba42a2b

Please sign in to comment.