conan-io / conan

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

[feature] Have a way to generate both conanbuild.bat and conanbuild.ps1 files. #11353

Open datalogics-kam opened 2 years ago

datalogics-kam commented 2 years ago

It would be handy to have a way tools.env.virtualenv:powershell to create both .ps1 and .bat files.

This came out of using conan.tools to make a Conan 2.0-ish workflow while using Conan 1.

memsharded commented 2 years ago

Hi @datalogics-kam

But for user side, you can easily have the one that you want, because you can do:

$ conan install ....
$ conan install ... -c tools.env.virtualenv:powershell=True  # or False, depending on your default

That is, the CLI always has priority, and can override. conan install will be fast once things are installed.

We are trying to avoid the definition of multiple files by Conan, because the automatic activation of those files is based on the files existence itself. So generating both .bat and .ps1 will result in an error by any Conan method that tries to apply the environment. Does this make sense?

datalogics-kam commented 2 years ago

I see...I installed our project that uses conan.tools with -c tools.env.virtualenv:powershell=True, on Conan 1.49.

A few things happened:

  1. It built the .bat files anyway. I didn't expect that.
  2. conan build failed, and I see the warning about wrapping the command with different envs.
  3. I noticed that the Powershell scripts don't support conan.tools.microsoft.VCVars. That would be nice.

I'm curious...doesn't Conan know what shell it's going to use to run a command? On Windows, isn't it CMD, unless something specified win_bash?

A potential situation for us is that the user is using PowerShell for manual building, but Conan is using CMD to run the commands. Unless there's something to make Conan use PowerShell, that I missed.

(I removed things that reveal what product I'm working on)

> conan build . -if .\build\x64\Debug\
Using lockfile: 'C:\Users\kam\src\...\x64\Debug/conan.lock'
Using cached profile from lockfile
conanfile.py (DevTests/1.0.0): Calling build()
conanfile.py (DevTests/1.0.0): CMake command: cmake -G "Ninja" -DCMAKE_TOOLCHAIN_FILE="C:/Users/kam/src/.../build/x64/Debug/conan/conan_toolchain.cmake" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Debug" "C:\Users\kam\src\..."
ERROR: conanfile.py (product/1.0.0): Error in build() method, line 273
        cmake.configure()
        ConanException: Cannot wrap command with different envs, ['C:\\Users\\kam\\src\\pdfl18_all\\.../x64/Debug\\conan\\conanbuild.bat'] - [] - ['C:\\Users\\kam\\src\\...\\build/x64/Debug\\conan\\conanbuild.ps1']