Debian Codegraph @

gn/find_msvc.py

raw
1 #!/usr/bin/env python
2 # Copyright 2019 Google Inc.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import os
7 import sys
8 import subprocess
9
10 '''
11 Look for the first match in the format
12 C:\\Program Files (x86)\\Microsoft Visual Studio\\${RELEASE}\\${VERSION}\\VC
13 C:\\Program Files\\Microsoft Visual Studio\\${RELEASE}\\${VERSION}\\VC
14 If not found, use vswhere.exe.
15 '''
16 def find_msvc():
17 if sys.platform.startswith('win'):
18 default_dirs = [r'C:\Program Files\Microsoft Visual Studio',
19 r'C:\Program Files (x86)\Microsoft Visual Studio']
20 for default_dir in default_dirs:
21 for release in ['2022', '2019', '2017']:
22 for version in ['Enterprise', 'Professional', 'Community', 'BuildTools', 'Preview']:
23 path = os.path.join(default_dir, release, version, 'VC')
24 if os.path.isdir(path):
25 return path
26 # Fall back to vswhere.exe to determine non-standard installation paths
27 # Fixed location, https://github.com/Microsoft/vswhere/wiki/Installing
28 vswhere = os.path.join(os.getenv('ProgramFiles(x86)'),
29 'Microsoft Visual Studio', 'Installer', 'vswhere.exe')
30 command = (vswhere + ' -prerelease -legacy -products * -sort -utf8 '
31 '-property installationPath')
32 paths = subprocess.check_output(command).decode('utf-8').splitlines()
33 if paths:
34 return paths[0] + '\\VC'
35
36 return None
37
38 if __name__ == '__main__':
39 result = find_msvc()
40 if result:
41 sys.stdout.write(result + '\n')