Hal Canary | f72728e | 2019-07-10 11:24:52 -0400 | [diff] [blame] | 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 |
Martin Vejdarski | c569504 | 2020-03-09 01:07:26 +0700 | [diff] [blame] | 8 | import subprocess |
Hal Canary | f72728e | 2019-07-10 11:24:52 -0400 | [diff] [blame] | 9 | |
| 10 | ''' |
| 11 | Look for the first match in the format |
| 12 | C:\\Program Files (x86)\\Microsoft Visual Studio\\${RELEASE}\\${VERSION}\\VC |
| 13 | ''' |
| 14 | def find_msvc(): |
| 15 | if sys.platform.startswith('win'): |
| 16 | default_dir = r'C:\Program Files (x86)\Microsoft Visual Studio' |
| 17 | for release in ['2019', '2017']: |
Ben Wagner | 6666229 | 2020-04-30 14:12:00 -0400 | [diff] [blame] | 18 | for version in ['Enterprise', 'Professional', 'Community', 'BuildTools', 'Preview']: |
Hal Canary | f72728e | 2019-07-10 11:24:52 -0400 | [diff] [blame] | 19 | path = os.path.join(default_dir, release, version, 'VC') |
| 20 | if os.path.isdir(path): |
| 21 | return path |
Martin Vejdarski | c569504 | 2020-03-09 01:07:26 +0700 | [diff] [blame] | 22 | |
| 23 | # Fall back to vswhere.exe to determine non-standard installation paths |
| 24 | # Fixed location, https://github.com/Microsoft/vswhere/wiki/Installing |
| 25 | vswhere = os.path.join(os.getenv('ProgramFiles(x86)'), |
| 26 | 'Microsoft Visual Studio', 'Installer', 'vswhere.exe') |
| 27 | command = (vswhere + ' -prerelease -legacy -products * -sort -utf8 ' |
| 28 | '-property installationPath') |
| 29 | paths = subprocess.check_output(command).decode('utf-8').splitlines() |
| 30 | if paths: |
| 31 | return paths[0] + '\\VC' |
| 32 | |
Hal Canary | f72728e | 2019-07-10 11:24:52 -0400 | [diff] [blame] | 33 | return None |
| 34 | |
| 35 | if __name__ == '__main__': |
| 36 | result = find_msvc() |
| 37 | if result: |
| 38 | sys.stdout.write(result + '\n') |