@@ -1272,8 +1272,6 @@ def reset(cls):
1272
1272
cls .seen_vswhere = set ()
1273
1273
cls .seen_root = set ()
1274
1274
1275
- cls .vswhere_executables = []
1276
-
1277
1275
cls .msvc_instances = []
1278
1276
cls .msvc_map = {}
1279
1277
@@ -1283,20 +1281,20 @@ def _initialize(cls):
1283
1281
cls .reset ()
1284
1282
1285
1283
@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 ):
1290
1285
1291
- @classmethod
1292
- def _filter_vswhere_paths (cls , vswhere_exe ):
1286
+ vswhere_norm = None
1293
1287
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
1295
1291
1296
- if vswhere_exe and vswhere_exe not in cls .seen_vswhere :
1297
- vswhere_paths .append (vswhere_exe )
1292
+ return vswhere_norm
1298
1293
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' )
1300
1298
1301
1299
@classmethod
1302
1300
def _vswhere_query_json_output (cls , vswhere_exe , vswhere_args ):
@@ -1352,95 +1350,85 @@ def vswhere_update_msvc_map(cls, vswhere_exe):
1352
1350
1353
1351
frozen_binary , vswhere_binary = _VSWhereExecutable .vswhere_freeze_executable (vswhere_exe )
1354
1352
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 :
1359
1355
return cls .msvc_map
1360
1356
1361
- n_instances = len ( cls .msvc_instances )
1357
+ debug ( 'vswhere_norm=%s' , repr ( vswhere_norm ), extra = cls .debug_extra )
1362
1358
1363
- for vswhere_exe in vswhere_paths :
1359
+ vswhere_json = cls ._vswhere_query_json_output (
1360
+ vswhere_norm ,
1361
+ ['-all' , '-products' , '*' ]
1362
+ )
1364
1363
1365
- if vswhere_exe in cls . seen_vswhere :
1366
- continue
1364
+ if not vswhere_json :
1365
+ return cls . msvc_map
1367
1366
1368
- cls .seen_vswhere .add (vswhere_exe )
1369
- cls .vswhere_executables .append (vswhere_exe )
1367
+ n_instances = len (cls .msvc_instances )
1370
1368
1371
- debug ( 'vswhere_exe=%s' , repr ( vswhere_exe ), extra = cls . debug_extra )
1369
+ for instance in vswhere_json :
1372
1370
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))
1377
1372
1378
- if not vswhere_json :
1373
+ installation_path = instance .get ('installationPath' )
1374
+ if not installation_path or not os .path .exists (installation_path ):
1379
1375
continue
1380
1376
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
1392
1380
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 )
1397
1385
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
1401
1389
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
1406
1394
1407
- vc_version = _VSWHERE_VSMAJOR_TO_VCVERSION [vs_major ]
1395
+ vc_version = _VSWHERE_VSMAJOR_TO_VCVERSION [vs_major ]
1408
1396
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
1412
1400
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
1417
1405
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} ' )
1421
1409
1422
- scons_suffix = _VSWHERE_COMPONENTID_SCONS_SUFFIX [component_id ]
1410
+ scons_suffix = _VSWHERE_COMPONENTID_SCONS_SUFFIX [component_id ]
1423
1411
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
+ )
1442
1430
1443
- cls .msvc_instances .append (msvc_instance )
1431
+ cls .msvc_instances .append (msvc_instance )
1444
1432
1445
1433
new_roots = bool (len (cls .msvc_instances ) > n_instances )
1446
1434
if new_roots :
0 commit comments