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

Fix $(dirname) for roslaunch-check. #1624

Merged

Conversation

mikepurvis
Copy link
Member

Small fix for using $(dirname) in launch files covered by the roslaunch-check tests. Currently you get the test failing with a traceback like this:

Traceback (most recent call last):
  File "<ws>/share/roslaunch/scripts/roslaunch-check", line 90, in <module>
    error_msg = check_roslaunch_file(roslaunch_path, use_test_depends=options.test_depends)
  File "<ws>/share/roslaunch/scripts/roslaunch-check", line 47, in check_roslaunch_file
    error_msg = roslaunch.rlutil.check_roslaunch(roslaunch_file, use_test_depends=use_test_depends)
  File "<ws>/lib/python2.7/dist-packages/roslaunch/rlutil.py", line 201, in check_roslaunch
    base_pkg, file_deps, missing = roslaunch.depends.roslaunch_deps([f], use_test_depends=use_test_depends)
  File "<ws>/lib/python2.7/dist-packages/roslaunch/depends.py", line 332, in roslaunch_deps
    rl_file_deps(file_deps, launch_file, verbose)
  File "<ws>/lib/python2.7/dist-packages/roslaunch/depends.py", line 226, in rl_file_deps
    parse_launch(launch_file, file_deps, verbose)
  File "<ws>/lib/python2.7/dist-packages/roslaunch/depends.py", line 211, in parse_launch
    _parse_launch(launch_tag.childNodes, launch_file, file_deps, verbose, context)
  File "<ws>/lib/python2.7/dist-packages/roslaunch/depends.py", line 141, in _parse_launch
    sub_launch_file = resolve_args(tag.attributes['file'].value, context)
  File "<ws>/lib/python2.7/dist-packages/roslaunch/substitution_args.py", line 389, in resolve_args
    resolved = _resolve_args(arg_str, context, resolve_anon, commands)
  File "<ws>/lib/python2.7/dist-packages/roslaunch/substitution_args.py", line 407, in _resolve_args
    resolved = commands[command](resolved, a, args, context)
  File "<ws>/lib/python2.7/dist-packages/roslaunch/substitution_args.py", line 136, in _dirname
    return resolved.replace("$(%s)" % a, _eval_dirname(context.get('filename', None)))
  File "<ws>/lib/python2.7/dist-packages/roslaunch/substitution_args.py", line 125, in _eval_dirname
    raise SubstitutionException("Cannot substitute $(dirname), no file/directory information available.")
roslaunch.substitution_args.SubstitutionException: Cannot substitute $(dirname), no file/directory information available.

The file/directory information it's referring to comes in via xmlloader, here:

def resolve_args(self, args, context):
"""
Wrapper around substitution_args.resolve_args to set common parameters
"""
# resolve_args gets called a lot, so we optimize by testing for dollar sign before resolving
if args and '$' in args:
# Populate resolve_dict with name of the current file being processed.
context.resolve_dict['filename'] = context.filename
return substitution_args.resolve_args(args, context=context.resolve_dict, resolve_anon=self.resolve_anon)
else:
return args

However, roslaunch-check bypasses this logic so the context value never gets set. This change corrects that.

@dirk-thomas
Copy link
Member

Thanks for the patch.

@dirk-thomas dirk-thomas merged commit c8e63ee into ros:melodic-devel Mar 29, 2019
@mikepurvis mikepurvis deleted the fix-dirname-roslaunch-check branch April 2, 2019 18:46
tahsinkose pushed a commit to tahsinkose/ros_comm that referenced this pull request Apr 15, 2019
dirk-thomas pushed a commit that referenced this pull request Aug 4, 2020
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.

2 participants