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

[bug] ensure that the msys2 bin folder is added to PATH before calling bash.exe #11986

Closed
jellespijker opened this issue Aug 30, 2022 · 5 comments

Comments

@jellespijker
Copy link
Contributor

jellespijker commented Aug 30, 2022

Came across this while trying to modernize the msys2 recipe See reproduction steps)

When using the buildenv_info instead of env_info Setting the toolchains shell scripts in the bash resulted in errors that printenv couldn't be found. This is because the PATH variable doesn't contain the PATH to the msys2 ......../bin/msys2/usr/bin yet.

I think the PATH containing the msys2 bins should be added to the environment as soon as possible in this chain. I think a possible solution is to prepend the directory of the shell_path, since the MSYS2_PATH_TYPE is set to inherit the bash.exe will be aware of all the other programs.

msys2_mode_env.define("MSYS2_PATH_TYPE", "inherit")

msys2_mode_env.prepend_path("PATH", os.path.dirname(shell_path))

Downside of this is that the shell script which will be activated in the bash environment will also restore that path if the deactivation script is called. But I think that won't be a huge issue, because (as far as I'm aware) all the bash commands are called as single shot commands.

I don't know exactly how this will affect setups which use their own msys2 environment and don't specify the full path for the tools.microsoft.bash:path configuration

Environment Details (include every applicable attribute)

  • Operating System+version: Windows 11
  • Compiler+version: MSVC
  • Conan version: 1.50.2 (and dev)
  • Python version: 3.10.4

Steps to reproduce (Include if Applicable)

Logs (Executed commands with output) (Include/Attach if Applicable)

----Running------
> "C:\.conan\376fd79\1\build-release\conan\conanbuild.bat" && "C:\.conan\376fd79\1\build-release\conan\msys2_mode.bat" && C:\.conan\7c3916\1\bin\msys64\usr\bin\bash.exe -c ^". \^"C:\.conan\376fd79\1\build-release\conan\conanbuild.sh\^" ^&^& make install DESTDIR=/c/.conan/f8e0e8f/1 -j12^"      
-----------------
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.1.6
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
Capturing current environment in C:\.conan\376fd79\1\build-release\conan\deactivate_msys2_mode.bat
Configuring environment variables
Capturing current environment in C:\.conan\376fd79\1\build-release\conan\deactivate_conanautotoolstoolchain.sh
/c/.conan/376fd79/1/build-release/conan/conanautotoolstoolchain.sh: line 6: printenv: command not found
/c/.conan/376fd79/1/build-release/conan/conanautotoolstoolchain.sh: line 6: printenv: command not found
/c/.conan/376fd79/1/build-release/conan/conanautotoolstoolchain.sh: line 6: printenv: command not found
/c/.conan/376fd79/1/build-release/conan/conanautotoolstoolchain.sh: line 6: printenv: command not found
/c/.conan/376fd79/1/build-release/conan/conanautotoolstoolchain.sh: line 6: printenv: command not found
/c/.conan/376fd79/1/build-release/conan/conanautotoolstoolchain.sh: line 6: printenv: command not found
/c/.conan/376fd79/1/build-release/conan/conanautotoolstoolchain.sh: line 6: printenv: command not found
Configuring environment variables
Capturing current environment in C:\.conan\376fd79\1\build-release\conan\deactivate_conanautotoolsdeps.sh
/c/.conan/376fd79/1/build-release/conan/conanautotoolsdeps.sh: line 6: printenv: command not found
/c/.conan/376fd79/1/build-release/conan/conanautotoolsdeps.sh: line 6: printenv: command not found
/c/.conan/376fd79/1/build-release/conan/conanautotoolsdeps.sh: line 6: printenv: command not found
/c/.conan/376fd79/1/build-release/conan/conanautotoolsdeps.sh: line 6: printenv: command not found
/c/.conan/376fd79/1/build-release/conan/conanautotoolsdeps.sh: line 6: printenv: command not found
Configuring environment variables
Capturing current environment in C:\.conan\376fd79\1\build-release\conan\deactivate_conanbuildenv-release-x86_64.sh
/c/.conan/376fd79/1/build-release/conan/conanbuildenv-release-x86_64.sh: line 6: printenv: command not found
/c/.conan/376fd79/1/build-release/conan/conanbuildenv-release-x86_64.sh: line 6: printenv: command not found
/c/.conan/376fd79/1/build-release/conan/conanbuildenv-release-x86_64.sh: line 6: printenv: command not found
Configuring environment variables

Closely relates to #11980

@jellespijker
Copy link
Contributor Author

Will open up a PR for the proposed fix.

jellespijker pushed a commit to Ultimaker/conan that referenced this issue Aug 30, 2022
This should prepend the root directory of msys bin dir, on which the bash.exe
is located, as well as tools such as `printenv`.

Fixes conan-io#11986
@SpaceIm
Copy link
Contributor

SpaceIm commented Aug 31, 2022

Not sure it's a conan issue, it's a an issue in msys2 recipe in conan-center, you have forgotten to add this folder to cpp_info.bindirs in your fork. AFAIK, in conan v2 bindirs of tool_requires are automatically added to PATH in build scope.

see conan-io/conan-center-index#12715

@jellespijker
Copy link
Contributor Author

jellespijker commented Aug 31, 2022

Thank you, will cont. working from your new msys2 recipe, to check if this is still an issue then. If not, then I will close the issue and PR

@jellespijker
Copy link
Contributor Author

@SpaceIm you're correct. Using your new msys2 conan recipe for msys2 fixed this issue. I will close this issue and the PR

@hassec
Copy link

hassec commented Nov 20, 2022

Mhh, but what if someone is using their own msys2 installation?

E.g. the profile I'm currently using while trying to get a build working on msys is:

[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=12
os=Windows
os_build=Windows
[options]
[build_requires]
[env]
CONAN_BASH_PATH=C:/Users/IEUser/scoop/apps/msys2/2022-09-04/usr/bin/bash.exe
[conf]
tools.microsoft.bash:path=C:/Users/IEUser/scoop/apps/msys2/2022-09-04/usr/bin/bash.exe
tools.microsoft.bash:subsystem=msys2
tools.env.virtualenv:auto_use=True

And if I start the conan command from PowerShell, I run into the above problem as described by @jellespijker.
And with #11987 I don't get those printenv warnings 👍

So should that PR or a different solution maybe be reconsidered?

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

Successfully merging a pull request may close this issue.

3 participants