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

Make roslaunch-check respect if/unless attribute on <include> #998

Merged
merged 1 commit into from
Apr 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tools/roslaunch/resources/example.launch
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,15 @@
<!-- more compact import syntax -->
<include ns="included2" file="$(find roslaunch)/resources/example-include.launch" />

<!-- Pass over an include and node with if-attributes that evaluate to false. -->
<arg name="false_arg" value="false" />
<include if="$(arg false_arg)" file="does/not/exist.launch" />
<node if="$(arg false_arg)" pkg="doesnt_exist" type="nope" name="nope" />

<!-- Pass over a group with an unless-attribute that evaluate to true. -->
<arg name="true_arg" value="true" />
<group unless="$(arg true_arg)">
<include file="does/not/exist.launch" />
<node pkg="doesnt_exist" type="nope" name="nope" />
</group>
</launch>
33 changes: 13 additions & 20 deletions tools/roslaunch/src/roslaunch/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

import rospkg

from .loader import convert_value
from .substitution_args import resolve_args

NAME="roslaunch-deps"
Expand Down Expand Up @@ -94,20 +95,16 @@ def _get_arg_value(tag, context):
else:
raise RoslaunchDepsException("No value for arg [%s]"%(name))

def _parse_arg(tag, context):
name = tag.attributes['name'].value
def _check_ifunless(tag, context):
if tag.attributes.has_key('if'):
val = resolve_args(tag.attributes['if'].value, context)
if val == '1' or val == 'true':
return (name, _get_arg_value(tag, context))
if not convert_value(val, 'bool'):
return False
elif tag.attributes.has_key('unless'):
val = resolve_args(tag.attributes['unless'].value, context)
if val == '0' or val == 'false':
return (name, _get_arg_value(tag, context))
else:
return (name, _get_arg_value(tag, context))
# nothing to return (no value, or conditional wasn't satisfied)
return None
if convert_value(val, 'bool'):
return False
return True

def _parse_subcontext(tags, context):
subcontext = {'arg': {}}
Expand All @@ -116,12 +113,8 @@ def _parse_subcontext(tags, context):
return subcontext

for tag in [t for t in tags if t.nodeType == DomNode.ELEMENT_NODE]:
if tag.tagName == 'arg':
# None is returned for args with if/unless that evaluate to false
ret = _parse_arg(tag, context)
if ret is not None:
(name, val) = ret
subcontext['arg'][name] = val
if tag.tagName == 'arg' and _check_ifunless(tag, context):
subcontext['arg'][tag.attributes['name'].value] = _get_arg_value(tag, context)
return subcontext

def _parse_launch(tags, launch_file, file_deps, verbose, context):
Expand All @@ -130,17 +123,17 @@ def _parse_launch(tags, launch_file, file_deps, verbose, context):

# process group, include, node, and test tags from launch file
for tag in [t for t in tags if t.nodeType == DomNode.ELEMENT_NODE]:
if not _check_ifunless(tag, context):
continue

if tag.tagName == 'group':

#descend group tags as they can contain node tags
_parse_launch(tag.childNodes, launch_file, file_deps, verbose, context)

elif tag.tagName == 'arg':
v = _parse_arg(tag, context)
if v:
(name, val) = v
context['arg'][name] = val
context['arg'][tag.attributes['name'].value] = _get_arg_value(tag, context)

elif tag.tagName == 'include':
try:
sub_launch_file = resolve_args(tag.attributes['file'].value, context)
Expand Down