Skip to content

Commit

Permalink
build: Add a --msvc-preview flag
Browse files Browse the repository at this point in the history
This flag allows compiling against the latest MSVC preview version. By
default, this is disabled; meaning only the latest stable MSVC release
is used.
  • Loading branch information
sankhesh committed Dec 1, 2023
1 parent 0c109c4 commit 1c991f8
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,21 @@ 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)' ],
'Microsoft Visual Studio',
'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 ] )
Expand Down Expand Up @@ -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',
Expand All @@ -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." )

Expand Down

0 comments on commit 1c991f8

Please sign in to comment.