From b600e09730ac6a2004a4233ef54bded77f0202bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abril=20Rinc=C3=B3n=20Blanco?= Date: Tue, 29 Oct 2024 09:41:32 +0100 Subject: [PATCH 1/2] More docs on generators --- reference/conanfile/attributes/consumers.inc | 10 +++++++++ reference/conanfile/methods/package_info.rst | 23 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/reference/conanfile/attributes/consumers.inc b/reference/conanfile/attributes/consumers.inc index 39a135953790..95473c0d1d05 100644 --- a/reference/conanfile/attributes/consumers.inc +++ b/reference/conanfile/attributes/consumers.inc @@ -96,6 +96,16 @@ Should be only filled in the ``package_info()`` method. Read here :ref:`the complete reference of self.conf_info `. +generators_info +--------------- + +Generators to be passed to the dependant recipes. +Should be only filled in the ``package_info()`` method. + +.. seealso:: + + Read here :ref:`the complete reference of self.generators_info `. + deprecated ---------- diff --git a/reference/conanfile/methods/package_info.rst b/reference/conanfile/methods/package_info.rst index d6c8322551c9..a69afb05e230 100644 --- a/reference/conanfile/methods/package_info.rst +++ b/reference/conanfile/methods/package_info.rst @@ -296,6 +296,29 @@ configuration as: Note that this only propagates from the immediate, direct ``tool_requires`` of a recipe. +.. _conan_conanfile_model_generators_info: +generators_info +--------------- + +``tool_requires`` in the build context can inject generators into the recipe, +by adding them to the ``generators_info`` list inside the ``package_info`` method. +This is useful to inject custom generators into the recipe, that will be used by the consumers of the package, +just as if they were declared in their ``generators`` attribute. + +.. code-block:: python + + class MyGenerator: + def __init__(self, conanfile): + self._conanfile = conanfile + + def generate(self): + self.output.info(f"Calling custom generator for {conanfile}") + + def package_info(self): + self.generators_info.append(MyGenerator) + +Note that this only propagates from the immediate, direct ``tool_requires`` of a recipe. + .. note:: From 2306154950dea596e4263401a87e040de0fa3780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abril=20Rinc=C3=B3n=20Blanco?= Date: Tue, 29 Oct 2024 10:23:21 +0100 Subject: [PATCH 2/2] More docs for generators_info --- reference/conanfile/attributes/consumers.inc | 5 ++++- reference/conanfile/methods/package_info.rst | 4 ++++ reference/extensions/custom_generators.rst | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/reference/conanfile/attributes/consumers.inc b/reference/conanfile/attributes/consumers.inc index 95473c0d1d05..bb987874665c 100644 --- a/reference/conanfile/attributes/consumers.inc +++ b/reference/conanfile/attributes/consumers.inc @@ -99,12 +99,15 @@ Should be only filled in the ``package_info()`` method. generators_info --------------- +.. include:: ../../common/experimental_warning.inc + Generators to be passed to the dependant recipes. Should be only filled in the ``package_info()`` method. .. seealso:: - Read here :ref:`the complete reference of self.generators_info `. + See :ref:`an example usage here ` + and :ref:`the complete reference of self.generators_info `. deprecated ---------- diff --git a/reference/conanfile/methods/package_info.rst b/reference/conanfile/methods/package_info.rst index a69afb05e230..f812b037199f 100644 --- a/reference/conanfile/methods/package_info.rst +++ b/reference/conanfile/methods/package_info.rst @@ -297,9 +297,13 @@ Note that this only propagates from the immediate, direct ``tool_requires`` of a .. _conan_conanfile_model_generators_info: + generators_info --------------- +.. include:: ../../../common/experimental_warning.inc + + ``tool_requires`` in the build context can inject generators into the recipe, by adding them to the ``generators_info`` list inside the ``package_info`` method. This is useful to inject custom generators into the recipe, that will be used by the consumers of the package, diff --git a/reference/extensions/custom_generators.rst b/reference/extensions/custom_generators.rst index a1e454b99db5..d9a75a6d456c 100644 --- a/reference/extensions/custom_generators.rst +++ b/reference/extensions/custom_generators.rst @@ -100,6 +100,8 @@ argument: conan install --requires=zlib/1.2.13 -g MyGenerator +.. _reference_commands_custom_generators_tool_requires: + Generators from tool_requires -----------------------------