@@ -2572,28 +2572,24 @@ def msvc_toolset_versions_spectre(msvc_version=None, vswhere_exe=None):
2572
2572
2573
2573
def msvc_query_version_toolset (version = None , prefer_newest : bool = True , vswhere_exe = None ):
2574
2574
"""
2575
- Returns an msvc version and a toolset version given a version
2575
+ Return an msvc version and a toolset version given a version
2576
2576
specification.
2577
2577
2578
2578
This is an EXPERIMENTAL proxy for using a toolset version to perform
2579
2579
msvc instance selection. This function will be removed when
2580
2580
toolset version is taken into account during msvc instance selection.
2581
2581
2582
- Search for an installed Visual Studio instance that supports the
2583
- specified version.
2582
+ This function searches for an installed Visual Studio instance that
2583
+ contains the requested version. A component suffix (e.g., Exp) is not
2584
+ supported for toolset version specifications (e.g., 14.39).
2584
2585
2585
- When the specified version contains a component suffix (e.g., Exp),
2586
- the msvc version is returned and the toolset version is None. No
2587
- search if performed .
2586
+ An MSVCArgumentError is raised when argument validation fails. An
2587
+ MSVCToolsetVersionNotFound exception is raised when the requested
2588
+ version is not found .
2588
2589
2589
- When the specified version does not contain a component suffix, the
2590
- version is treated as a toolset version specification. A search is
2591
- performed for the first msvc instance that contains the toolset
2592
- version.
2593
-
2594
- Only Visual Studio 2017 and later support toolset arguments. For
2595
- Visual Studio 2015 and earlier, the msvc version is returned and
2596
- the toolset version is None.
2590
+ For Visual Studio 2015 and earlier, the msvc version is returned and
2591
+ the toolset version is None. For Visual Studio 2017 and later, the
2592
+ selected toolset version is returned.
2597
2593
2598
2594
Args:
2599
2595
@@ -2623,106 +2619,132 @@ def msvc_query_version_toolset(version=None, prefer_newest: bool=True, vswhere_e
2623
2619
msvc_version = None
2624
2620
msvc_toolset_version = None
2625
2621
2626
- if not version :
2627
- version = msvc_default_version ()
2622
+ with MSVC .Policy .msvc_notfound_policy_contextmanager ('suppress' ):
2628
2623
2629
- if not version :
2630
- debug ('no msvc versions detected' )
2631
- return msvc_version , msvc_toolset_version
2624
+ _VSWhereExecutable .vswhere_freeze_executable (vswhere_exe )
2632
2625
2633
- version_def = MSVC . Util . msvc_extended_version_components ( version )
2626
+ vcs = get_installed_vcs ( )
2634
2627
2635
- if not version_def :
2636
- msg = f'Unsupported msvc version { version !r} '
2637
- raise MSVCArgumentError (msg )
2628
+ if not version :
2629
+ version = msvc_default_version ()
2638
2630
2639
- if version_def .msvc_suffix :
2640
- if version_def .msvc_verstr != version_def .msvc_toolset_version :
2641
- # toolset version with component suffix
2642
- msg = f'Unsupported toolset version { version !r} '
2643
- raise MSVCArgumentError (msg )
2631
+ if not version :
2632
+ msg = f'No versions of the MSVC compiler were found'
2633
+ debug (f'MSVCToolsetVersionNotFound: { msg } ' )
2634
+ raise MSVCToolsetVersionNotFound (msg )
2644
2635
2645
- if version_def .msvc_vernum > 14.0 :
2646
- # VS2017 and later
2647
- force_toolset_msvc_version = False
2648
- else :
2649
- # VS2015 and earlier
2650
- force_toolset_msvc_version = True
2651
- extended_version = version_def .msvc_verstr + '0.00000'
2652
- if not extended_version .startswith (version_def .msvc_toolset_version ):
2653
- # toolset not equivalent to msvc version
2654
- msg = 'Unsupported toolset version {} (expected {})' .format (
2655
- repr (version ), repr (extended_version )
2656
- )
2636
+ version_def = MSVC .Util .msvc_extended_version_components (version )
2637
+
2638
+ if not version_def :
2639
+ msg = f'Unsupported MSVC version { version !r} '
2640
+ debug (f'MSVCArgumentError: { msg } ' )
2657
2641
raise MSVCArgumentError (msg )
2658
2642
2659
- msvc_version = version_def .msvc_version
2643
+ msvc_version = version_def .msvc_version
2660
2644
2661
- if msvc_version not in MSVC .Config .MSVC_VERSION_TOOLSET_SEARCH_MAP :
2662
- # VS2013 and earlier
2663
- debug (
2664
- 'ignore: msvc_version=%s, msvc_toolset_version=%s' ,
2665
- repr (msvc_version ), repr (msvc_toolset_version )
2666
- )
2667
- return msvc_version , msvc_toolset_version
2645
+ if version_def .msvc_suffix :
2668
2646
2669
- if force_toolset_msvc_version :
2670
- query_msvc_toolset_version = version_def .msvc_verstr
2671
- else :
2672
- query_msvc_toolset_version = version_def .msvc_toolset_version
2647
+ if version_def .msvc_verstr != version_def .msvc_toolset_version :
2648
+ # toolset version with component suffix
2649
+ msg = f'Unsupported MSVC toolset version { version !r} '
2650
+ debug (f'MSVCArgumentError: { msg } ' )
2651
+ raise MSVCArgumentError (msg )
2673
2652
2674
- if prefer_newest :
2675
- query_version_list = MSVC .Config .MSVC_VERSION_TOOLSET_SEARCH_MAP [msvc_version ]
2676
- else :
2677
- query_version_list = MSVC .Config .MSVC_VERSION_TOOLSET_DEFAULTS_MAP [msvc_version ] + \
2678
- MSVC .Config .MSVC_VERSION_TOOLSET_SEARCH_MAP [msvc_version ]
2653
+ if msvc_version not in vcs :
2654
+ msg = f'MSVC version { msvc_version !r} not found'
2655
+ debug (f'MSVCToolsetVersionNotFound: { msg } ' )
2656
+ raise MSVCToolsetVersionNotFound (msg )
2679
2657
2680
- seen_msvc_version = set ()
2681
- for query_msvc_version in query_version_list :
2658
+ if msvc_version not in MSVC .Config .MSVC_VERSION_TOOLSET_SEARCH_MAP :
2659
+ debug (
2660
+ 'suffix: msvc_version=%s, msvc_toolset_version=%s' ,
2661
+ repr (msvc_version ), repr (msvc_toolset_version )
2662
+ )
2663
+ return msvc_version , msvc_toolset_version
2682
2664
2683
- if query_msvc_version in seen_msvc_version :
2684
- continue
2685
- seen_msvc_version .add (query_msvc_version )
2665
+ if version_def .msvc_vernum > 14.0 :
2666
+ # VS2017 and later
2667
+ force_toolset_msvc_version = False
2668
+ else :
2669
+ # VS2015 and earlier
2670
+ force_toolset_msvc_version = True
2671
+ extended_version = version_def .msvc_verstr + '0.00000'
2672
+ if not extended_version .startswith (version_def .msvc_toolset_version ):
2673
+ # toolset not equivalent to msvc version
2674
+ msg = 'Unsupported MSVC toolset version {} (expected {})' .format (
2675
+ repr (version ), repr (extended_version )
2676
+ )
2677
+ debug (f'MSVCArgumentError: { msg } ' )
2678
+ raise MSVCArgumentError (msg )
2686
2679
2687
- vc_dir = _find_vc_pdir (query_msvc_version , vswhere_exe )
2688
- if not vc_dir :
2689
- continue
2680
+ if msvc_version not in MSVC .Config .MSVC_VERSION_TOOLSET_SEARCH_MAP :
2681
+
2682
+ # VS2013 and earlier
2683
+
2684
+ if msvc_version not in vcs :
2685
+ msg = f'MSVC version { version !r} not found'
2686
+ debug (f'MSVCToolsetVersionNotFound: { msg } ' )
2687
+ raise MSVCToolsetVersionNotFound (msg )
2690
2688
2691
- if query_msvc_version .startswith ('14.0' ):
2692
- # VS2015 does not support toolset version argument
2693
- msvc_toolset_version = None
2694
2689
debug (
2695
- 'found : msvc_version=%s, msvc_toolset_version=%s' ,
2696
- repr (query_msvc_version ), repr (msvc_toolset_version )
2690
+ 'earlier : msvc_version=%s, msvc_toolset_version=%s' ,
2691
+ repr (msvc_version ), repr (msvc_toolset_version )
2697
2692
)
2698
- return query_msvc_version , msvc_toolset_version
2693
+ return msvc_version , msvc_toolset_version
2699
2694
2700
- try :
2701
- toolset_vcvars = MSVC .ScriptArguments ._msvc_toolset_internal (query_msvc_version , query_msvc_toolset_version , vc_dir )
2702
- if toolset_vcvars :
2703
- msvc_toolset_version = toolset_vcvars
2695
+ if force_toolset_msvc_version :
2696
+ query_msvc_toolset_version = version_def .msvc_verstr
2697
+ else :
2698
+ query_msvc_toolset_version = version_def .msvc_toolset_version
2699
+
2700
+ if prefer_newest :
2701
+ query_version_list = MSVC .Config .MSVC_VERSION_TOOLSET_SEARCH_MAP [msvc_version ]
2702
+ else :
2703
+ query_version_list = MSVC .Config .MSVC_VERSION_TOOLSET_DEFAULTS_MAP [msvc_version ] + \
2704
+ MSVC .Config .MSVC_VERSION_TOOLSET_SEARCH_MAP [msvc_version ]
2705
+
2706
+ seen_msvc_version = set ()
2707
+ for query_msvc_version in query_version_list :
2708
+
2709
+ if query_msvc_version in seen_msvc_version :
2710
+ continue
2711
+ seen_msvc_version .add (query_msvc_version )
2712
+
2713
+ vc_dir = _find_vc_pdir (query_msvc_version , vswhere_exe )
2714
+ if not vc_dir :
2715
+ continue
2716
+
2717
+ if query_msvc_version .startswith ('14.0' ):
2718
+ # VS2015 does not support toolset version argument
2719
+ msvc_toolset_version = None
2704
2720
debug (
2705
2721
'found: msvc_version=%s, msvc_toolset_version=%s' ,
2706
2722
repr (query_msvc_version ), repr (msvc_toolset_version )
2707
2723
)
2708
2724
return query_msvc_version , msvc_toolset_version
2709
2725
2710
- except MSVCToolsetVersionNotFound :
2711
- pass
2726
+ try :
2727
+ toolset_vcvars = MSVC .ScriptArguments ._msvc_toolset_internal (query_msvc_version , query_msvc_toolset_version , vc_dir )
2728
+ if toolset_vcvars :
2729
+ msvc_toolset_version = toolset_vcvars
2730
+ debug (
2731
+ 'found: msvc_version=%s, msvc_toolset_version=%s' ,
2732
+ repr (query_msvc_version ), repr (msvc_toolset_version )
2733
+ )
2734
+ return query_msvc_version , msvc_toolset_version
2712
2735
2713
- msvc_toolset_version = query_msvc_toolset_version
2736
+ except MSVCToolsetVersionNotFound :
2737
+ pass
2738
+
2739
+ msvc_toolset_version = query_msvc_toolset_version
2714
2740
2715
2741
debug (
2716
2742
'not found: msvc_version=%s, msvc_toolset_version=%s' ,
2717
2743
repr (msvc_version ), repr (msvc_toolset_version )
2718
2744
)
2719
2745
2720
- if version_def .msvc_verstr == msvc_toolset_version :
2721
- msg = f'MSVC version { version !r} was not found'
2722
- MSVC .Policy .msvc_notfound_handler (None , msg )
2723
- return msvc_version , msvc_toolset_version
2724
-
2725
2746
msg = f'MSVC toolset version { version !r} not found'
2747
+ debug (f'MSVCToolsetVersionNotFound: { msg } ' )
2726
2748
raise MSVCToolsetVersionNotFound (msg )
2727
2749
2728
2750
0 commit comments