OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import json | 6 import json |
7 import os | 7 import os |
8 import pipes | 8 import pipes |
9 import shutil | 9 import shutil |
10 import subprocess | 10 import subprocess |
(...skipping 46 matching lines...) Loading... | |
57 # values there. | 57 # values there. |
58 gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES')) | 58 gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES')) |
59 gyp_defines_dict['windows_sdk_path'] = win_sdk | 59 gyp_defines_dict['windows_sdk_path'] = win_sdk |
60 os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v))) | 60 os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v))) |
61 for k, v in gyp_defines_dict.iteritems()) | 61 for k, v in gyp_defines_dict.iteritems()) |
62 os.environ['WINDOWSSDKDIR'] = win_sdk | 62 os.environ['WINDOWSSDKDIR'] = win_sdk |
63 os.environ['WDK_DIR'] = wdk | 63 os.environ['WDK_DIR'] = wdk |
64 # Include the VS runtime in the PATH in case it's not machine-installed. | 64 # Include the VS runtime in the PATH in case it's not machine-installed. |
65 runtime_path = ';'.join(vs_runtime_dll_dirs) | 65 runtime_path = ';'.join(vs_runtime_dll_dirs) |
66 os.environ['PATH'] = runtime_path + ';' + os.environ['PATH'] | 66 os.environ['PATH'] = runtime_path + ';' + os.environ['PATH'] |
67 elif sys.platform in ('win32', 'cygwin') and not depot_tools_win_toolchain: | |
scottmg
2016/01/05 23:30:32
Did you test on cygwin? Otherwise drop that; I thi
Daniel Bratell
2016/01/07 16:10:48
Quite likely, and yes, I did not test in cygwin. R
| |
68 if not 'GYP_MSVS_OVERRIDE_PATH' in os.environ: | |
69 os.environ['GYP_MSVS_OVERRIDE_PATH'] = DetectVisualStudioPath() | |
70 | |
67 return vs_runtime_dll_dirs | 71 return vs_runtime_dll_dirs |
68 | 72 |
69 | 73 |
74 def _RegistryGetValueUsingWinReg(key, value): | |
75 """Use the _winreg module to obtain the value of a registry key. | |
76 | |
77 Args: | |
78 key: The registry key. | |
79 value: The particular registry value to read. | |
80 Return: | |
81 contents of the registry key's value, or None on failure. Throws | |
82 ImportError if _winreg is unavailable. | |
83 """ | |
84 import _winreg | |
85 try: | |
86 root, subkey = key.split('\\', 1) | |
87 assert root == 'HKLM' # Only need HKLM for now. | |
88 with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, subkey) as hkey: | |
89 return _winreg.QueryValueEx(hkey, value)[0] | |
90 except WindowsError: | |
91 return None | |
92 | |
93 | |
94 def _RegistryGetValue(key, value): | |
95 try: | |
scottmg
2016/01/05 23:30:32
Indent is wrong in this function.
Daniel Bratell
2016/01/07 16:10:48
Done.
| |
96 return _RegistryGetValueUsingWinReg(key, value) | |
97 except ImportError: | |
98 raise Exception('The python library _winreg not found.') | |
99 | |
100 | |
101 def DetectVisualStudioPath(): | |
102 """Return path to the GYP_MSVS_VERSION of Visual Studio | |
scottmg
2016/01/05 23:30:32
nit; End with '.'.
| |
103 """ | |
104 | |
105 # Note that this code is used from | |
106 # build/toolchain/win/setup_toolchain.py as well. | |
107 | |
108 # Default to Visual Studio 2013 for now. | |
109 version_as_year = os.environ.get('GYP_MSVS_VERSION', '2013') | |
110 year_to_version = { | |
111 '2013': '12.0', | |
112 '2015': '14.0', | |
113 } | |
114 if not version_as_year in year_to_version: | |
scottmg
2016/01/05 23:30:32
"if version_as_year not in year_to_version" is mor
Daniel Bratell
2016/01/07 16:10:48
Done.
| |
115 raise Exception(('Visual Studio Version %s (from GYP_MSVS_VERSION)' | |
scottmg
2016/01/05 23:30:32
nit; lower case v on "version".
Daniel Bratell
2016/01/07 16:10:48
Done.
| |
116 ' not supported. Supported versions are: %s') % ( | |
117 version_as_year, ', '.join(year_to_version.keys()))) | |
118 version = year_to_version[version_as_year] | |
119 keys = [r'HKLM\Software\Microsoft\VisualStudio\%s' % version, | |
120 r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\%s' % version] | |
121 for key in keys: | |
122 path = _RegistryGetValue(key, 'InstallDir') | |
123 if not path: | |
124 continue | |
125 path = os.path.normpath(os.path.join(path, '..', '..')) | |
126 return path | |
127 | |
128 raise Exception(('Visual Studio Version %s (from GYP_MSVS_VERSION)' | |
129 ' not found.') % (version_as_year)) | |
130 | |
131 | |
70 def _VersionNumber(): | 132 def _VersionNumber(): |
71 """Gets the standard version number ('120', '140', etc.) based on | 133 """Gets the standard version number ('120', '140', etc.) based on |
72 GYP_MSVS_VERSION.""" | 134 GYP_MSVS_VERSION.""" |
73 if os.environ['GYP_MSVS_VERSION'] == '2013': | 135 if os.environ['GYP_MSVS_VERSION'] == '2013': |
74 return '120' | 136 return '120' |
75 elif os.environ['GYP_MSVS_VERSION'] == '2015': | 137 elif os.environ['GYP_MSVS_VERSION'] == '2015': |
76 return '140' | 138 return '140' |
77 else: | 139 else: |
78 raise ValueError('Unexpected GYP_MSVS_VERSION') | 140 raise ValueError('Unexpected GYP_MSVS_VERSION') |
79 | 141 |
(...skipping 183 matching lines...) Loading... | |
263 'copy_dlls': CopyDlls, | 325 'copy_dlls': CopyDlls, |
264 } | 326 } |
265 if len(sys.argv) < 2 or sys.argv[1] not in commands: | 327 if len(sys.argv) < 2 or sys.argv[1] not in commands: |
266 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) | 328 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) |
267 return 1 | 329 return 1 |
268 return commands[sys.argv[1]](*sys.argv[2:]) | 330 return commands[sys.argv[1]](*sys.argv[2:]) |
269 | 331 |
270 | 332 |
271 if __name__ == '__main__': | 333 if __name__ == '__main__': |
272 sys.exit(main()) | 334 sys.exit(main()) |
OLD | NEW |