Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[missing doc] Undocumented side-effect and parameter auto_generate #3676

Open
araffin opened this issue Apr 11, 2024 · 1 comment
Open

[missing doc] Undocumented side-effect and parameter auto_generate #3676

araffin opened this issue Apr 11, 2024 · 1 comment
Assignees
Milestone

Comments

@araffin
Copy link

araffin commented Apr 11, 2024

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).

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

from conan.tools.env import VirtualBuildEnv, VirtualRunEnv

class MyGenerator:
    def __init__(self, conanfile):
        self._conanfile = conanfile
        # This will prevent `conanrun.sh` to be generated
        self.virtual_run_env = VirtualRunEnv(conanfile, auto_generate=False)
        self.virtual_build_env = VirtualBuildEnv(conanfile, auto_generate=False)

    def generate(self):
        pass
@memsharded memsharded self-assigned this Apr 11, 2024
@memsharded
Copy link
Member

Thanks @araffin for reporting this.

It is true that https://docs.conan.io/2/reference/tools/env/virtualbuildenv.html#reference shows the argument, but not fully document it.

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!

@memsharded memsharded transferred this issue from conan-io/conan Apr 11, 2024
@memsharded memsharded added this to the 2 milestone Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants