From aba1b1d021ba5e73fcb0f6c2fab8e76d836e4639 Mon Sep 17 00:00:00 2001 From: Sankhesh Jhaveri Date: Fri, 1 Dec 2023 15:31:03 -0500 Subject: [PATCH] build: Add a --preview-msvc flag This flag allows compiling against the latest MSVC preview version. By default, this is disabled; meaning only the latest stable MSVC release is used. --- build.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/build.py b/build.py index 2b50993949..14971b5201 100755 --- a/build.py +++ b/build.py @@ -115,7 +115,7 @@ def Exit( self ): 'See the YCM docs for details on how to use a custom Clangd.' ) -def FindLatestMSVC( quiet ): +def FindLatestMSVC( quiet, preview=False ): ACCEPTABLE_VERSIONS = [ 17, 16, 15 ] VSWHERE_EXE = os.path.join( os.environ[ 'ProgramFiles(x86)' ], @@ -123,12 +123,13 @@ def FindLatestMSVC( quiet ): 'Installer', 'vswhere.exe' ) if os.path.exists( VSWHERE_EXE ): + vswhere_args = [ VSWHERE_EXE, + '-latest', '-property', 'installationVersion' ] + if preview: + vswhere_args.append( '-prerelease' ) if not quiet: - print( "Calling vswhere -latest -installationVersion" ) - latest_full_v = subprocess.check_output( - [ VSWHERE_EXE, '-latest', '-prerelease', '-property', - 'installationVersion' ] - ).strip().decode() + print( "Calling", *vswhere_args ) + latest_full_v = subprocess.check_output( vswhere_args ).strip().decode() if '.' in latest_full_v: try: latest_v = int( latest_full_v.split( '.' )[ 0 ] ) @@ -535,6 +536,10 @@ def ParseArguments(): action = 'store_true', help = 'Compiling with sudo causes problems. If you' ' know what you are doing, proceed.' ) + parser.add_argument( '--preview-msvc', + action = 'store_true', + help = 'Allow compiling against latest MSVC Preview' + ' version.' ) # These options are deprecated. parser.add_argument( '--omnisharp-completer', action = 'store_true', @@ -556,7 +561,7 @@ def ParseArguments(): args.enable_debug = True if OnWindows() and args.msvc is None: - args.msvc = FindLatestMSVC( args.quiet ) + args.msvc = FindLatestMSVC( args.quiet, args.preview_msvc ) if args.msvc is None: raise FileNotFoundError( "Could not find a valid MSVC version." )