|
| 1 | +Migrating your package.xml to format 2 |
| 2 | +====================================== |
| 3 | + |
| 4 | +.. contents:: Table of Contents |
| 5 | + :depth: 2 |
| 6 | + :local: |
| 7 | + |
| 8 | +ROS 2 requires ``package.xml`` files to use at least `format 2 <https://ros.org/reps/rep-0140.html>`__. |
| 9 | +This guide shows how to migrate a ``package.xml`` from format 1 to format 2. |
| 10 | + |
| 11 | +If the ``<package>`` 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. |
| 12 | + |
| 13 | +.. code-block:: xml |
| 14 | +
|
| 15 | + <package> |
| 16 | +
|
| 17 | +.. code-block:: xml |
| 18 | +
|
| 19 | + <package format="1"> |
| 20 | +
|
| 21 | +
|
| 22 | +Prerequisites |
| 23 | +------------- |
| 24 | + |
| 25 | +You should have a working ROS 1 installation. |
| 26 | +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. |
| 27 | + |
| 28 | +Migrate from format 1 to 2 |
| 29 | +-------------------------- |
| 30 | + |
| 31 | +Format 1 and format 2 differ in how they specify dependencies. |
| 32 | +Read the `compatibility section in REP-0140 <https://www.ros.org/reps/rep-0140.html#compatibility>`__ for a summary of the differences. |
| 33 | + |
| 34 | +Add ``format`` attribute to ``<package>`` |
| 35 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 36 | + |
| 37 | +Add or set the ``format`` attribute to ``2`` to indicate that the ``package.xml`` uses format 2. |
| 38 | + |
| 39 | +.. code:: xml |
| 40 | +
|
| 41 | + <package format="2"> |
| 42 | +
|
| 43 | +Replace ``<run_depend>`` |
| 44 | +~~~~~~~~~~~~~~~~~~~~~~~~ |
| 45 | + |
| 46 | +The ``<run_depend>`` tag is no longer allowed. |
| 47 | +If you have a dependency specified like this: |
| 48 | + |
| 49 | +.. code:: xml |
| 50 | +
|
| 51 | + <run_depend>foo</run_depend> |
| 52 | +
|
| 53 | +then replace it with one or both of these tags: |
| 54 | + |
| 55 | +.. code:: xml |
| 56 | +
|
| 57 | + <build_export_depend>foo</build_export_depend> |
| 58 | + <exec_depend>foo</exec_depend> |
| 59 | +
|
| 60 | +If the dependency is needed when something in your package is executed, then use the ``<exec_depend>`` tag. |
| 61 | +If packages that depend on your package need the dependency when they are built, then use the ``<build_export_depend>`` tag. |
| 62 | +Use both tags if you are unsure. |
| 63 | + |
| 64 | +Convert some ``<build_depend>`` to ``<test_depend>`` |
| 65 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 66 | + |
| 67 | +In format 1 ``<test_depend>`` declares dependencies that are needed when running your package's tests. |
| 68 | +It still does that in format 2, but it additionally declares dependencies that are needed when building your package's tests. |
| 69 | + |
| 70 | +Because of the limitations of this tag in format 1, your package may have a test-only dependency specified as a ``<build_depend>`` like this: |
| 71 | + |
| 72 | +.. code:: xml |
| 73 | +
|
| 74 | + <build_depend>testfoo</build_depend> |
| 75 | +
|
| 76 | +If so, change it to a ``<test_depend>``. |
| 77 | + |
| 78 | +.. code:: xml |
| 79 | +
|
| 80 | + <test_depend>testfoo</test_depend> |
| 81 | +
|
| 82 | +.. note:: |
| 83 | + |
| 84 | + If you are using CMake, then make sure your test dependencies are only referenced within a ``if(BUILD_TESTING)`` block: |
| 85 | + |
| 86 | + .. code:: cmake |
| 87 | +
|
| 88 | + if (BUILD_TESTING) |
| 89 | + find_package(testfoo REQUIRED) |
| 90 | + endif() |
| 91 | +
|
| 92 | +Begin using ``<doc_depend>`` |
| 93 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 94 | + |
| 95 | +Use the new ``<doc_depend>`` tag to declare dependencies needed for building your package's documentation. |
| 96 | +For example, C++ packages might have this dependency: |
| 97 | + |
| 98 | +.. code:: xml |
| 99 | +
|
| 100 | + <doc_depend>doxygen</doc_depend> |
| 101 | +
|
| 102 | +while Python packages might have this one: |
| 103 | + |
| 104 | +.. code:: xml |
| 105 | +
|
| 106 | + <doc_depend>python3-sphinx</doc_depend> |
| 107 | +
|
| 108 | +See :doc:`the guide on documenting ROS 2 packages <../Documenting-a-ROS-2-Package>` for more information. |
| 109 | + |
| 110 | +Simplify dependencies with ``<depend>`` |
| 111 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 112 | + |
| 113 | +``<depend>`` is a new tag that makes ``package.xml`` files more concise. |
| 114 | +If your ``package.xml`` has these three tags for the same dependency: |
| 115 | + |
| 116 | +.. code:: |
| 117 | +
|
| 118 | + <build_depend>foo</build_depend> |
| 119 | + <build_export_depend>foo</build_export_depend> |
| 120 | + <exec_depend>foo</exec_depend> |
| 121 | +
|
| 122 | +then replace them with a single ``<depend>`` like this: |
| 123 | + |
| 124 | +.. code:: xml |
| 125 | +
|
| 126 | + <depend>foo</depend> |
| 127 | +
|
| 128 | +Test your new ``package.xml`` |
| 129 | +----------------------------- |
| 130 | + |
| 131 | +Build and test your package as you normally do using ``catkin_make``, ``cakin_make_isolated``, or the ``catkin`` build tool. |
| 132 | +If everything succeeds, then your ``package.xml`` is valid. |
0 commit comments