From 9dba3957f19b089a307d74460c3baf244249f5d2 Mon Sep 17 00:00:00 2001 From: Yuki Furuta Date: Fri, 22 May 2026 10:43:41 -0700 Subject: [PATCH] Resolve runfiles in launch_exec.*.tpl --- ros2/cc_defs.bzl | 3 ++- ros2/launch_exec.py.tpl | 3 ++- ros2/launch_exec.sh.tpl | 6 ++++-- ros2/py_defs.bzl | 3 ++- ros2/rust_defs.bzl | 3 ++- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ros2/cc_defs.bzl b/ros2/cc_defs.bzl index 524c5407..010bbaef 100644 --- a/ros2/cc_defs.bzl +++ b/ros2/cc_defs.bzl @@ -87,7 +87,7 @@ def _ros2_cpp_exec(target, name, ros2_package_name, set_up_ament, idl_deps, **kw ament_setup_deps = ament_setup_deps, template = "@com_github_mvukov_rules_ros2//ros2:launch_exec.sh.tpl", substitutions = { - "{entry_point}": "$(rootpath {})".format(target_impl), + "{entry_point}": "$(rlocationpath {})".format(target_impl), }, tags = ["manual"], data = [target_impl], @@ -100,6 +100,7 @@ def _ros2_cpp_exec(target, name, ros2_package_name, set_up_ament, idl_deps, **kw name = name, srcs = [launcher], data = [target_impl], + use_bash_launcher = True, **launcher_target_kwargs ) diff --git a/ros2/launch_exec.py.tpl b/ros2/launch_exec.py.tpl index 5b6a2cd6..84189826 100644 --- a/ros2/launch_exec.py.tpl +++ b/ros2/launch_exec.py.tpl @@ -1,5 +1,6 @@ import os import sys +from python.runfiles import runfiles env = os.environ.copy() @@ -16,5 +17,5 @@ if not ament_prefix_path: else: env["AMENT_PREFIX_PATH"] = ament_prefix_path -entry_point = "{entry_point}" +entry_point = runfiles.Create().Rlocation("{entry_point}") os.execve(entry_point, [entry_point, *sys.argv[1:]], env) diff --git a/ros2/launch_exec.sh.tpl b/ros2/launch_exec.sh.tpl index ab6f5792..46b239d0 100644 --- a/ros2/launch_exec.sh.tpl +++ b/ros2/launch_exec.sh.tpl @@ -12,10 +12,12 @@ if [ -n "${BAZEL_TEST:-}" ]; then fi fi +ENTRYPOINT="$(rlocation {entry_point})" + ament_prefix_path="{{ament_prefix_path}}" if [ -z "${ament_prefix_path}" ]; then unset AMENT_PREFIX_PATH - exec {entry_point} "$@" + exec ${ENTRYPOINT} "$@" else - AMENT_PREFIX_PATH="${ament_prefix_path}" exec {entry_point} "$@" + AMENT_PREFIX_PATH="${ament_prefix_path}" exec ${ENTRYPOINT} "$@" fi diff --git a/ros2/py_defs.bzl b/ros2/py_defs.bzl index 40fef7e3..1a98abd0 100644 --- a/ros2/py_defs.bzl +++ b/ros2/py_defs.bzl @@ -37,7 +37,7 @@ def _ros2_py_exec(target, name, srcs, main, set_up_ament, testonly, **kwargs): ament_setup_deps = ament_setup_deps, template = "@com_github_mvukov_rules_ros2//ros2:launch_exec.py.tpl", substitutions = { - "{entry_point}": "$(rootpath {})".format(target_impl_symlink), + "{entry_point}": "$(rlocationpath {})".format(target_impl_symlink), }, tags = ["manual"], data = [target_impl_symlink], @@ -50,6 +50,7 @@ def _ros2_py_exec(target, name, srcs, main, set_up_ament, testonly, **kwargs): srcs = [launcher], main = launcher + ".py", data = [target_impl_symlink], + deps = ["@rules_python//python/runfiles"], **launcher_target_kwargs ) diff --git a/ros2/rust_defs.bzl b/ros2/rust_defs.bzl index cae114a4..1559c1a6 100644 --- a/ros2/rust_defs.bzl +++ b/ros2/rust_defs.bzl @@ -32,7 +32,7 @@ def ros2_rust_test(name, **kwargs): name = launcher, template = "@com_github_mvukov_rules_ros2//ros2:launch_exec.sh.tpl", substitutions = { - "{entry_point}": "$(rootpath {})".format(target_impl), + "{entry_point}": "$(rlocationpath {})".format(target_impl), }, tags = ["manual"], data = [target_impl], @@ -43,5 +43,6 @@ def ros2_rust_test(name, **kwargs): name = name, srcs = [launcher], data = [target_impl], + use_bash_launcher = True, **launcher_target_kwargs )