Migrating your package.xml to format 2
======================================
.. contents:: Table of Contents
:depth: 2
:local:
ROS 2 requires ``package.xml`` files to use at least `format 2 `__.
This guide shows how to migrate a ``package.xml`` from format 1 to format 2.
If the ```` tag at the start of your ``package.xml`` looks like either of the following, then it is using format 1 and you must migrate it.
.. code-block:: xml
.. code-block:: xml
Prerequisites
-------------
You should have a working ROS 1 installation.
This enables you to check that the converted ``package.xml`` is valid by building and testing the package, since ROS 1 supports all ``package.xml`` format versions.
Migrate from format 1 to 2
--------------------------
Format 1 and format 2 differ in how they specify dependencies.
Read the `compatibility section in REP-0140 `__ for a summary of the differences.
Add ``format`` attribute to ````
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Add or set the ``format`` attribute to ``2`` to indicate that the ``package.xml`` uses format 2.
.. code:: xml
Replace ````
~~~~~~~~~~~~~~~~~~~~~~~~
The ```` tag is no longer allowed.
If you have a dependency specified like this:
.. code:: xml
foo
then replace it with one or both of these tags:
.. code:: xml
foo
foo
If the dependency is needed when something in your package is executed, then use the ```` tag.
If packages that depend on your package need the dependency when they are built, then use the ```` tag.
Use both tags if you are unsure.
Convert some ```` to ````
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In format 1 ```` declares dependencies that are needed when running your package's tests.
It still does that in format 2, but it additionally declares dependencies that are needed when building your package's tests.
Because of the limitations of this tag in format 1, your package may have a test-only dependency specified as a ```` like this:
.. code:: xml
testfoo
If so, change it to a ````.
.. code:: xml
testfoo
.. note::
If you are using CMake, then make sure your test dependencies are only referenced within a ``if(BUILD_TESTING)`` block:
.. code:: cmake
if (BUILD_TESTING)
find_package(testfoo REQUIRED)
endif()
Begin using ````
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Use the new ```` tag to declare dependencies needed for building your package's documentation.
For example, C++ packages might have this dependency:
.. code:: xml
doxygen
while Python packages might have this one:
.. code:: xml
python3-sphinx
See :doc:`the guide on documenting ROS 2 packages <../Documenting-a-ROS-2-Package>` for more information.
Simplify dependencies with ````
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```` is a new tag that makes ``package.xml`` files more concise.
If your ``package.xml`` has these three tags for the same dependency:
.. code::
foo
foo
foo
then replace them with a single ```` like this:
.. code:: xml
foo
Test your new ``package.xml``
-----------------------------
Build and test your package as you normally do using ``catkin_make``, ``cakin_make_isolated``, or the ``catkin`` build tool.
If everything succeeds, then your ``package.xml`` is valid.