You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, conan2 uses VirtualRunEnv and VirtualBuildEnv generators (this is briefly mentioned but is missing from the VirtualRunEnv doc).
However, if a generator (or anything from the top conanfile) instantiates VirtualRunEnv (or VirtualBuildEnv) for its own use, this will have a side effect, prevent the default behavior and VirtualRunEnv.generate() will never be called (so conanrun.sh won't be present).
A solution is to use the undocumented parameter auto_generate=True or to explicitly call self.virtual_run_env.generate() everytime VirtualRunEnv() is instantiated.
It would be nice to document the parameter, default behavior and side effect (if intended).
fromconan.tools.envimportVirtualBuildEnv, VirtualRunEnvclassMyGenerator:
def__init__(self, conanfile):
self._conanfile=conanfile# This will prevent `conanrun.sh` to be generatedself.virtual_run_env=VirtualRunEnv(conanfile, auto_generate=False)
self.virtual_build_env=VirtualBuildEnv(conanfile, auto_generate=False)
defgenerate(self):
pass
The text was updated successfully, but these errors were encountered:
We added the argument to allow our usage to not cause this effect, but we are also reconsidering if instantiating directly these generators elsewhere for the purpose of aggregating env-vars, but not generating environment script files is the way to go. We might refactor these generator into some base classes that don't generate files and can be used everywhere, but this is not fully clear yet.
In general I think it makes sense to think that if VirtualXXXEnv is instantiated by the user somewhere, the default behavior of not generating environment files is good, the user took control of the generation. So lets move it to the docs repo to add some clarification in the docs regarding this behavior and auto_generate, thanks!
By default, conan2 uses
VirtualRunEnv
andVirtualBuildEnv
generators (this is briefly mentioned but is missing from theVirtualRunEnv
doc).However, if a generator (or anything from the top conanfile) instantiates
VirtualRunEnv
(orVirtualBuildEnv
) for its own use, this will have a side effect, prevent the default behavior andVirtualRunEnv.generate()
will never be called (soconanrun.sh
won't be present).A solution is to use the undocumented parameter
auto_generate=True
or to explicitly callself.virtual_run_env.generate()
everytimeVirtualRunEnv()
is instantiated.It would be nice to document the parameter, default behavior and side effect (if intended).
Relevant code:
https://github.com/conan-io/conan/blob/ad0b39c228ecb6b5539fb5995c7a3e98f85c9bf9/conan/tools/env/virtualrunenv.py#L39-L40
The behavior was introduced in conan-io/conan#9543
How to reproduce it
The text was updated successfully, but these errors were encountered: