Skip to content

Commit fe86f13

Browse files
authored
Merge pull request #4388 from memsharded/feature/virtualenvs_disable
virtualenvs disabling
1 parent 654f449 commit fe86f13

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

reference/tools/env/virtualbuildenv.rst

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,52 @@ will create the following files:
107107
Please open a Github ticket to report any feedback about this feature.
108108

109109

110-
.. note::
111110

112-
Disabling the automatic generation of these files for consumers can be achieved by passing ``--envs-generation=false`` to the ``conan install`` command.
113-
**This feature is experimental and subject to change**, and disabling this file can lead to unexpected build errors,
114-
if for example ``tool_requires`` are used. Ensure they are not needed if the generation is disabled.
111+
.. _reference_tools_env_virtualbuildenv_disable:
112+
113+
Disabling VirtualBuildEnv
114+
-------------------------
115+
116+
It is possible to disable the generation of the ``VirtualBuildEnv`` and ``VirtualRunEnv`` files with
117+
different mechanisms:
118+
119+
- By passing ``--envs-generation=false`` to the ``conan install`` command, it will disable the generation
120+
of environment files (both ``VirtualBuildEnv`` and ``VirtualRunEnv``) for the current consumer only
121+
(dependencies that need to be built from source will generate their own environment files as needed).
122+
**This feature is experimental and subject to change**.
123+
- Recipes can instantiate a ``VirtualBuildEnv(self)`` in their ``generate()`` method, without calling
124+
their ``generate()`` method. That will inhibit the creation of environment files for that specific
125+
recipe:
126+
127+
.. code-block:: python
128+
129+
def generate(self):
130+
VirtualBuildEnv(self)
131+
# do not call its generate() method
132+
# discouraged, in most cases, it is desired
133+
# to call generate()
134+
VirtualRunEnv(self)
135+
# Same for VirtualRunEnv
136+
137+
- Recipes can directly define their ``virtualbuildenv = False`` attribute to inhibit the automatic
138+
default creation of ``VirtualBuildEnv`` files for this recipe:
139+
140+
.. code-block:: python
141+
142+
class Pkg(ConanFile):
143+
virtualbuildenv = False
144+
# Also for VirtualRunEnv
145+
virtualrunenv = False
146+
147+
148+
.. warning::
149+
150+
In general, disabling the generation of environment files is **discouraged**. Environment files are the
151+
mechanism use for things like ``[tool_requires]`` defined in the profiles to be able to inject those
152+
tools dynamically in dependencies, even if those dependencies didn't directly declare such
153+
``tool_requires``. Without proper ``VirtualBuildEnv`` files in the recipe, the ``tool_requires`` will
154+
fail to apply.
155+
115156

116157
Reference
117158
---------

reference/tools/env/virtualrunenv.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ current active configuration, like ``deactivate_conanrunenv-release-x86_64.bat``
8080

8181
.. note::
8282

83-
Disabling the automatic generation of these files for consumers can be achieved by passing ``--env-generation=false`` to the ``conan install`` command.
84-
**This feature is experimental and subject to change**, and disabling this file can lead to unexpected runtime errors.
83+
For disabling the automatic generation of environment files, check :ref:`reference_tools_env_virtualbuildenv_disable`
84+
8585

8686
Reference
8787
---------

0 commit comments

Comments
 (0)