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 |
11 import sys | 11 import sys |
12 | 12 |
13 | 13 |
14 script_dir = os.path.dirname(os.path.realpath(__file__)) | 14 script_dir = os.path.dirname(os.path.realpath(__file__)) |
15 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir)) | 15 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir)) |
16 SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 16 SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
17 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib')) | 17 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib')) |
18 json_data_file = os.path.join(script_dir, 'win_toolchain.json') | 18 json_data_file = os.path.join(script_dir, 'win_toolchain.json') |
19 | 19 |
20 | 20 |
21 import gyp | 21 import gyp |
22 | 22 |
23 | 23 |
24 # Use MSVS2013 as the default toolchain. | |
25 CURRENT_TOOLCHAIN_VERSION = '2013' | |
brucedawson
2016/01/15 21:10:52
Should probably be "CURRENT_DEFAULT_TOOLCHAIN_VERS
Sébastien Marchand
2016/01/15 21:21:39
Done.
| |
26 | |
27 | |
24 def SetEnvironmentAndGetRuntimeDllDirs(): | 28 def SetEnvironmentAndGetRuntimeDllDirs(): |
25 """Sets up os.environ to use the depot_tools VS toolchain with gyp, and | 29 """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 | 30 returns the location of the VS runtime DLLs so they can be copied into |
27 the output directory after gyp generation. | 31 the output directory after gyp generation. |
28 """ | 32 """ |
29 vs_runtime_dll_dirs = None | 33 vs_runtime_dll_dirs = None |
30 depot_tools_win_toolchain = \ | 34 depot_tools_win_toolchain = \ |
31 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) | 35 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) |
32 # When running on a non-Windows host, only do this if the SDK has explicitly | 36 # When running on a non-Windows host, only do this if the SDK has explicitly |
33 # been downloaded before (in which case json_data_file will exist). | 37 # been downloaded before (in which case json_data_file will exist). |
34 if ((sys.platform in ('win32', 'cygwin') or os.path.exists(json_data_file)) | 38 if ((sys.platform in ('win32', 'cygwin') or os.path.exists(json_data_file)) |
35 and depot_tools_win_toolchain): | 39 and depot_tools_win_toolchain): |
36 if not os.path.exists(json_data_file): | 40 if ShouldUpdateToolchain(): |
37 Update() | 41 Update() |
38 with open(json_data_file, 'r') as tempf: | 42 with open(json_data_file, 'r') as tempf: |
39 toolchain_data = json.load(tempf) | 43 toolchain_data = json.load(tempf) |
40 | 44 |
41 toolchain = toolchain_data['path'] | 45 toolchain = toolchain_data['path'] |
42 version = toolchain_data['version'] | 46 version = toolchain_data['version'] |
43 win_sdk = toolchain_data.get('win_sdk') | 47 win_sdk = toolchain_data.get('win_sdk') |
44 if not win_sdk: | 48 if not win_sdk: |
45 win_sdk = toolchain_data['win8sdk'] | 49 win_sdk = toolchain_data['win8sdk'] |
46 wdk = toolchain_data['wdk'] | 50 wdk = toolchain_data['wdk'] |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 raise Exception('The python library _winreg not found.') | 102 raise Exception('The python library _winreg not found.') |
99 | 103 |
100 | 104 |
101 def DetectVisualStudioPath(): | 105 def DetectVisualStudioPath(): |
102 """Return path to the GYP_MSVS_VERSION of Visual Studio. | 106 """Return path to the GYP_MSVS_VERSION of Visual Studio. |
103 """ | 107 """ |
104 | 108 |
105 # Note that this code is used from | 109 # Note that this code is used from |
106 # build/toolchain/win/setup_toolchain.py as well. | 110 # build/toolchain/win/setup_toolchain.py as well. |
107 | 111 |
108 # Default to Visual Studio 2013 for now. | 112 version_as_year = os.environ.get('GYP_MSVS_VERSION', |
109 version_as_year = os.environ.get('GYP_MSVS_VERSION', '2013') | 113 CURRENT_TOOLCHAIN_VERSION) |
110 year_to_version = { | 114 year_to_version = { |
111 '2013': '12.0', | 115 '2013': '12.0', |
112 '2015': '14.0', | 116 '2015': '14.0', |
113 } | 117 } |
114 if version_as_year not in year_to_version: | 118 if version_as_year not in year_to_version: |
115 raise Exception(('Visual Studio version %s (from GYP_MSVS_VERSION)' | 119 raise Exception(('Visual Studio version %s (from GYP_MSVS_VERSION)' |
116 ' not supported. Supported versions are: %s') % ( | 120 ' not supported. Supported versions are: %s') % ( |
117 version_as_year, ', '.join(year_to_version.keys()))) | 121 version_as_year, ', '.join(year_to_version.keys()))) |
118 version = year_to_version[version_as_year] | 122 version = year_to_version[version_as_year] |
119 keys = [r'HKLM\Software\Microsoft\VisualStudio\%s' % version, | 123 keys = [r'HKLM\Software\Microsoft\VisualStudio\%s' % version, |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 def _GetDesiredVsToolchainHashes(): | 260 def _GetDesiredVsToolchainHashes(): |
257 """Load a list of SHA1s corresponding to the toolchains that we want installed | 261 """Load a list of SHA1s corresponding to the toolchains that we want installed |
258 to build with.""" | 262 to build with.""" |
259 if os.environ.get('GYP_MSVS_VERSION') == '2015': | 263 if os.environ.get('GYP_MSVS_VERSION') == '2015': |
260 return ['17c7ddb3595be5c6b9c98b6f930adad7e4456671'] # Update 1 | 264 return ['17c7ddb3595be5c6b9c98b6f930adad7e4456671'] # Update 1 |
261 else: | 265 else: |
262 # Default to VS2013. | 266 # Default to VS2013. |
263 return ['9ff97c632ae1fee0c98bcd53e71770eb3a0d8deb'] | 267 return ['9ff97c632ae1fee0c98bcd53e71770eb3a0d8deb'] |
264 | 268 |
265 | 269 |
270 def ShouldUpdateToolchain(): | |
271 """Check if the toolchain should be upgraded.""" | |
272 if not os.path.exists(json_data_file): | |
273 return True | |
274 with open(json_data_file, 'r') as tempf: | |
275 toolchain_data = json.load(tempf) | |
276 version = toolchain_data['version'] | |
277 env_version = os.environ.get('GYP_MSVS_VERSION', CURRENT_TOOLCHAIN_VERSION) | |
278 # If there's a mismatch between the version set in the environment and the one | |
279 # in the json file then the toolchain should be updated. | |
280 if version != env_version: | |
scottmg
2016/01/15 21:08:13
return version != env_version
Sébastien Marchand
2016/01/15 21:21:39
Done.
| |
281 return True | |
282 return False | |
283 | |
284 | |
266 def Update(force=False): | 285 def Update(force=False): |
267 """Requests an update of the toolchain to the specific hashes we have at | 286 """Requests an update of the toolchain to the specific hashes we have at |
268 this revision. The update outputs a .json of the various configuration | 287 this revision. The update outputs a .json of the various configuration |
269 information required to pass to gyp which we use in |GetToolchainDir()|. | 288 information required to pass to gyp which we use in |GetToolchainDir()|. |
270 """ | 289 """ |
271 if force != False and force != '--force': | 290 if force != False and force != '--force': |
272 print >>sys.stderr, 'Unknown parameter "%s"' % force | 291 print >>sys.stderr, 'Unknown parameter "%s"' % force |
273 return 1 | 292 return 1 |
274 if force == '--force' or os.path.exists(json_data_file): | 293 if force == '--force' or os.path.exists(json_data_file): |
275 force = True | 294 force = True |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 'copy_dlls': CopyDlls, | 344 'copy_dlls': CopyDlls, |
326 } | 345 } |
327 if len(sys.argv) < 2 or sys.argv[1] not in commands: | 346 if len(sys.argv) < 2 or sys.argv[1] not in commands: |
328 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) | 347 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) |
329 return 1 | 348 return 1 |
330 return commands[sys.argv[1]](*sys.argv[2:]) | 349 return commands[sys.argv[1]](*sys.argv[2:]) |
331 | 350 |
332 | 351 |
333 if __name__ == '__main__': | 352 if __name__ == '__main__': |
334 sys.exit(main()) | 353 sys.exit(main()) |
OLD | NEW |