Custom metadata in package.xml

I am interested in adding custom metadata to the ROS-2 package.xml and providing a way to validate that other packages correctly define that metadata. However, when I attempt to add a new XML tag (e.g., ‘my_custom_tag’) ament fails during the validation process, with the following error:

$ ament build
Traceback (most recent call last):
  File "/ros2_ws/install/bin/ament", line 9, in <module>
    load_entry_point('ament-tools==0.0.0', 'console_scripts', 'ament')()
  File "/ros2_ws/install/lib/python3.5/site-packages/ament_tools/commands/ament.py", line 86, in main
    rc = args.main(args)
  File "/ros2_ws/install/lib/python3.5/site-packages/ament_tools/verbs/build/cli.py", line 154, in main
    packages = topological_order(opts.basepath)
  File "/ros2_ws/install/lib/python3.5/site-packages/ament_tools/topological_order.py", line 102, in topological_order
    packages = _find_unique_packages(root_dir)
  File "/ros2_ws/install/lib/python3.5/site-packages/ament_tools/packages.py", line 81, in find_unique_packages
    packages = find_packages(basepath, exclude_paths=exclude_paths)
  File "/ros2_ws/install/lib/python3.5/site-packages/ament_tools/packages.py", line 66, in find_packages
packages[path] = parse_package(os.path.join(basepath, path))
  File "/ros2_ws/install/lib/python3.5/site-packages/ament_tools/package_types/__init__.py", line 31, in parse_package
    pkg = package_type['parse_package'](path)
  File "/ros2_ws/install/lib/python3.5/site-packages/ament_package/__init__.py", line 60, in parse_package
return parse_package_string(f.read(), filename=filename)
  File "/ros2_ws/install/lib/python3.5/site-packages/ament_package/__init__.py", line 292, in parse_package_string
    (filename, ''.join(['\n- %s' % e for e in errors])))
ament_package.exceptions.InvalidPackage: Invalid package manifest './src/custom_package/package.xml': Error(s) in ./src/custom_package/package.xml:
- The 'url' tag must not contain the following children: my_custom_tag

Is there a recommended way to get around the validation that the package.xml contains no unknown tags? Is this even possible? I’d prefer not to have to branch ament_package.

It may make sense for companies/organizations to add their own custom metadata to packages and ideally they would not need to modify ament_package. In some/most cases this metadata is not something that would make sense to include in ament_package (e.g., company specific).

One option is to include the custom metadata in a separate XML file, but I would prefer to have a single file for package information.

Assuming I can get ament to accept the custom metadata (or I use a separate XML file), are there are suggestions on how best to validate the metadata at build/compile time? My plan is to provide some custom cmake scripts to perform the validation, but was curious if there are better approaches.

There’s space for custom tags in the export tag. See the documentation here http://www.ros.org/reps/rep-0140.html#export

I think that should satisfy your use case.

Thanks @tfoote for pointing that out – it should work for what I want to do.

1 Like