Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 # | 4 # |
| 5 # Copies the given "win tool" (which the toolchain uses to wrap compiler | 5 # Copies the given "win tool" (which the toolchain uses to wrap compiler |
| 6 # invocations) and the environment blocks for the 32-bit and 64-bit builds on | 6 # invocations) and the environment blocks for the 32-bit and 64-bit builds on |
| 7 # Windows to the build directory. | 7 # Windows to the build directory. |
| 8 # | 8 # |
| 9 # The arguments are the visual studio install location and the location of the | 9 # The arguments are the visual studio install location and the location of the |
| 10 # win tool. The script assumes that the root build directory is the current dir | 10 # win tool. The script assumes that the root build directory is the current dir |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 # later, python will still be found. | 47 # later, python will still be found. |
| 48 setting = os.path.dirname(sys.executable) + os.pathsep + setting | 48 setting = os.path.dirname(sys.executable) + os.pathsep + setting |
| 49 env[var.upper()] = setting | 49 env[var.upper()] = setting |
| 50 break | 50 break |
| 51 for required in ('SYSTEMROOT', 'TEMP', 'TMP'): | 51 for required in ('SYSTEMROOT', 'TEMP', 'TMP'): |
| 52 if required not in env: | 52 if required not in env: |
| 53 raise Exception('Environment variable "%s" ' | 53 raise Exception('Environment variable "%s" ' |
| 54 'required to be set to valid path' % required) | 54 'required to be set to valid path' % required) |
| 55 return env | 55 return env |
| 56 | 56 |
| 57 def _RegistryGetValueUsingWinReg(key, value): | |
| 58 """Use the _winreg module to obtain the value of a registry key. | |
| 59 | |
| 60 Args: | |
| 61 key: The registry key. | |
| 62 value: The particular registry value to read. | |
| 63 Return: | |
| 64 contents of the registry key's value, or None on failure. Throws | |
| 65 ImportError if _winreg is unavailable. | |
| 66 """ | |
| 67 import _winreg | |
| 68 try: | |
| 69 root, subkey = key.split('\\', 1) | |
| 70 assert root == 'HKLM' # Only need HKLM for now. | |
| 71 with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, subkey) as hkey: | |
| 72 return _winreg.QueryValueEx(hkey, value)[0] | |
| 73 except WindowsError: | |
| 74 return None | |
| 75 | |
| 76 | |
| 77 def _RegistryGetValue(key, value): | |
| 78 try: | |
| 79 return _RegistryGetValueUsingWinReg(key, value) | |
|
brucedawson
2016/01/04 21:36:06
Indented two extra spaces?
| |
| 80 except ImportError: | |
| 81 raise Exception('The python library _winreg not found.') | |
| 82 | |
| 83 | |
| 84 def _DetectVisualStudioPath(): | |
| 85 """Return path to the GYP_MSVS_VERSION of Visual Studio | |
| 86 """ | |
| 87 | |
| 88 # Default to 2015 for now. | |
| 89 version_as_year = os.environ.get('GYP_MSVS_VERSION', '2015') | |
| 90 year_to_version = { | |
| 91 '2013': '12.0', | |
| 92 '2015': '14.0', | |
| 93 } | |
| 94 if not version_as_year in year_to_version: | |
| 95 raise Exception(('Visual Studio Version %s (from GYP_MSVS_VERSION)' | |
| 96 ' not supported. Supported versions are: %s') % ( | |
| 97 version_as_year, ', '.join(year_to_version.keys()))) | |
| 98 version = year_to_version[version_as_year] | |
| 99 keys = [r'HKLM\Software\Microsoft\VisualStudio\%s' % version, | |
| 100 r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\%s' % version] | |
| 101 for key in keys: | |
| 102 path = _RegistryGetValue(key, 'InstallDir') | |
| 103 if not path: | |
| 104 continue | |
| 105 path = os.path.normpath(os.path.join(path, '..', '..')) | |
| 106 return path | |
| 107 | |
| 108 raise Exception(('Visual Studio Version %s (from GYP_MSVS_VERSION)' | |
| 109 ' not found.') % (version_as_year)) | |
| 110 | |
| 111 | |
| 57 | 112 |
| 58 def _SetupScript(target_cpu, sdk_dir): | 113 def _SetupScript(target_cpu, sdk_dir): |
| 59 """Returns a command (with arguments) to be used to set up the | 114 """Returns a command (with arguments) to be used to set up the |
| 60 environment.""" | 115 environment.""" |
| 61 # Check if we are running in the SDK command line environment and use | 116 # Check if we are running in the SDK command line environment and use |
| 62 # the setup script from the SDK if so. |target_cpu| should be either | 117 # the setup script from the SDK if so. |target_cpu| should be either |
| 63 # 'x86' or 'x64'. | 118 # 'x86' or 'x64'. |
| 64 assert target_cpu in ('x86', 'x64') | 119 assert target_cpu in ('x86', 'x64') |
| 65 if bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', 1))) and sdk_dir: | 120 if bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', 1))) and sdk_dir: |
| 66 return [os.path.normpath(os.path.join(sdk_dir, 'Bin/SetEnv.Cmd')), | 121 return [os.path.normpath(os.path.join(sdk_dir, 'Bin/SetEnv.Cmd')), |
| 67 '/' + target_cpu] | 122 '/' + target_cpu] |
| 68 else: | 123 else: |
| 124 if not 'GYP_MSVS_OVERRIDE_PATH' in os.environ: | |
| 125 os.environ['GYP_MSVS_OVERRIDE_PATH'] = _DetectVisualStudioPath() | |
| 69 # We only support x64-hosted tools. | 126 # We only support x64-hosted tools. |
| 70 # TODO(scottmg|dpranke): Non-depot_tools toolchain: need to get Visual | |
| 71 # Studio install location from registry. | |
| 72 return [os.path.normpath(os.path.join(os.environ['GYP_MSVS_OVERRIDE_PATH'], | 127 return [os.path.normpath(os.path.join(os.environ['GYP_MSVS_OVERRIDE_PATH'], |
| 73 'VC/vcvarsall.bat')), | 128 'VC/vcvarsall.bat')), |
| 74 'amd64_x86' if target_cpu == 'x86' else 'amd64'] | 129 'amd64_x86' if target_cpu == 'x86' else 'amd64'] |
| 75 | 130 |
| 76 | 131 |
| 77 def _FormatAsEnvironmentBlock(envvar_dict): | 132 def _FormatAsEnvironmentBlock(envvar_dict): |
| 78 """Format as an 'environment block' directly suitable for CreateProcess. | 133 """Format as an 'environment block' directly suitable for CreateProcess. |
| 79 Briefly this is a list of key=value\0, terminated by an additional \0. See | 134 Briefly this is a list of key=value\0, terminated by an additional \0. See |
| 80 CreateProcess documentation for more details.""" | 135 CreateProcess documentation for more details.""" |
| 81 block = '' | 136 block = '' |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 env_block = _FormatAsEnvironmentBlock(env) | 215 env_block = _FormatAsEnvironmentBlock(env) |
| 161 with open('environment.winrt_' + cpu, 'wb') as f: | 216 with open('environment.winrt_' + cpu, 'wb') as f: |
| 162 f.write(env_block) | 217 f.write(env_block) |
| 163 | 218 |
| 164 assert vc_bin_dir | 219 assert vc_bin_dir |
| 165 print 'vc_bin_dir = "%s"' % vc_bin_dir | 220 print 'vc_bin_dir = "%s"' % vc_bin_dir |
| 166 | 221 |
| 167 | 222 |
| 168 if __name__ == '__main__': | 223 if __name__ == '__main__': |
| 169 main() | 224 main() |
| OLD | NEW |