Skip to content

Commit

Permalink
tracking host version (#3197)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded authored May 11, 2023
1 parent 7bfb4f8 commit b512cfa
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
4 changes: 3 additions & 1 deletion reference/conanfile/methods.rst
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,9 @@ This method is useful for defining conditional tool requirements, for example:
.. seealso::

:ref:`Tool requirements <build_requires>`
- :ref:`Tool requirements <build_requires>`
- Read how a ``tool_requires("pkg/<host_version>")`` can track the version of the host context :ref:`in this section <tracking_host_versions>`


.. _method_system_requirements:

Expand Down
36 changes: 36 additions & 0 deletions versioning/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,42 @@ for normal dependencies versions management.**
default in Conan 2.0 while removing the previous one.


.. _tracking_host_versions:

Tracking host versions
++++++++++++++++++++++

New since Conan 1.60.

.. warning::

This is an **experimental** feature, added as a backport from Conan 2.0, subject to breaking changes in future releases.


When there are packages that are required both in the "host" context and in the "build" context with ``tool_requires``, sometimes
it is necessary to align the versions of both. This is possible with the ``<host_version>`` version specification:


.. code-block:: python
from conan import ConanFile
class ProtoBuf(ConanFile):
name = "pkg"
version = "0.1"
def requirements(self):
self.requires("protobuf/1.0")
def build_requirements(self):
self.tool_requires("protobuf/<host_version>")
The ``<host_version>`` will take the version from the regular ``requires``, so in this case, this recipe will ``tool_requires`` ``protobuf/1.0``.
Note this can be useful if for some reason the "host" requirement changes, like when it is overridden from downstream, or if it defined
a version range and resolved to another version.


Package revisions
+++++++++++++++++

Expand Down

0 comments on commit b512cfa

Please sign in to comment.