conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
7.95k stars 951 forks source link

[question] What is the replacement for the `run()`'s `run_environment` parameter in Conan 2? #16528

Closed PauloCarvalhoRJ closed 1 week ago

PauloCarvalhoRJ commented 1 week ago

Hello,

So, I have this call that used to work in Conan 1 to run a test package executable:

self.run(os.path.join("bin", "test"), run_environment=True)

The purpose of that run_environment=True is to setup the environment variables so the executable runs without runtime errors such as libraries not found. In Conan 2, that parameter no longer exists. The question is: how do I achieve the same effect in Conan 2 in order to run the test executabes without env issues?

best,

PC

Have you read the CONTRIBUTING guide?

RubenRBS commented 1 week ago

Hi @PauloCarvalhoRJ thanks for your question.

The think you're most likely looking for is the env argument to the self.run method. After looking into the docs, an example usage can be found here, but we need to have a more direct reference for the argument (As the run documentation is lacking info on this argument). I'll move this ticket to the docs repo after talking with the team :)

In Conan Center Index you can find examples of runs running witht he run environment if you look for the "conanrun" string, I hope this helps a bit for now!

PauloCarvalhoRJ commented 1 week ago

Hi, @RubenRBS ,

Thank you for your reply. So, running a test has turned much more verbose in terms of code (and, hence, more error-prone) in Conan 2? If I understood it right, I have to explicitly set env vars like PATH and LD_LIBRARY_PATH with the dynamic library locations of the package under test. Right? In Conan 1 we had that handy flag and the framework took care of the rest.

regards,

PC

RubenRBS commented 1 week ago

Not at all. By instantiating the VirtualRunEnv/VirtualBuildEnv generators as needed, that information is already propagated to your scripts, no need to do it manually for most cases :)

PauloCarvalhoRJ commented 1 week ago

Very interesting. Thank you for sharing that.