-
Notifications
You must be signed in to change notification settings - Fork 947
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] msys2 subsystem should always unset ORIGINAL_PATH first #16268
Comments
Hi @paulharris Thanks for your report. I am trying to wrap my head around this issue. It would be fantastic to have some links to any msys2 docs about the Many thanks for the PR in #16269, it would also be much better to have a failing test that would evidence better the need for this change. You can grep |
I found this link that talks a little about ORIGINAL_PATH: I wasn't able to find any other documentation on ORIGINAL_PATH.
That way, The /etc/profile in question is here:
I'm not sure how to write a test for this,
I modified the conan-cache's copy of /etc/profile to print out the PATH values to confirm. The Conan is assuming that the internal msys env it uses for autotools will inherit the PATH that conan configures. When ORIGINAL_PATH is set, the paths inherited are not the conan paths, but the paths BEFORE conan was called. This will be another one of those situations where you explain that it is up to the conan user to ensure the environment is clean and ready for build, but this is something that the typical user hasn't introduced, and won't realise it is poisoning their builds. Conan2 works well running from within an msys shell, there are just a couple of things to improve and then we are all the way there. If we can't clear the env variable as I suggest, could we instead check if the env variable is set and show a warning. Is there a way in the profile to UNSET an environment variable? Perhaps this is something I (and other people) can add to their profile. |
Thanks for the feedback This looks like a patch/change in
Not really, I think I start to understand this better, and I understand how this can be more obscure, and it would be nice if this could be managed by Conan. Just to clarify, if I understood correctly, this doesn't happen when you are in
yes, profiles can do |
Well that patch was applied to msys2, I only linked it because it was the only thing I could find that even mentioned ORIGINAL_PATH at all.
Yes, you understand correctly. You can see the behaviour in msys terminals.
Now PATH doesn't contain the windows env PATH entries, but instead contains blahblah. conan is spinning up a cmd, setting the PATH and then running bash --login. If conan wants to set PATH and make msys inherit from that PATH, it needs to unset ORIGINAL_PATH.
I can't imagine anyone would want the current behaviour. |
Note that I didn't investigate further, I suspect it is related to when the environment things are applied - I assume |
I have been checking this a bit more. diff --git a/conans/client/subsystems.py b/conans/client/subsystems.py
index daba56c06..ac7ca25c7 100644
--- a/conans/client/subsystems.py
+++ b/conans/client/subsystems.py
@@ -82,6 +82,7 @@ def _windows_bash_wrapper(conanfile, command, env, envfiles_folder):
# - CHERE_INVOKING is necessary to keep the CWD and not change automatically to the user home
msys2_mode_env.define("MSYSTEM", _msystem)
msys2_mode_env.define("MSYS2_PATH_TYPE", "inherit")
+ msys2_mode_env.unset("ORIGINAL_PATH")
# So --login do not change automatically to the user home
msys2_mode_env.define("CHERE_INVOKING", "1")
path = os.path.join(conanfile.generators_folder, "msys2_mode.bat") Can you please try to use this patch instead of yours and test it in your setup? |
I can confirm that your patch works for me! |
Describe the bug
In short:
The result is builds either work because the ORIGINAL_PATH already had the correct compiler paths (ie user was running conan from within an MSVC Developer CMD),
or
builds don't work because the compiler could not be found.
I previously did not understand this, and I "solved it" by hand-picking the environment vars that were kept (which did not include ORIGINAL_PATH).
#16118 and #16119
This couldn't be merged.
#12760
This describes the exact problem and correctly identifies that ORIGINAL_PATH is the culprit, but does not dive into exactly why it is a problem.
#16122
This is a merged PR that fixes problems when HOME and USERPROFILE both exist in the environment.
I suggest that we add code to the same place as #16122 to always remove ORIGINAL_PATH.
There is no need for this variable to be set for conan's purposes, and it disrupts the intended behaviour of inheriting the PATH from the environment that conan was executed within.
The code from /etc/profile, but only the PATH related bits
The key part is:
ORIGINAL_PATH="${ORIGINAL_PATH:-${PATH}}"
which will set ORIGINAL_PATH to PATH but only if ORIGINAL_PATH was originally unset.
So the environment's PATH is backed up into ORIGINAL_PATH, and then added into the final PATH.
I propose we add to
conans/utils/windows.py
def conan_expand_user(path):
the code:I believe it will make conan behave the way we would expect.
How to reproduce it
No response
The text was updated successfully, but these errors were encountered: