Skip to content

Commit 8abc02f

Browse files
committed
Fix msvc_query_version_toolset function test in vcTests.py
Changes: * Add function to return msvc version and toolset version pairs for all installed vcs. * Construct set of installed toolset vcs for determining if msvc_query_version_toolset should raise an exception.
1 parent 4a2f1dc commit 8abc02f

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

SCons/Tool/MSCommon/vc.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,6 +2570,34 @@ def msvc_toolset_versions_spectre(msvc_version=None, vswhere_exe=None):
25702570
rval = MSVC.ScriptArguments._msvc_toolset_versions_spectre_internal(msvc_version, vc_dir)
25712571
return rval
25722572

2573+
def get_installed_vcs_toolsets_components(env=None):
2574+
2575+
vcs = get_installed_vcs(env)
2576+
2577+
msvc_toolset_component_defs = []
2578+
2579+
for msvc_version in vcs:
2580+
msvc_version_def = MSVC.Util.msvc_version_components(msvc_version)
2581+
if msvc_version_def.msvc_vernum > 14.0:
2582+
# VS2017 and later
2583+
toolset_all_list = msvc_toolset_versions(msvc_version=msvc_version, full=True, sxs=True)
2584+
for toolset_version in toolset_all_list:
2585+
debug('msvc_version=%s, toolset_version=%s', repr(msvc_version), repr(toolset_version))
2586+
toolset_version_def = MSVC.Util.msvc_extended_version_components(toolset_version)
2587+
if not toolset_version_def:
2588+
continue
2589+
rval = (msvc_version_def, toolset_version_def)
2590+
msvc_toolset_component_defs.append(rval)
2591+
else:
2592+
# VS2015 and earlier
2593+
toolset_version = msvc_version_def.msvc_verstr
2594+
debug('msvc_version=%s, toolset_version=%s', repr(msvc_version), repr(toolset_version))
2595+
toolset_version_def = MSVC.Util.msvc_extended_version_components(toolset_version)
2596+
rval = (msvc_version_def, toolset_version_def)
2597+
msvc_toolset_component_defs.append(rval)
2598+
2599+
return msvc_toolset_component_defs
2600+
25732601
def msvc_query_version_toolset(version=None, prefer_newest: bool=True, vswhere_exe=None):
25742602
"""
25752603
Return an msvc version and a toolset version given a version
@@ -2616,13 +2644,13 @@ def msvc_query_version_toolset(version=None, prefer_newest: bool=True, vswhere_e
26162644
"""
26172645
debug('version=%s, prefer_newest=%s', repr(version), repr(prefer_newest))
26182646

2647+
_VSWhereExecutable.vswhere_freeze_executable(vswhere_exe)
2648+
26192649
msvc_version = None
26202650
msvc_toolset_version = None
26212651

26222652
with MSVC.Policy.msvc_notfound_policy_contextmanager('suppress'):
26232653

2624-
_VSWhereExecutable.vswhere_freeze_executable(vswhere_exe)
2625-
26262654
vcs = get_installed_vcs()
26272655

26282656
if not version:

SCons/Tool/MSCommon/vcTests.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ class Data:
237237
INSTALLED_VCS = MSCommon.vc.get_installed_vcs()
238238
INSTALLED_VCS_COMPONENTS = MSCommon.vc.get_installed_vcs_components()
239239

240+
INSTALLED_VCS_TOOLSETS_COMPONENTS = MSCommon.vc.get_installed_vcs_toolsets_components()
241+
INSTALLED_VCS_TOOLSETS = set()
242+
for msvc_version_def, toolset_version_def in INSTALLED_VCS_TOOLSETS_COMPONENTS:
243+
INSTALLED_VCS_TOOLSETS.add(msvc_version_def.msvc_version)
244+
INSTALLED_VCS_TOOLSETS.add(toolset_version_def.msvc_version)
245+
240246
@classmethod
241247
def query_version_list(cls, vcver):
242248
# VS 2022 (14.3) can have either/both toolset versions 14.3X and 14.4X
@@ -498,7 +504,7 @@ def test_valid_default_msvc(self) -> None:
498504

499505
def test_valid_vcver(self) -> None:
500506
for symbol in MSCommon.vc._VCVER:
501-
have_msvc = bool(symbol in Data.INSTALLED_VCS)
507+
have_msvc = bool(symbol in Data.INSTALLED_VCS_TOOLSETS)
502508
version_def = MSCommon.msvc_version_components(symbol)
503509
for prefer_newest in (True, False):
504510
if not have_msvc:

0 commit comments

Comments
 (0)