OLD | NEW |
---|---|
1 #!/usr/bin/env python | |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # 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 |
3 # found in the LICENSE file. | 4 # found in the LICENSE file. |
4 | 5 |
5 import json | 6 import json |
6 import os | 7 import os |
7 import pipes | 8 import pipes |
8 import shutil | 9 import shutil |
9 import subprocess | 10 import subprocess |
10 import sys | 11 import sys |
(...skipping 11 matching lines...) Expand all Loading... | |
22 | 23 |
23 | 24 |
24 def SetEnvironmentAndGetRuntimeDllDirs(): | 25 def SetEnvironmentAndGetRuntimeDllDirs(): |
25 """Sets up os.environ to use the depot_tools VS toolchain with gyp, and | 26 """Sets up os.environ to use the depot_tools VS toolchain with gyp, and |
26 returns the location of the VS runtime DLLs so they can be copied into | 27 returns the location of the VS runtime DLLs so they can be copied into |
27 the output directory after gyp generation. | 28 the output directory after gyp generation. |
28 """ | 29 """ |
29 vs2013_runtime_dll_dirs = None | 30 vs2013_runtime_dll_dirs = None |
30 depot_tools_win_toolchain = \ | 31 depot_tools_win_toolchain = \ |
31 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) | 32 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) |
32 if sys.platform in ('win32', 'cygwin') and depot_tools_win_toolchain: | 33 # When running on a non-Windows host, only do this if the SDK has explicitly |
34 # been downloaded before (in which case json_data_file will exist). | |
35 if (sys.platform in ('win32', 'cygwin') and depot_tools_win_toolchain or | |
scottmg
2015/08/11 22:08:15
can you add more () here? `a and b or c` always co
Nico
2015/08/11 22:11:47
Done.
| |
36 os.path.exists(json_data_file)): | |
33 if not os.path.exists(json_data_file): | 37 if not os.path.exists(json_data_file): |
34 Update() | 38 Update() |
35 with open(json_data_file, 'r') as tempf: | 39 with open(json_data_file, 'r') as tempf: |
36 toolchain_data = json.load(tempf) | 40 toolchain_data = json.load(tempf) |
37 | 41 |
38 toolchain = toolchain_data['path'] | 42 toolchain = toolchain_data['path'] |
39 version = toolchain_data['version'] | 43 version = toolchain_data['version'] |
40 win_sdk = toolchain_data.get('win_sdk') | 44 win_sdk = toolchain_data.get('win_sdk') |
41 if not win_sdk: | 45 if not win_sdk: |
42 win_sdk = toolchain_data['win8sdk'] | 46 win_sdk = toolchain_data['win8sdk'] |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 | 113 |
110 | 114 |
111 def CopyVsRuntimeDlls(output_dir, runtime_dirs): | 115 def CopyVsRuntimeDlls(output_dir, runtime_dirs): |
112 """Copies the VS runtime DLLs from the given |runtime_dirs| to the output | 116 """Copies the VS runtime DLLs from the given |runtime_dirs| to the output |
113 directory so that even if not system-installed, built binaries are likely to | 117 directory so that even if not system-installed, built binaries are likely to |
114 be able to run. | 118 be able to run. |
115 | 119 |
116 This needs to be run after gyp has been run so that the expected target | 120 This needs to be run after gyp has been run so that the expected target |
117 output directories are already created. | 121 output directories are already created. |
118 """ | 122 """ |
119 assert sys.platform.startswith(('win32', 'cygwin')) | |
120 | |
121 x86, x64 = runtime_dirs | 123 x86, x64 = runtime_dirs |
122 out_debug = os.path.join(output_dir, 'Debug') | 124 out_debug = os.path.join(output_dir, 'Debug') |
123 out_debug_nacl64 = os.path.join(output_dir, 'Debug', 'x64') | 125 out_debug_nacl64 = os.path.join(output_dir, 'Debug', 'x64') |
124 out_release = os.path.join(output_dir, 'Release') | 126 out_release = os.path.join(output_dir, 'Release') |
125 out_release_nacl64 = os.path.join(output_dir, 'Release', 'x64') | 127 out_release_nacl64 = os.path.join(output_dir, 'Release', 'x64') |
126 out_debug_x64 = os.path.join(output_dir, 'Debug_x64') | 128 out_debug_x64 = os.path.join(output_dir, 'Debug_x64') |
127 out_release_x64 = os.path.join(output_dir, 'Release_x64') | 129 out_release_x64 = os.path.join(output_dir, 'Release_x64') |
128 | 130 |
129 if os.path.exists(out_debug) and not os.path.exists(out_debug_nacl64): | 131 if os.path.exists(out_debug) and not os.path.exists(out_debug_nacl64): |
130 os.makedirs(out_debug_nacl64) | 132 os.makedirs(out_debug_nacl64) |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 def _GetDesiredVsToolchainHashes(): | 188 def _GetDesiredVsToolchainHashes(): |
187 """Load a list of SHA1s corresponding to the toolchains that we want installed | 189 """Load a list of SHA1s corresponding to the toolchains that we want installed |
188 to build with.""" | 190 to build with.""" |
189 if os.environ.get('GYP_MSVS_VERSION') == '2015': | 191 if os.environ.get('GYP_MSVS_VERSION') == '2015': |
190 return ['49ae4b60d898182fc3f521c2fcda82c453915011'] | 192 return ['49ae4b60d898182fc3f521c2fcda82c453915011'] |
191 else: | 193 else: |
192 # Default to VS2013. | 194 # Default to VS2013. |
193 return ['ee7d718ec60c2dc5d255bbe325909c2021a7efef'] | 195 return ['ee7d718ec60c2dc5d255bbe325909c2021a7efef'] |
194 | 196 |
195 | 197 |
196 def Update(): | 198 def Update(force=False): |
197 """Requests an update of the toolchain to the specific hashes we have at | 199 """Requests an update of the toolchain to the specific hashes we have at |
198 this revision. The update outputs a .json of the various configuration | 200 this revision. The update outputs a .json of the various configuration |
199 information required to pass to gyp which we use in |GetToolchainDir()|. | 201 information required to pass to gyp which we use in |GetToolchainDir()|. |
200 """ | 202 """ |
203 if force != False and force != '--force': | |
204 print >>sys.stderr, 'Unknown parameter "%s"' % force | |
205 return 1 | |
206 if force == '--force' or os.path.exists(json_data_file): | |
scottmg
2015/08/11 22:08:15
what crazy person made `json_data_file` a global?
Nico
2015/08/11 22:11:47
Acknowledged.
scottmg
2015/08/11 22:15:56
Acknowledged.
| |
207 force = True | |
208 | |
201 depot_tools_win_toolchain = \ | 209 depot_tools_win_toolchain = \ |
202 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) | 210 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) |
203 if sys.platform in ('win32', 'cygwin') and depot_tools_win_toolchain: | 211 if ((sys.platform in ('win32', 'cygwin') or force) and |
212 depot_tools_win_toolchain): | |
204 import find_depot_tools | 213 import find_depot_tools |
205 depot_tools_path = find_depot_tools.add_depot_tools_to_path() | 214 depot_tools_path = find_depot_tools.add_depot_tools_to_path() |
206 get_toolchain_args = [ | 215 get_toolchain_args = [ |
207 sys.executable, | 216 sys.executable, |
208 os.path.join(depot_tools_path, | 217 os.path.join(depot_tools_path, |
209 'win_toolchain', | 218 'win_toolchain', |
210 'get_toolchain_if_necessary.py'), | 219 'get_toolchain_if_necessary.py'), |
211 '--output-json', json_data_file, | 220 '--output-json', json_data_file, |
212 ] + _GetDesiredVsToolchainHashes() | 221 ] + _GetDesiredVsToolchainHashes() |
222 if force: | |
223 get_toolchain_args.append('--force') | |
213 subprocess.check_call(get_toolchain_args) | 224 subprocess.check_call(get_toolchain_args) |
214 | 225 |
215 return 0 | 226 return 0 |
216 | 227 |
217 | 228 |
218 def GetToolchainDir(): | 229 def GetToolchainDir(): |
219 """Gets location information about the current toolchain (must have been | 230 """Gets location information about the current toolchain (must have been |
220 previously updated by 'update'). This is used for the GN build.""" | 231 previously updated by 'update'). This is used for the GN build.""" |
221 runtime_dll_dirs = SetEnvironmentAndGetRuntimeDllDirs() | 232 runtime_dll_dirs = SetEnvironmentAndGetRuntimeDllDirs() |
222 | 233 |
(...skipping 10 matching lines...) Expand all Loading... | |
233 runtime_dirs = "%s" | 244 runtime_dirs = "%s" |
234 ''' % ( | 245 ''' % ( |
235 os.environ['GYP_MSVS_OVERRIDE_PATH'], | 246 os.environ['GYP_MSVS_OVERRIDE_PATH'], |
236 os.environ['WINDOWSSDKDIR'], | 247 os.environ['WINDOWSSDKDIR'], |
237 os.environ['GYP_MSVS_VERSION'], | 248 os.environ['GYP_MSVS_VERSION'], |
238 os.environ.get('WDK_DIR', ''), | 249 os.environ.get('WDK_DIR', ''), |
239 ';'.join(runtime_dll_dirs or ['None'])) | 250 ';'.join(runtime_dll_dirs or ['None'])) |
240 | 251 |
241 | 252 |
242 def main(): | 253 def main(): |
243 if not sys.platform.startswith(('win32', 'cygwin')): | |
scottmg
2015/08/11 22:08:15
i'm slightly nervous about this failing somewhere
| |
244 return 0 | |
245 commands = { | 254 commands = { |
246 'update': Update, | 255 'update': Update, |
247 'get_toolchain_dir': GetToolchainDir, | 256 'get_toolchain_dir': GetToolchainDir, |
248 'copy_dlls': CopyDlls, | 257 'copy_dlls': CopyDlls, |
249 } | 258 } |
250 if len(sys.argv) < 2 or sys.argv[1] not in commands: | 259 if len(sys.argv) < 2 or sys.argv[1] not in commands: |
251 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) | 260 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) |
252 return 1 | 261 return 1 |
253 return commands[sys.argv[1]](*sys.argv[2:]) | 262 return commands[sys.argv[1]](*sys.argv[2:]) |
254 | 263 |
255 | 264 |
256 if __name__ == '__main__': | 265 if __name__ == '__main__': |
257 sys.exit(main()) | 266 sys.exit(main()) |
OLD | NEW |