Skip to content

Commit 95108b8

Browse files
authored
More docs on generators (#3887)
* More docs on generators * More docs for generators_info
1 parent 315f3e9 commit 95108b8

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

reference/conanfile/attributes/consumers.inc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ Should be only filled in the ``package_info()`` method.
9696
Read here :ref:`the complete reference of self.conf_info <conan_conanfile_model_conf_info>`.
9797

9898

99+
generators_info
100+
---------------
101+
102+
.. include:: ../../common/experimental_warning.inc
103+
104+
Generators to be passed to the dependant recipes.
105+
Should be only filled in the ``package_info()`` method.
106+
107+
.. seealso::
108+
109+
See :ref:`an example usage here <reference_commands_custom_generators_tool_requires>`
110+
and :ref:`the complete reference of self.generators_info <conan_conanfile_model_generators_info>`.
111+
99112
deprecated
100113
----------
101114

reference/conanfile/methods/package_info.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,33 @@ configuration as:
296296
Note that this only propagates from the immediate, direct ``tool_requires`` of a recipe.
297297
298298
299+
.. _conan_conanfile_model_generators_info:
300+
301+
generators_info
302+
---------------
303+
304+
.. include:: ../../../common/experimental_warning.inc
305+
306+
307+
``tool_requires`` in the build context can inject generators into the recipe,
308+
by adding them to the ``generators_info`` list inside the ``package_info`` method.
309+
This is useful to inject custom generators into the recipe, that will be used by the consumers of the package,
310+
just as if they were declared in their ``generators`` attribute.
311+
312+
.. code-block:: python
313+
314+
class MyGenerator:
315+
def __init__(self, conanfile):
316+
self._conanfile = conanfile
317+
318+
def generate(self):
319+
self.output.info(f"Calling custom generator for {conanfile}")
320+
321+
def package_info(self):
322+
self.generators_info.append(MyGenerator)
323+
324+
Note that this only propagates from the immediate, direct ``tool_requires`` of a recipe.
325+
299326
300327
.. note::
301328

reference/extensions/custom_generators.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ argument:
100100
conan install --requires=zlib/1.2.13 -g MyGenerator
101101
102102
103+
.. _reference_commands_custom_generators_tool_requires:
104+
103105
Generators from tool_requires
104106
-----------------------------
105107

0 commit comments

Comments
 (0)