VirtualEnv
Warning
This is a very experimental feature and it will have breaking changes in future releases.
The VirtualEnv generator can be used by name in conanfiles:
class Pkg(ConanFile):
generators = "VirtualEnv"
[generators]
VirtualEnv
And it can also be fully instantiated in the conanfile generate() method:
from conans import ConanFile
from conan.tools.env import VirtualEnv
class Pkg(ConanFile):
settings = "os", "compiler", "arch", "build_type"
requires = "zlib/1.2.11", "bzip2/1.0.8"
def generate(self):
ms = VirtualEnv(self)
ms.generate()
When the VirtualEnv generator is used, calling conan install will generate files containing environment variables information:
conanbuildenv .bat or .sh scripts, that are automatically loaded if existing by the
self.run()recipes methods. conanbuildenv is the build time environment information. It is collected from the directbuild_requiresin “build” context recipes from theself.buildenv_infodefinition plus theself.runenv_infoof the transitive dependencies of thosebuild_requires.conanrunenv .bat or .sh scripts, that can be explicitly opted-in in
self.run()recipes methods withself.run(..., env=["conanrunenv"]). conanrunenv is the runtime environment information, anything that is necessary in the environment to actually run the compiled executables and applications.In both cases, whenever the runtime environment information is necessary, it wil also be automatically deduced from the
self.cpp_infodefinition of the package, to definePATH,LD_LIBRARY_PATH,DYLD_LIBRARY_PATHandDYLD_FRAMEWORK_PATHenvironment variables.