find_msvc.py 776 B

1234567891011121314151617181920212223242526
  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. import os
  6. import sys
  7. '''
  8. Look for the first match in the format
  9. C:\\Program Files (x86)\\Microsoft Visual Studio\\${RELEASE}\\${VERSION}\\VC
  10. '''
  11. def find_msvc():
  12. if sys.platform.startswith('win'):
  13. default_dir = r'C:\Program Files (x86)\Microsoft Visual Studio'
  14. for release in ['2019', '2017']:
  15. for version in ['Enterprise', 'Professional', 'Community', 'BuildTools']:
  16. path = os.path.join(default_dir, release, version, 'VC')
  17. if os.path.isdir(path):
  18. return path
  19. return None
  20. if __name__ == '__main__':
  21. result = find_msvc()
  22. if result:
  23. sys.stdout.write(result + '\n')