Skip to content

Commit

Permalink
Make roslaunch-check respect if/unless attribute on <include> (#998)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepurvis committed Mar 2, 2017
1 parent 4c4358f commit 8033da9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
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>
35 changes: 14 additions & 21 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))
elif tag.attributes.has_key('unless'):
if not convert_value(val, 'bool'):
return False
if 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

0 comments on commit 8033da9

Please sign in to comment.