VirtualBuildEnv is a generator that produces a conanbuildenv .bat or .sh script containing the environment variables of the build time context:
- From the
self.buildenv_infoof the direct
tool_requiresin “build” context.
- From the
self.runenv_infoof the transitive dependencies of those
It can be used by name in conanfiles:
class Pkg(ConanFile): generators = "VirtualBuildEnv"
And it can also be fully instantiated in the conanfile
from conan import ConanFile from conan.tools.env import VirtualBuildEnv class Pkg(ConanFile): settings = "os", "compiler", "arch", "build_type" requires = "zlib/1.2.11", "bzip2/1.0.8" def generate(self): ms = VirtualBuildEnv(self) ms.generate()
This generator (for example the invocation of
conan install --tool-require=cmake/3.20.0@ -g VirtualBuildEnv)
will create the following files:
- conanbuildenv-release-x86_64.(bat|sh): This file contains the actual definition of environment variables
like PATH, LD_LIBRARY_PATH, etc, and any other variable defined in the dependencies
buildenv_infocorresponding to the
buildcontext, and to the current installed configuration. If a repeated call is done with other settings, a different file will be created. After the execution or sourcing of this file, a new deactivation script will be generated, capturing the current environment, so the environment can be restored when desired. The file will be named also following the current active configuration, like
- conanbuild.(bat|sh): Accumulates the calls to one or more other scripts, in case there are multiple tools
in the generate process that create files, to give one single convenient file for all. This only calls
the latest specific configuration one, that is, if
conan installis called first for Release build type, and then for Debug,
conanbuild.(bat|sh)script will call the Debug one.
- deactivate_conanbuild.(bat|sh): Accumulates the deactivation calls defined in the above
conanbuild.(bat|sh). This file should only be called after the accumulated activate has been called first.
Calculates the environment variables of the build time context and produces a conanbuildenv .bat or .sh script
Environmentobject containing the environment variables of the build context.
Environmentobject instance containing the obtained variables.
Parameters: scope – Scope to be used. Returns: An
EnvVarsinstance containing the computed environment variables.
Produces the launcher scripts activating the variables for the build context.
Parameters: scope – Scope to be used.