Chromium Code Reviews| Index: build/vs_toolchain.py |
| diff --git a/build/vs_toolchain.py b/build/vs_toolchain.py |
| index 7f535ea9bb41c317b55af45eb804116f38324f9d..4444375c38e8faa6f51e1fb738b0a946d8898423 100755 |
| --- a/build/vs_toolchain.py |
| +++ b/build/vs_toolchain.py |
| @@ -64,9 +64,68 @@ def SetEnvironmentAndGetRuntimeDllDirs(): |
| # Include the VS runtime in the PATH in case it's not machine-installed. |
| runtime_path = ';'.join(vs_runtime_dll_dirs) |
| os.environ['PATH'] = runtime_path + ';' + os.environ['PATH'] |
| + elif sys.platform in ('win32', 'cygwin') and not depot_tools_win_toolchain: |
| + if not 'GYP_MSVS_OVERRIDE_PATH' in os.environ: |
| + os.environ['GYP_MSVS_OVERRIDE_PATH'] = _DetectVisualStudioPath() |
| + |
| return vs_runtime_dll_dirs |
| +def _RegistryGetValueUsingWinReg(key, value): |
| + """Use the _winreg module to obtain the value of a registry key. |
| + |
| + Args: |
| + key: The registry key. |
| + value: The particular registry value to read. |
| + Return: |
| + contents of the registry key's value, or None on failure. Throws |
| + ImportError if _winreg is unavailable. |
| + """ |
| + import _winreg |
| + try: |
| + root, subkey = key.split('\\', 1) |
| + assert root == 'HKLM' # Only need HKLM for now. |
| + with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, subkey) as hkey: |
| + return _winreg.QueryValueEx(hkey, value)[0] |
| + except WindowsError: |
| + return None |
| + |
| + |
| +def _RegistryGetValue(key, value): |
| + try: |
| + return _RegistryGetValueUsingWinReg(key, value) |
|
brucedawson
2016/01/04 21:36:06
Also indented two extra spaces.
|
| + except ImportError: |
| + raise Exception('The python library _winreg not found.') |
| + |
| + |
| +def _DetectVisualStudioPath(): |
| + """Return path to the GYP_MSVS_VERSION of Visual Studio |
| + """ |
| + |
| + # Default to 2015 for now. |
| + version_as_year = os.environ.get('GYP_MSVS_VERSION', '2015') |
| + year_to_version = { |
| + '2013': '12.0', |
| + '2015': '14.0', |
| + } |
| + if not version_as_year in year_to_version: |
| + raise Exception(('Visual Studio Version %s (from GYP_MSVS_VERSION)' |
| + ' not supported. Supported versions are: %s') % ( |
| + version_as_year, ', '.join(year_to_version.keys()))) |
| + version = year_to_version[version_as_year] |
| + keys = [r'HKLM\Software\Microsoft\VisualStudio\%s' % version, |
| + r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\%s' % version] |
| + for key in keys: |
| + path = _RegistryGetValue(key, 'InstallDir') |
| + if not path: |
| + continue |
| + path = os.path.normpath(os.path.join(path, '..', '..')) |
| + return path |
| + |
| + raise Exception(('Visual Studio Version %s (from GYP_MSVS_VERSION)' |
| + ' not found.') % (version_as_year)) |
| + |
| + |
| def _VersionNumber(): |
| """Gets the standard version number ('120', '140', etc.) based on |
| GYP_MSVS_VERSION.""" |