Skip to content

Commit 1dacd31

Browse files
committed
Rework vswhere executable filter/seen handling.
1 parent 9714abc commit 1dacd31

File tree

3 files changed

+69
-86
lines changed

3 files changed

+69
-86
lines changed

SCons/Tool/MSCommon/MSVC/Kind.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ def msvc_version_register_kind(msvc_version, kind_t) -> None:
177177
global _cache_vcver_kind_map
178178
if kind_t is None:
179179
kind_t = _VCVER_DETECT_KIND_UNKNOWN
180-
# print('register_kind: msvc_version=%s, kind=%s' % (repr(msvc_version), repr(VCVER_KIND_STR[kind_t.kind])))
181180
debug('msvc_version=%s, kind=%s', repr(msvc_version), repr(VCVER_KIND_STR[kind_t.kind]))
182181
_cache_vcver_kind_map[msvc_version] = kind_t
183182

SCons/Tool/MSCommon/vc.py

Lines changed: 69 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,8 +1272,6 @@ def reset(cls):
12721272
cls.seen_vswhere = set()
12731273
cls.seen_root = set()
12741274

1275-
cls.vswhere_executables = []
1276-
12771275
cls.msvc_instances = []
12781276
cls.msvc_map = {}
12791277

@@ -1283,20 +1281,20 @@ def _initialize(cls):
12831281
cls.reset()
12841282

12851283
@classmethod
1286-
def _new_roots_discovered(cls):
1287-
# TODO(JCB) should not happen due to freezing vswhere.exe
1288-
# need sanity check?
1289-
pass
1284+
def _filter_vswhere_binary(cls, vswhere_binary):
12901285

1291-
@classmethod
1292-
def _filter_vswhere_paths(cls, vswhere_exe):
1286+
vswhere_norm = None
12931287

1294-
vswhere_paths = []
1288+
if vswhere_binary.vswhere_norm not in cls.seen_vswhere:
1289+
cls.seen_vswhere.add(vswhere_binary.vswhere_norm)
1290+
vswhere_norm = vswhere_binary.vswhere_norm
12951291

1296-
if vswhere_exe and vswhere_exe not in cls.seen_vswhere:
1297-
vswhere_paths.append(vswhere_exe)
1292+
return vswhere_norm
12981293

1299-
return vswhere_paths
1294+
@classmethod
1295+
def _new_roots_discovered(cls):
1296+
if len(cls.seen_vswhere) > 1:
1297+
raise MSVCInternalError(f'vswhere discovered new msvc installations after initial detection')
13001298

13011299
@classmethod
13021300
def _vswhere_query_json_output(cls, vswhere_exe, vswhere_args):
@@ -1352,95 +1350,85 @@ def vswhere_update_msvc_map(cls, vswhere_exe):
13521350

13531351
frozen_binary, vswhere_binary = _VSWhereExecutable.vswhere_freeze_executable(vswhere_exe)
13541352

1355-
vswhere_exe = frozen_binary.vswhere_exe
1356-
1357-
vswhere_paths = cls._filter_vswhere_paths(vswhere_exe)
1358-
if not vswhere_paths:
1353+
vswhere_norm = cls._filter_vswhere_binary(frozen_binary)
1354+
if not vswhere_norm:
13591355
return cls.msvc_map
13601356

1361-
n_instances = len(cls.msvc_instances)
1357+
debug('vswhere_norm=%s', repr(vswhere_norm), extra=cls.debug_extra)
13621358

1363-
for vswhere_exe in vswhere_paths:
1359+
vswhere_json = cls._vswhere_query_json_output(
1360+
vswhere_norm,
1361+
['-all', '-products', '*']
1362+
)
13641363

1365-
if vswhere_exe in cls.seen_vswhere:
1366-
continue
1364+
if not vswhere_json:
1365+
return cls.msvc_map
13671366

1368-
cls.seen_vswhere.add(vswhere_exe)
1369-
cls.vswhere_executables.append(vswhere_exe)
1367+
n_instances = len(cls.msvc_instances)
13701368

1371-
debug('vswhere_exe=%s', repr(vswhere_exe), extra=cls.debug_extra)
1369+
for instance in vswhere_json:
13721370

1373-
vswhere_json = cls._vswhere_query_json_output(
1374-
vswhere_exe,
1375-
['-all', '-products', '*']
1376-
)
1371+
#print(json.dumps(instance, indent=4, sort_keys=True))
13771372

1378-
if not vswhere_json:
1373+
installation_path = instance.get('installationPath')
1374+
if not installation_path or not os.path.exists(installation_path):
13791375
continue
13801376

1381-
for instance in vswhere_json:
1382-
1383-
#print(json.dumps(instance, indent=4, sort_keys=True))
1384-
1385-
installation_path = instance.get('installationPath')
1386-
if not installation_path or not os.path.exists(installation_path):
1387-
continue
1388-
1389-
vc_path = os.path.join(installation_path, 'VC')
1390-
if not os.path.exists(vc_path):
1391-
continue
1377+
vc_path = os.path.join(installation_path, 'VC')
1378+
if not os.path.exists(vc_path):
1379+
continue
13921380

1393-
vc_root = MSVC.Util.normalize_path(vc_path)
1394-
if vc_root in cls.seen_root:
1395-
continue
1396-
cls.seen_root.add(vc_root)
1381+
vc_root = MSVC.Util.normalize_path(vc_path)
1382+
if vc_root in cls.seen_root:
1383+
continue
1384+
cls.seen_root.add(vc_root)
13971385

1398-
installation_version = instance.get('installationVersion')
1399-
if not installation_version:
1400-
continue
1386+
installation_version = instance.get('installationVersion')
1387+
if not installation_version:
1388+
continue
14011389

1402-
vs_major = installation_version.split('.')[0]
1403-
if not vs_major in _VSWHERE_VSMAJOR_TO_VCVERSION:
1404-
debug('ignore vs_major: %s', vs_major, extra=cls.debug_extra)
1405-
continue
1390+
vs_major = installation_version.split('.')[0]
1391+
if not vs_major in _VSWHERE_VSMAJOR_TO_VCVERSION:
1392+
debug('ignore vs_major: %s', vs_major, extra=cls.debug_extra)
1393+
continue
14061394

1407-
vc_version = _VSWHERE_VSMAJOR_TO_VCVERSION[vs_major]
1395+
vc_version = _VSWHERE_VSMAJOR_TO_VCVERSION[vs_major]
14081396

1409-
product_id = instance.get('productId')
1410-
if not product_id:
1411-
continue
1397+
product_id = instance.get('productId')
1398+
if not product_id:
1399+
continue
14121400

1413-
component_id = product_id.split('.')[-1]
1414-
if component_id not in _VSWHERE_COMPONENTID_CANDIDATES:
1415-
debug('ignore component_id: %s', component_id, extra=cls.debug_extra)
1416-
continue
1401+
component_id = product_id.split('.')[-1]
1402+
if component_id not in _VSWHERE_COMPONENTID_CANDIDATES:
1403+
debug('ignore component_id: %s', component_id, extra=cls.debug_extra)
1404+
continue
14171405

1418-
component_rank = _VSWHERE_COMPONENTID_RANKING.get(component_id,0)
1419-
if component_rank == 0:
1420-
raise MSVCInternalError(f'unknown component_rank for component_id: {component_id!r}')
1406+
component_rank = _VSWHERE_COMPONENTID_RANKING.get(component_id,0)
1407+
if component_rank == 0:
1408+
raise MSVCInternalError(f'unknown component_rank for component_id: {component_id!r}')
14211409

1422-
scons_suffix = _VSWHERE_COMPONENTID_SCONS_SUFFIX[component_id]
1410+
scons_suffix = _VSWHERE_COMPONENTID_SCONS_SUFFIX[component_id]
14231411

1424-
if scons_suffix:
1425-
vc_version_scons = vc_version + scons_suffix
1426-
else:
1427-
vc_version_scons = vc_version
1428-
1429-
is_prerelease = True if instance.get('isPrerelease', False) else False
1430-
is_release = False if is_prerelease else True
1431-
1432-
msvc_instance = MSVCInstance(
1433-
vc_path = vc_path,
1434-
vc_version = vc_version,
1435-
vc_version_numeric = float(vc_version),
1436-
vc_version_scons = vc_version_scons,
1437-
vc_release = is_release,
1438-
vc_component_id = component_id,
1439-
vc_component_rank = component_rank,
1440-
vc_component_suffix = component_suffix,
1441-
)
1412+
if scons_suffix:
1413+
vc_version_scons = vc_version + scons_suffix
1414+
else:
1415+
vc_version_scons = vc_version
1416+
1417+
is_prerelease = True if instance.get('isPrerelease', False) else False
1418+
is_release = False if is_prerelease else True
1419+
1420+
msvc_instance = MSVCInstance(
1421+
vc_path = vc_path,
1422+
vc_version = vc_version,
1423+
vc_version_numeric = float(vc_version),
1424+
vc_version_scons = vc_version_scons,
1425+
vc_release = is_release,
1426+
vc_component_id = component_id,
1427+
vc_component_rank = component_rank,
1428+
vc_component_suffix = component_suffix,
1429+
)
14421430

1443-
cls.msvc_instances.append(msvc_instance)
1431+
cls.msvc_instances.append(msvc_instance)
14441432

14451433
new_roots = bool(len(cls.msvc_instances) > n_instances)
14461434
if new_roots:

SCons/Tool/MSCommon/vs.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,8 @@ def reset(self) -> None:
426426
),
427427
]
428428

429-
SupportedVSWhereList = []
430429
SupportedVSMap = {}
431430
for vs in SupportedVSList:
432-
if vs.vernum >= 14.1:
433-
# VS2017 and later detected via vswhere.exe
434-
SupportedVSWhereList.append(vs)
435431
SupportedVSMap[vs.version] = vs
436432

437433

0 commit comments

Comments
 (0)