Skip to content

Commit be02ed7

Browse files
authored
dotenv new feature (#4246)
1 parent da15d41 commit be02ed7

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

reference/tools/env/environment.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,28 @@ by default, but the ``separator`` argument can be provided to define a custom on
3838
The "path" variables (the ones declared with ``define_path``, ``append_path`` and ``prepend_path``) will be appended
3939
with the default system path separator, either ``:`` or ``;``, but it also allows defining which one.
4040

41+
Generation of environment files
42+
+++++++++++++++++++++++++++++++
43+
44+
The generation of environment script files (like ``envfile.bat|.sh|.ps1|.env``) can be done indirectly
45+
by the ``EnvVars`` class, which can be obtained with:
46+
47+
.. code:: python
48+
49+
from conan.tools.env import Environment
50+
51+
env1 = Environment()
52+
...
53+
envvars = env1.vars(self) # An EnvVars object
54+
# Generate a .bat|.sh|.ps1|.env file depending on current
55+
# settings and Conan configuration
56+
envars.save_script("mybuild")
57+
# or decide to be explicit and generate some of the files:
58+
envvars.save_dotenv("myenv.env")
59+
60+
These files can be used also automatically by subsequent ``self.run()`` calls.
61+
For more information see the ``EnvVars`` class documentation.
62+
4163

4264
Composition
4365
+++++++++++

reference/tools/env/envvars.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ aggregate and create a ``conanrun.bat|sh|ps1`` script:
5858
envvars.save_script("my_env_file")
5959
6060
61+
From Conan 2.21, if the **experimental** ``tools.env:dotenv`` configuration is active, then
62+
``.env`` files will also be generated. These files are not intended to be activated as scripts,
63+
but loaded by tools such as IDEs.
64+
65+
6166
You can also use ``scope=None`` argument to avoid appending the script to the aggregated ``conanbuild.bat|sh|ps1``:
6267

6368
.. code:: python

reference/tools/env/virtualbuildenv.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ will create the following files:
9595
or ``False`` is deprecated as of Conan 2.11.0 and should no longer be used.
9696

9797

98+
.. note::
99+
100+
To create ``.env`` dotenv files, use the **experimental** (new in Conan 2.21) ``tools.env:dotenv`` configuration.
101+
These files are not intended to be activated as scripts, but loaded by tools such as IDEs.
102+
The configuration specific files such as ``conanbuildenv-Release.env`` will be generated, as the
103+
environment can be different for Release and Debug configurations.
104+
These files at the moment do not use variable interpolation due to some VScode limitations,
105+
a warning is printed pointing to https://github.com/microsoft/vscode-cpptools/issues/13781 to
106+
track progress.
107+
Please open a Github ticket to report any feedback about this feature.
108+
109+
98110
.. note::
99111

100112
Disabling the automatic generation of these files for consumers can be achieved by passing ``--envs-generation=false`` to the ``conan install`` command.

reference/tools/env/virtualrunenv.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ current active configuration, like ``deactivate_conanrunenv-release-x86_64.bat``
6767
executable (e.g., ``powershell.exe`` or ``pwsh``). Note that, setting it to ``True``
6868
or ``False`` is deprecated as of Conan 2.11.0 and should no longer be used.
6969

70+
.. note::
71+
72+
To create ``.env`` dotenv files, use the **experimental** (new in Conan 2.21) ``tools.env:dotenv`` configuration.
73+
These files are not intended to be activated as scripts, but loaded by tools such as IDEs.
74+
The configuration specific files such as ``conanrunenv-Release.env`` will be generated, as the
75+
environment can be different for Release and Debug configurations.
76+
These files at the moment do not use variable interpolation due to some VScode limitations,
77+
a warning is printed pointing to https://github.com/microsoft/vscode-cpptools/issues/13781 to
78+
track progress.
79+
Please open a Github ticket to report any feedback about this feature.
80+
7081
.. note::
7182

7283
Disabling the automatic generation of these files for consumers can be achieved by passing ``--env-generation=false`` to the ``conan install`` command.

0 commit comments

Comments
 (0)