Skip to content

Commit ea5baf8

Browse files
committed
Clear VisualStudio internal cache and installed visual studios data structures when vswhere finds new msvc roots.
1 parent 981d74a commit ea5baf8

File tree

4 files changed

+68
-24
lines changed

4 files changed

+68
-24
lines changed

CHANGES.txt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,14 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
8080
of the results from all vswhere executables). There is a single invocation for
8181
each vswhere executable that processes the output for all installations. Prior
8282
implementations called the vswhere executable for each supported msvc version.
83-
- Previously, the installed vcs list was constructed once and cached at runtime. If
84-
a vswhere executable was specified via the construction variable VSWHERE and found
85-
additional msvc installations, the new installations were not reflected in the
86-
installed vcs list. During runtime, if a user-specified vswhere executable finds
87-
new msvc installations, internal runtime caches are cleared and the installed vcs
88-
list is reconstructed.
89-
83+
- Previously, the installed vcs and visual studios lists were constructed once and
84+
cached at runtime. If a vswhere executable was specified via the construction
85+
variable VSWHERE and found additional msvc installations, the new installations
86+
were not reflected in the installed vcs and visual studios lists. Now, when a
87+
user-specified vswhere executable finds new msvc installations, internal runtime
88+
caches are cleared and the installed vcs and visual studios lists are reconstructed
89+
on their next retrieval.
90+
9091
From Thaddeus Crews:
9192
- Implemented SCons.Util.sctyping as a safe means of hinting complex types. Currently
9293
only implemented for `Executor` as a proof-of-concept.
@@ -1404,7 +1405,7 @@ RELEASE 3.1.2 - Mon, 17 Dec 2019 02:06:27 +0000
14041405
in the case where a child process is spawned while a Python action has a
14051406
file open. Original author: Ryan Beasley.
14061407
- Added memoization support for calls to Environment.Value() in order to
1407-
improve performance of repeated calls.
1408+
improve performance of repeated calls.
14081409

14091410

14101411
From Jason Kenny

RELEASE.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ FIXES
7070
msiexec /i VCForPython27.msi ALLUSERS=1
7171
When installed for all users, Visual Studio 2008 (9.0) Visual C++ For Python is
7272
now correctly detected.
73-
- MSVC: The installed vcs list was constructed and cached during the initial
74-
invocation. If a vswhere executable was specified via the construction variable
75-
VSWHERE and found additional msvc installations, the new installations were not
76-
reflected in the installed vcs list. Now, when a user-specified vswhere
77-
executable finds new msvc installations, the installed vcs list is reconstructed.
73+
- MSVC: The installed vcs and visual studios lists were constructed and cached
74+
during their initial invocations. If a vswhere executable was specified via the
75+
construction variable VSWHERE and found additional msvc installations, the new
76+
installations were not reflected in the cached installed vcs and visual studios
77+
lists. Now, when a user-specified vswhere executable finds new msvc installations,
78+
the installed vcs and visual studios lists are cleared and reconstructed on their
79+
next retrieval.
7880
- On Windows platform, when collecting command output (Configure checks),
7981
make sure decoding of bytes doesn't fail.
8082
- Documentation indicated that both Pseudo() and env.Pseudo() were usable,

SCons/Tool/MSCommon/vc.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,8 @@ def msvc_find_vswhere():
10081008

10091009
class _VSWhere:
10101010

1011-
reset_funcs = []
1011+
reset_funcs_list = []
1012+
reset_funcs_seen = set()
10121013

10131014
@classmethod
10141015
def reset(cls):
@@ -1036,15 +1037,20 @@ def msvc_instances_default_order(a, b):
10361037

10371038
@classmethod
10381039
def register_reset_func(cls, func):
1039-
cls.reset_funcs.append(func)
1040+
if func and func not in cls.reset_funcs_seen:
1041+
cls.reset_funcs_seen.add(func)
1042+
cls.reset_funcs_list.append(func)
10401043

10411044
@classmethod
10421045
def call_reset_funcs(cls):
1043-
for func in cls.reset_funcs:
1046+
for func in cls.reset_funcs_list:
10441047
func()
10451048

10461049
_VSWhere.reset()
10471050

1051+
def vswhere_register_reset_func(func):
1052+
_VSWhere.register_reset_func(func)
1053+
10481054
def _filter_vswhere_paths(env):
10491055

10501056
vswhere_paths = []
@@ -1117,7 +1123,7 @@ def _vswhere_query_json_output(vswhere_exe, vswhere_args):
11171123
'vc_component_suffix',
11181124
])
11191125

1120-
def _update_vswhere_msvc_map(env):
1126+
def _vswhere_update_msvc_map(env):
11211127

11221128
vswhere_paths = _filter_vswhere_paths(env)
11231129
if not vswhere_paths:
@@ -1241,6 +1247,9 @@ def _update_vswhere_msvc_map(env):
12411247

12421248
return _VSWhere.msvc_map
12431249

1250+
def vswhere_update_msvc(env):
1251+
_vswhere_update_msvc_map(env)
1252+
12441253
_cache_pdir_vswhere_queries = {}
12451254

12461255
def _reset_pdir_vswhere_queries():
@@ -1267,7 +1276,7 @@ def find_vc_pdir_vswhere(msvc_version, env=None):
12671276
"""
12681277
global _cache_pdir_vswhere_queries
12691278

1270-
msvc_map = _update_vswhere_msvc_map(env)
1279+
msvc_map = _vswhere_update_msvc_map(env)
12711280
if not msvc_map:
12721281
return None
12731282

@@ -1751,9 +1760,9 @@ def _check_files_exist_in_vc_dir(env, vc_dir, msvc_version) -> bool:
17511760
def get_installed_vcs(env=None):
17521761
global __INSTALLED_VCS_RUN
17531762

1754-
# the installed vcs cache is cleared
1755-
# if new vc roots are discovered
1756-
_update_vswhere_msvc_map(env)
1763+
debug('')
1764+
# the installed vcs cache is cleared if new vc roots are discovered
1765+
_vswhere_update_msvc_map(env)
17571766

17581767
if __INSTALLED_VCS_RUN is not None:
17591768
return __INSTALLED_VCS_RUN

SCons/Tool/MSCommon/vs.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import os
2929

3030
import SCons.Errors
31-
import SCons.Tool.MSCommon.vc
3231
import SCons.Util
3332

3433
from .common import (
@@ -40,6 +39,14 @@
4039
read_reg,
4140
)
4241

42+
from .vc import (
43+
find_vc_pdir,
44+
get_msvc_version_numeric,
45+
reset_installed_vcs,
46+
vswhere_register_reset_func,
47+
vswhere_update_msvc,
48+
)
49+
4350

4451
class VisualStudio:
4552
"""
@@ -48,6 +55,7 @@ class VisualStudio:
4855
"""
4956
def __init__(self, version, **kw) -> None:
5057
self.version = version
58+
self.vernum = float(get_msvc_version_numeric(version))
5159
kw['vc_version'] = kw.get('vc_version', version)
5260
kw['sdk_version'] = kw.get('sdk_version', version)
5361
self.__dict__.update(kw)
@@ -66,7 +74,7 @@ def find_batch_file(self):
6674
return batch_file
6775

6876
def find_vs_dir_by_vc(self, env):
69-
dir = SCons.Tool.MSCommon.vc.find_vc_pdir(self.vc_version, env)
77+
dir = find_vc_pdir(self.vc_version, env)
7078
if not dir:
7179
debug('no installed VC %s', self.vc_version)
7280
return None
@@ -411,8 +419,12 @@ def reset(self) -> None:
411419
),
412420
]
413421

422+
SupportedVSWhereList = []
414423
SupportedVSMap = {}
415424
for vs in SupportedVSList:
425+
if vs.vernum >= 14.1:
426+
# VS2017 and later detected via vswhere.exe
427+
SupportedVSWhereList.append(vs)
416428
SupportedVSMap[vs.version] = vs
417429

418430

@@ -428,6 +440,12 @@ def reset(self) -> None:
428440
def get_installed_visual_studios(env=None):
429441
global InstalledVSList
430442
global InstalledVSMap
443+
debug('')
444+
# Calling vswhere_update_msvc may cause installed caches to be cleared.
445+
# The installed vcs and visual studios are cleared when new vc roots
446+
# are discovered which causes the InstalledVSList and InstalledVSMap
447+
# variables to be set to None.
448+
vswhere_update_msvc(env)
431449
if InstalledVSList is None:
432450
InstalledVSList = []
433451
InstalledVSMap = {}
@@ -442,14 +460,28 @@ def get_installed_visual_studios(env=None):
442460
def reset_installed_visual_studios() -> None:
443461
global InstalledVSList
444462
global InstalledVSMap
463+
debug('')
445464
InstalledVSList = None
446465
InstalledVSMap = None
447466
for vs in SupportedVSList:
448467
vs.reset()
449468

450469
# Need to clear installed VC's as well as they are used in finding
451470
# installed VS's
452-
SCons.Tool.MSCommon.vc.reset_installed_vcs()
471+
reset_installed_vcs()
472+
473+
def _reset_installed_vswhere_visual_studios():
474+
# vswhere found new roots: reset VS2017 and later
475+
global InstalledVSList
476+
global InstalledVSMap
477+
debug('')
478+
InstalledVSList = None
479+
InstalledVSMap = None
480+
for vs in SupportedVSWhereList:
481+
vs.reset()
482+
483+
# register vswhere callback function
484+
vswhere_register_reset_func(_reset_installed_vswhere_visual_studios)
453485

454486

455487
# We may be asked to update multiple construction environments with

0 commit comments

Comments
 (0)