Skip to content

Commit 2e4f17e

Browse files
committed
Add prefix filtering to Executable description class.
Distro A, OPSEC #4584. You may have additional rights; please see https://rosmilitary.org/faq/?category=ros-2-license Signed-off-by: matthew.lanting <[email protected]>
1 parent 50631d9 commit 2e4f17e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

launch/launch/descriptions/executable.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"""Module for a description of an Executable."""
1919

2020
import os
21+
import re
2122
import shlex
2223
import threading
2324
from typing import Dict
@@ -59,7 +60,10 @@ def __init__(
5960
and Substitutions to be resolved at runtime
6061
:param: prefix a set of commands/arguments to preceed the cmd, used for
6162
things like gdb/valgrind and defaults to the LaunchConfiguration
62-
called 'launch-prefix'
63+
called 'launch-prefix'. Note that a non-default prefix provided in
64+
a launch file will override the prefix provided via the `launch-prefix`
65+
launch configuration regardless of whether the `launch-prefix-filter` launch
66+
configuration is provided.
6367
:param name: The label used to represent the process, as a string or a Substitution
6468
to be resolved at runtime, defaults to the basename of the executable
6569
:param cwd: The directory in which to run the executable
@@ -76,6 +80,9 @@ def __init__(
7680
self.__prefix = normalize_to_list_of_substitutions(
7781
LaunchConfiguration('launch-prefix', default='') if prefix is None else prefix
7882
)
83+
self.__prefix_filter = normalize_to_list_of_substitutions(
84+
LaunchConfiguration('launch-prefix-filter', default='')
85+
) if prefix is None else None
7986
self.__name = name if name is None else normalize_to_list_of_substitutions(name)
8087
self.__cwd = cwd if cwd is None else normalize_to_list_of_substitutions(cwd)
8188
self.__env = None # type: Optional[List[Tuple[List[Substitution], List[Substitution]]]]
@@ -165,7 +172,14 @@ def prepare(self, context: LaunchContext, action: Action):
165172
"""
166173
# expand substitutions in arguments to async_execute_process()
167174
cmd = [perform_substitutions(context, x) for x in self.__cmd]
168-
cmd = shlex.split(perform_substitutions(context, self.__prefix)) + cmd
175+
# Perform filtering for prefix application
176+
should_apply_prefix = True # by default
177+
if self.__prefix_filter is not None: # no prefix given on construction
178+
prefix_filter = perform_substitutions(context, self.__prefix_filter)
179+
# Apply if filter regex matches (empty regex matches all strings)
180+
should_apply_prefix = re.match(prefix_filter, os.path.basename(cmd[0]))
181+
if should_apply_prefix:
182+
cmd = shlex.split(perform_substitutions(context, self.__prefix)) + cmd
169183
self.__final_cmd = cmd
170184
name = os.path.basename(cmd[0]) if self.__name is None \
171185
else perform_substitutions(context, self.__name)

0 commit comments

Comments
 (0)