[bug] 'ConanException: Cannot wrap command with different envs' when trying to generate .sh on Windows
Describe the bug
Environnement details:
- Windows
- Running conan 2.22 in Git bash
Description:
We are using bash scripts in our CI/CD pipelines for both Linux and Windows platforms. We have use cases where we have a CMake-based project, containing a conan file. The workflow is equivalent to:
conan install --build=missing .
source <build_dir>/generators/conanbuild.sh
export CMAKE_TOOLCHAIN_FILE=<build_dir>/generators/conan_toolchain.cmake
cmake -S . -B <build_dir>
Using Git bash on Windows, we need a conanbuild.sh to setup the build environment. The only way we've found to do so is to define these configs:
tools.microsoft.bash:active=True
tools.microsoft.bash:subsystem=msys2
However, doing this the conan install command fails when there are missing packages to build:
zlib/1.3.1: ERROR:
Package '8b7e35f91e516e42ed736c6dd52a9263da3a5dad' build failed
zlib/1.3.1: WARN: Build folder C:\Users\user\dev\git\conan-home-test\p\b\zlib4f790c2b0cdb6\b\build\Debug
ERROR: zlib/1.3.1: Error in build() method, line 81
cmake.configure()
ConanException: Cannot wrap command with different envs,['C:\\Users\\user\\dev\\git\\conan-home-test\\p\\b\\zlib4f790c2b0cdb6\\b\\build\\Debug\\generators\\conanbuild.bat'] - ['C:\\Users\\user\\dev\\git\\conan-home-test\\p\\b\\zlib4f790c2b0cdb6\\b\\build\\Debug\\generators\\conanbuild.sh']
As I understand, Conan doesn't like the fact that both .bat and .sh are generated.
How to reproduce it
conanfile.txt
[tool_requires]
cmake/3.31.8
[requires]
zlib/1.3.1
[generators]
CMakeDeps
CMakeToolchain
VirtualBuildEnv
[layout]
cmake_layout
shell:
conan install -c tools.microsoft.bash:active=True -c tools.microsoft.bash:subsystem=msys2 --build=zlib* .
Hi @phamelin
Thanks for the report.
Note there are different challenges when using git-bash as the terminal to run Conan.
For example there is https://github.com/conan-io/conan/issues/16963, when it makes very hard to build ffmpeg, because git-bash Python subprocess forward the PKG_CONFIG_PATH variable with paths with backslash that break it:
$ echo $PKG_CONFIG_PATH
/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig
$ python
Python 3.12.9 (main, Feb 13 2025, 09:16:40) [GCC 14.2.0 64 bit (AMD64)] on win32
>>> import subprocess
>>> subprocess.run("echo %PKG_CONFIG_PATH%", check=True, shell=True)
C:\ws\msys64\mingw64\lib\pkgconfig;C:\ws\msys64\mingw64\share\pkgconfig
Another issue is that using the default MSVC compilers in Windows in some build systems (autotools, etc) or with some generators (like using Ninja generator instead of Visual Studio generators) require activation of the vcvars.bat to activate the MSVC environment with paths to compiler, include dirs, etc. And that becomes a challenge in the git-bash.
In any case, I am trying to reproduce, with your above command, but what I see is:
/c/Users/memsharded/conanws/.envs/conan2_312/Scripts/conan.exe install -c tools.microsoft.bash:active=True -c tools.microsoft.bash:subsystem=msys2 --build=zlib* . -vv
======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=194
os=Windows
[conf]
tools.microsoft.bash:active=True
tools.microsoft.bash:subsystem=msys2
Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=194
os=Windows
[conf]
...
zlib/1.3.1: Generating aggregated env files
zlib/1.3.1: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh']
zlib/1.3.1: Calling build()
zlib/1.3.1: Apply patch (conan): separate static/shared builds, disable debug suffix
zlib/1.3.1: Running CMake.configure()
zlib/1.3.1: RUN: cmake -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE="generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="C:/Users/memsharded/.conan2/p/b/zlibc3a1c0f7e9ca3/p" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" "C:/Users/memsharded/.conan2/p/b/zlibc3a1c0f7e9ca3/b/src"
zlib/1.3.1: Full command: . "C:\Users\memsharded\.conan2\p\b\zlibc3a1c0f7e9ca3\b\build\generators\conanbuild.sh" && cmake -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE="generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="C:/Users/memsharded/.conan2/p/b/zlibc3a1c0f7e9ca3/p" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" "C:/Users/memsharded/.conan2/p/b/zlibc3a1c0f7e9ca3/b/src"
'.' is not recognized as an internal or external command,
operable program or batch file.
I see an error, probably because some shell discrepancies or support. But I don't see generation of .bat files, only .sh files.
Maybe you have a dirty folder that contains .bat files from other executions?
Can you please provide more complete logs of the failing conan install command?
Hi @memsharded,
Indeed, I was probably having a dirty folder. With a clean setup, I am having the same issue as you with conan 2.22.2:
$ conan install -c tools.microsoft.bash:active=True -c tools.microsoft.bash:subsystem=msys2 --build=zlib* -vv .
======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=194
os=Windows
[conf]
tools.microsoft.bash:active=True
tools.microsoft.bash:subsystem=msys2
Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=194
os=Windows
======== Computing dependency graph ========
Graph root
conanfile.txt: C:\LOCAL\TEMP\conan-sh\test-project\conanfile.txt
Requirements
zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76 - Cache
Build requirements
cmake/3.31.8#dde3bde00bb843687e55aea5afa0e220 - Cache
======== Computing necessary packages ========
zlib/1.3.1: Forced build from source
Requirements
zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76:0d6dd492a7d31822b2f2686ec67bbaef586416a3 - Build
settings: os=Windows arch=x86_64 compiler=msvc compiler.runtime=dynamic compiler.runtime_type=Release compiler.version=194 build_type=Release
options: shared=False
Build requirements
cmake/3.31.8#dde3bde00bb843687e55aea5afa0e220:522dcea5982a3f8a5b624c16477e47195da2f84f#831d92567c6c9b20f23164cfc5512d12 - Cache
settings: os=Windows arch=x86_64
======== Installing packages ========
cmake/3.31.8: Already installed! (1 of 2)
-------- Installing package zlib/1.3.1 (2 of 2) --------
zlib/1.3.1: Building from source
zlib/1.3.1: Package zlib/1.3.1:0d6dd492a7d31822b2f2686ec67bbaef586416a3
zlib/1.3.1: settings: os=Windows arch=x86_64 compiler=msvc compiler.runtime=dynamic compiler.runtime_type=Release compiler.version=194 build_type=Release
zlib/1.3.1: options: shared=False
zlib/1.3.1: Copying sources to build folder
zlib/1.3.1: Building your package in C:\LOCAL\TEMP\conan-sh\conan-home\p\b\zlib3ae5a9b0f6e46\b
zlib/1.3.1: Calling generate()
zlib/1.3.1: Generators folder: C:\LOCAL\TEMP\conan-sh\conan-home\p\b\zlib3ae5a9b0f6e46\b\build\generators
zlib/1.3.1: CMakeToolchain generated: conan_toolchain.cmake
zlib/1.3.1: CMakeToolchain generated: C:\LOCAL\TEMP\conan-sh\conan-home\p\b\zlib3ae5a9b0f6e46\b\build\generators\CMakePresets.json
zlib/1.3.1: CMakeToolchain generated: C:\LOCAL\TEMP\conan-sh\conan-home\p\b\zlib3ae5a9b0f6e46\b\src\CMakeUserPresets.json
zlib/1.3.1: Generating aggregated env files
zlib/1.3.1: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh']
zlib/1.3.1: Calling build()
zlib/1.3.1: Apply patch (conan): separate static/shared builds, disable debug suffix
zlib/1.3.1: Running CMake.configure()
zlib/1.3.1: RUN: cmake -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE="generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="C:/LOCAL/TEMP/conan-sh/conan-home/p/b/zlib3ae5a9b0f6e46/p" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" "C:/LOCAL/TEMP/conan-sh/conan-home/p/b/zlib3ae5a9b0f6e46/b/src"
zlib/1.3.1: Full command: . "C:\LOCAL\TEMP\conan-sh\conan-home\p\b\zlib3ae5a9b0f6e46\b\build\generators\conanbuild.sh" && cmake -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE="generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="C:/LOCAL/TEMP/conan-sh/conan-home/p/b/zlib3ae5a9b0f6e46/p" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" "C:/LOCAL/TEMP/conan-sh/conan-home/p/b/zlib3ae5a9b0f6e46/b/src"
'.' n’est pas reconnu en tant que commande interne
ou externe, un programme exécutable ou un fichier de commandes.
zlib/1.3.1: ERROR:
Package '0d6dd492a7d31822b2f2686ec67bbaef586416a3' build failed
zlib/1.3.1: WARN: Build folder C:\LOCAL\TEMP\conan-sh\conan-home\p\b\zlib3ae5a9b0f6e46\b\build
ERROR: Traceback (most recent call last):
File "C:\LOCAL\TEMP\conan-sh\.venv\Lib\site-packages\conan\internal\errors.py", line 35, in conanfile_exception_formatter
yield
File "C:\LOCAL\TEMP\conan-sh\.venv\Lib\site-packages\conan\internal\methods.py", line 38, in run_build_method
conanfile.build()
File "C:\LOCAL\TEMP\conan-sh\conan-home\p\zlib204752602052d\e\conanfile.py", line 81, in build
cmake.configure()
File "C:\LOCAL\TEMP\conan-sh\.venv\Lib\site-packages\conan\tools\cmake\cmake.py", line 132, in configure
self._conanfile.run(command, stdout=stdout, stderr=stderr)
File "C:\LOCAL\TEMP\conan-sh\.venv\Lib\site-packages\conan\internal\model\conan_file.py", line 396, in run
raise ConanException("Error %d while executing" % retcode)
conan.errors.ConanException: Error 1 while executing
zlib/1.3.1: Error in build() method, line 81
cmake.configure()
ConanException: Error 1 while executing
Thanks for the report. As a workaround, it seems that opening a cmd shell when in git-bash works:
cmd
conan install --build=missing . # Without the confs for the subsystem
We have been trying to workaround or provide better solutions for this git-bash terminal for a long time, but still didn't manage to find something robust, because often things are out of our control, like the reported issues above around PKG_CONFIG_PATH or the activation of MSVC vcvars.bat. We will keep trying, but seems quite challenging.
I'll have a look to this .=source issue.