Chromium Code Reviews| Index: build/toolchain/win/setup_toolchain.py |
| diff --git a/build/toolchain/win/setup_toolchain.py b/build/toolchain/win/setup_toolchain.py |
| index 4e79cd904eea00303f17b15380ba7b807ebda02b..1dc550fc8a076f408246c7e57531fa85d6234740 100644 |
| --- a/build/toolchain/win/setup_toolchain.py |
| +++ b/build/toolchain/win/setup_toolchain.py |
| @@ -54,6 +54,61 @@ def _ExtractImportantEnvironment(output_of_set): |
| 'required to be set to valid path' % required) |
| return env |
| +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
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 _SetupScript(target_cpu, sdk_dir): |
| """Returns a command (with arguments) to be used to set up the |
| @@ -66,9 +121,9 @@ def _SetupScript(target_cpu, sdk_dir): |
| return [os.path.normpath(os.path.join(sdk_dir, 'Bin/SetEnv.Cmd')), |
| '/' + target_cpu] |
| else: |
| + if not 'GYP_MSVS_OVERRIDE_PATH' in os.environ: |
| + os.environ['GYP_MSVS_OVERRIDE_PATH'] = _DetectVisualStudioPath() |
| # We only support x64-hosted tools. |
| - # TODO(scottmg|dpranke): Non-depot_tools toolchain: need to get Visual |
| - # Studio install location from registry. |
| return [os.path.normpath(os.path.join(os.environ['GYP_MSVS_OVERRIDE_PATH'], |
| 'VC/vcvarsall.bat')), |
| 'amd64_x86' if target_cpu == 'x86' else 'amd64'] |