Skip to content

Commit

Permalink
Merge pull request #4432 from jcbrill/jbrill-msvc-clsearch
Browse files Browse the repository at this point in the history
MSVC: adjust the compiler search and warning message when configuring the environment.
  • Loading branch information
bdbaddog authored Oct 29, 2023
2 parents 58eb211 + fe0165d commit b7f0744
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
18 changes: 18 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
msvs. Moving any of these tools that used relative imports to the scons site tools
folder would fail on import (i.e., the relative import paths become invalid when
moved).
- The detection of the msvc compiler executable (cl.exe) has been modified:
* The host os environment path is no longer evaluated for the existence of the
msvc compiler executable when searching the detection dictionary.
* The existence of the msvc compiler executable is checked in the detection
dictionary and the scons ENV path before the detection dictionary is merged
into the scons ENV.
* Different warnings are produced when the msvc compiler is not detected in the
detection dictionary based on whether or not an msvc compiler was detected in
the scons ENV path (i.e., a msvc compiler executable already exists in the
user's ENV path prior to detection).
* The warning message issued when a msvc compiler executable is not found in the
detection dictionary was modified by adding the word "requested":
Old warning: "Could not find MSVC compiler 'cl'."
New warning: "Could not find requested MSVC compiler 'cl'.".
* An additonal sentence is appended to the warning message issued when an msvc
compiler executable is not found in the msvc detection dictionary and is found
in the user's ENV path prior to detection:
" A 'cl' was found on the scons ENV path which may be erroneous."

From Vitaly Cheptsov:
- Fix race condition in `Mkdir` which can happen when two `SConscript`
Expand Down
6 changes: 6 additions & 0 deletions RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ CHANGED/ENHANCED EXISTING FUNCTIONALITY
batch file exists but an individual msvc toolset may not support the host/target
architecture combination. For example, when using VS2022 on arm64, the arm64 native
tools are only installed for the 14.3x toolsets.
- MSVC: When the msvc compiler executable is not found during setup of the msvc
environment, the warning message issued takes into account whether or not a
possibly erroneous compiler executable was already present in the scons environment
path. See CHANGES.txt for details.
- Extend range of recognized Java versions to 20.
- Builder calls (like Program()) now accept pathlib objects in source lists.
- The Help() function now takes an additional keyword argument keep_local:
Expand Down Expand Up @@ -102,6 +106,8 @@ FIXES
- MSVC: Erroneous construction of the installed msvc list (as described above) caused an
index error in the msvc support code. An explicit check was added to prevent indexing
into an empty list. Fixes #4312.
- MSVC: The search for the msvc compiler executable (cl.exe) no longer inspects the
OS system path in certain situations when setting up the msvc environment.
- MSCommon: Test SConfTests.py would fail when mscommon debugging was enabled via the
MSVC_MSCOMMON_DEBUG environment variable. The mscommon logging filter class registered
with the python logging module was refactored to prevent test failure.
Expand Down
24 changes: 18 additions & 6 deletions SCons/Tool/MSCommon/vc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
debug(warn_msg)
SCons.Warnings.warn(SCons.Warnings.VisualCMissingWarning, warn_msg)

def msvc_exists(env=None, version=None):
Expand Down
2 changes: 1 addition & 1 deletion test/MSVC/MSVC_USE_SETTINGS.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
""" % locals())

test.run(arguments="--warn=visual-c-missing .", status=0, stderr=None)
test.must_contain_all(test.stderr(), "Could not find MSVC compiler 'cl'")
test.must_contain_all(test.stderr(), "Could not find requested MSVC compiler 'cl'")

test.write('SConstruct', """
env = Environment(MSVC_USE_SETTINGS='dict or None')
Expand Down

0 comments on commit b7f0744

Please sign in to comment.