Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filtering mechanism for executable prefix application #522

Merged
merged 10 commits into from Aug 24, 2021

Conversation

camm73
Copy link
Contributor

@camm73 camm73 commented Aug 18, 2021

In order to support the --launch-prefix-filter argument proposed in ros2/launch_ros#257, the regex filter supplied via the launch-prefix-filter LaunchConfiguration must be matched against the executable name. In the case of a match, the prefix passed via the launch-prefix LaunchConfiguration is prepended to the executable command. If a match is not found, the prefix is not applied.

Additionally, if the user provides a specific prefix for an executable in the launch file, the filter will be overridden and the prefix will be applied as expected.

Corresponding PR: ros2/launch_ros#261 will implement the --launch-prefix-filter argument into launch_ros.

Cameron Miller added 3 commits August 17, 2021 23:44
…utables

Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
@camm73 camm73 marked this pull request as draft August 18, 2021 22:51
@camm73 camm73 force-pushed the cameron/support-launch-prefix-filter branch from ad4dc2c to 1be7845 Compare August 18, 2021 23:47
Signed-off-by: Cameron Miller <cammlle@amazon.com>
@camm73 camm73 force-pushed the cameron/support-launch-prefix-filter branch from 1be7845 to 7177e69 Compare August 18, 2021 23:52
@camm73 camm73 marked this pull request as ready for review August 18, 2021 23:59
Comment on lines 691 to 700
filter_str = perform_substitutions(context, self.__prefix_filter)
regex_filter = None
if len(filter_str):
regex_filter = re.compile(filter_str)
if regex_filter is not None and regex_filter.match(os.path.basename(cmd[0])):
cmd = shlex.split(perform_substitutions(context, self.__prefix)) + cmd

# Apply to all if no filter is provided or filter is overridden
if regex_filter is None or self.__override_filter:
cmd = shlex.split(perform_substitutions(context, self.__prefix)) + cmd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@camm73 meta: hmm, if I read this correctly the prefix filter is irrelevant when a prefix is explicitly given. Nevermind the potential code simplification, that's actually a bit counter-intuitive when attempting to target an specific executable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking behind this was based on the fact that whenever a user sets a specific prefix in their launch file it currently overrides any launch-prefix provided in the launch configuration and applies the specific prefix:

self.__prefix = normalize_to_list_of_substitutions(
LaunchConfiguration('launch-prefix', default='') if prefix is None else prefix
)

Since the specific prefix already overrides a prefix passed via --launch-prefix, I figured it should also do the same when --launch-prefix and --launch-prefix-filter are used in conjunction, for the sake of consistency.

If you think it's more intuitive to remove the override_filter feature though, I can definitely do that.

Copy link
Contributor

@hidmic hidmic Aug 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured it should also do the same when --launch-prefix and --launch-prefix-filter are used in conjunction, for the sake of consistency.

That's fair. Should be fine so long as we document it.

If you think it's more intuitive to remove the override_filter feature though, I can definitely do that.

Not so much removing the feature. My naive (and wrong) expectation coming into launch could be that ros2 launch --launch-prefix-filter some_executable --launch-prefix gdb --args takes precedence for some_executable over whatever was specified as prefix. So long as we document this is NOT the case, it'll be fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifically, let's document this behavior in ExecuteProcess.__init__() docstring.

launch/launch/actions/execute_process.py Outdated Show resolved Hide resolved
launch/launch/actions/execute_process.py Outdated Show resolved Hide resolved
launch/launch/actions/execute_process.py Outdated Show resolved Hide resolved
launch/test/launch/test_execute_process.py Show resolved Hide resolved
Comment on lines 691 to 700
filter_str = perform_substitutions(context, self.__prefix_filter)
regex_filter = None
if len(filter_str):
regex_filter = re.compile(filter_str)
if regex_filter is not None and regex_filter.match(os.path.basename(cmd[0])):
cmd = shlex.split(perform_substitutions(context, self.__prefix)) + cmd

# Apply to all if no filter is provided or filter is overridden
if regex_filter is None or self.__override_filter:
cmd = shlex.split(perform_substitutions(context, self.__prefix)) + cmd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifically, let's document this behavior in ExecuteProcess.__init__() docstring.

camm73 and others added 5 commits August 23, 2021 18:25
Co-authored-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Co-authored-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Co-authored-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
@camm73 camm73 force-pushed the cameron/support-launch-prefix-filter branch from a23f33c to 9db2e8d Compare August 23, 2021 19:14
@camm73 camm73 requested a review from hidmic August 23, 2021 19:21
Copy link
Contributor

@hidmic hidmic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM

CI up to launch, launch_ros, and test_launch_ros:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

launch/launch/actions/execute_process.py Outdated Show resolved Hide resolved
Signed-off-by: Cameron Miller <cammlle@amazon.com>
@hidmic
Copy link
Contributor

hidmic commented Aug 24, 2021

Alright, going in!

@hidmic hidmic merged commit 83700f5 into ros2:master Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants