-
-
Notifications
You must be signed in to change notification settings - Fork 325
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
MSVC: adjust the compiler search and warning message when configuring the environment. #4432
Changes from all commits
bf5dc45
494d4d2
4a01e14
fe0165d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1515,18 +1515,30 @@ def msvc_setup_env(env): | |
SCons.Warnings.warn(SCons.Warnings.VisualCMissingWarning, warn_msg) | ||
return None | ||
|
||
found_cl_path = None | ||
found_cl_envpath = None | ||
|
||
seen_path = False | ||
for k, v in d.items(): | ||
if not seen_path and k == 'PATH': | ||
seen_path = True | ||
found_cl_path = SCons.Util.WhereIs('cl', v) | ||
found_cl_envpath = SCons.Util.WhereIs('cl', env['ENV'].get(k, [])) | ||
env.PrependENVPath(k, v, delete_existing=True) | ||
debug("env['ENV']['%s'] = %s", k, env['ENV'][k]) | ||
|
||
# final check to issue a warning if the compiler is not present | ||
if not find_program_path(env, 'cl'): | ||
debug("did not find %s", _CL_EXE_NAME) | ||
debug("cl paths: d['PATH']=%s, ENV['PATH']=%s", repr(found_cl_path), repr(found_cl_envpath)) | ||
|
||
# final check to issue a warning if the requested compiler is not present | ||
if not found_cl_path: | ||
warn_msg = "Could not find requested MSVC compiler 'cl'." | ||
if CONFIG_CACHE: | ||
propose = f"SCONS_CACHE_MSVC_CONFIG caching enabled, remove cache file {CONFIG_CACHE} if out of date." | ||
warn_msg += f" SCONS_CACHE_MSVC_CONFIG caching enabled, remove cache file {CONFIG_CACHE} if out of date." | ||
else: | ||
propose = "It may need to be installed separately with Visual Studio." | ||
warn_msg = f"Could not find MSVC compiler 'cl'. {propose}" | ||
warn_msg += " It may need to be installed separately with Visual Studio." | ||
if found_cl_envpath: | ||
warn_msg += " A 'cl' was found on the scons ENV path which may be erroneous." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the env['ENV']['PATH'] contains path to the requested and also otherwise found cl.exe, will this message get issued? If the user specifically sets all the env['ENV'][*]'s set by msvc initialization will this get issued even if that is correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No.
I'm not exactly sure what you're asking. The paths that come through this code are a request for the setup dictionary from MSVC_USE_SCRIPT (user script specification), MSVS_USE_SETTINGS (user dictionary specification), and MSVC autodetection. Bypassing detection exits before this point:
The message is invoked when a requested setup dictionary does not contain a compiler executable. The possibly erroneous fragment is indicating the there is a compiler in the user's path which may not be what was expected as the requested setup dictionary failed to include a compiler executable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. that's not clear from the CHANGES.txt (and release.txt) blurbs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MSVC_USE_SCRIPT => user-specified script (intent to get setup config from provided script output) Basically, the user requested a "valid" setup configuration. Failing to find a compiler executable in the setup dictionary indicates that the request failed. The augmented message is necessary because if/when there is a compiler executable already in the user's environment (which may or may not be the desired compiler), the build may continue and could possibly complete successfully with the "wrong" compiler. There is no guarantee that the configured system environment is the same as the requested setup environment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps the terminology is confusing: at the code level the "setup config" is a dictionary. All three methods that do not exit early return a setup configuration dictionary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So please be explicit about such in the CHANGES and RELEASE. While you may immediately know the correlation between the text and the variables above, most people won't. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The correlation between the text and the variables above did not change. With the exception of the bug fix, all that is different is that possibly another sentence is included.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Old message: New message (no cl on env path) with word New message (cl on env path) with word |
||
debug(warn_msg) | ||
SCons.Warnings.warn(SCons.Warnings.VisualCMissingWarning, warn_msg) | ||
|
||
def msvc_exists(env=None, version=None): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see code change which would have this effect in this PR?
Or is this code having this effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Searching for the compiler executable using the method
find_program_path
was removed:The
find_program_path
searches the OS path for the program when the program is not found in the scons environment which is undesirable in this case. A compiler executable path from the OS PATH should not be used in this context.This was a bug. When looking at the existing code, one would have to know what
find_program_path
is actually doing internally to realize there is a problem. Thefind_program_path
source is shown below.A similar issue arises when the detected dictionary keys are added to the env and then the environment path is searched. Was the found compiler executable in the detection dictionary, already in the user's environment, or both?
To solve these particular issues, the detection dictionary and the user's environment are both searched immediately prior to adding the detected path elements to the environment:
The code fragment Is searching the detection dictionary PATH element for a compiler executable. If no compiler executable is found in the detection dictionary this means that the user's request has failed to produce a valid compiler executable and a warning will be issued.
The code fragment is also searching the users
env['ENV']['PATH']
for a compiler executable and may append the "erroneous compiler" sentence to the end of the warning.When there is no compiler present in the requested version detection dictionary and there is a compiler already present in the user's environment, regardless of the warning issued, the build may succeed possibly using a compiler executable that is not the same version as the request.
If if still doesn't make sense, let me know, and I'll try again.
find_program_path
source:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So using env['ENV']['PATH'] to find cl is only valid if MSVC_USE_SCRIPT is set to false? Otherwise you'll get the warning?
(As a side note, the variable named "d" isn't descriptive and keeps hurting my eyes.. not for this PR, but if you could name it something which indicates it's purpose at some point my eyes would thank you! ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite.
When MSVC_USE_SCRIPT is set to false this code is not executed as there is an early exit so there is never a check for a compiler. However, a different warning is always issued. It would probably be easy enough to suppress the warning though if a compiler was found in env['ENV']['PATH'].
Early exit:
I completely agree.
That was not my doing. It has been that way since 2.0.0.final.0:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I would be happy to change the name :)