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 |
| 6 import glob |
5 import json | 7 import json |
6 import os | 8 import os |
7 import pipes | 9 import pipes |
| 10 import platform |
8 import shutil | 11 import shutil |
| 12 import stat |
9 import subprocess | 13 import subprocess |
10 import sys | 14 import sys |
11 | 15 |
12 | 16 |
13 script_dir = os.path.dirname(os.path.realpath(__file__)) | 17 script_dir = os.path.dirname(os.path.realpath(__file__)) |
14 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir)) | 18 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir)) |
15 SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 19 SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
16 sys.path.insert(1, os.path.join(chrome_src, 'tools')) | 20 sys.path.insert(1, os.path.join(chrome_src, 'tools')) |
17 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib')) | 21 sys.path.insert(0, os.path.join(chrome_src, 'third_party', 'gyp', 'pylib')) |
18 json_data_file = os.path.join(script_dir, 'win_toolchain.json') | 22 json_data_file = os.path.join(script_dir, 'win_toolchain.json') |
19 | 23 |
20 | 24 |
21 import gyp | 25 import gyp |
22 | 26 |
23 | 27 |
| 28 # Use MSVS2015 as the default toolchain. |
| 29 CURRENT_DEFAULT_TOOLCHAIN_VERSION = '2015' |
| 30 |
| 31 |
24 def SetEnvironmentAndGetRuntimeDllDirs(): | 32 def SetEnvironmentAndGetRuntimeDllDirs(): |
25 """Sets up os.environ to use the depot_tools VS toolchain with gyp, and | 33 """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 | 34 returns the location of the VS runtime DLLs so they can be copied into |
27 the output directory after gyp generation. | 35 the output directory after gyp generation. |
| 36 |
| 37 Return value is [x64path, x86path] or None |
28 """ | 38 """ |
29 vs2013_runtime_dll_dirs = None | 39 vs_runtime_dll_dirs = None |
30 depot_tools_win_toolchain = \ | 40 depot_tools_win_toolchain = \ |
31 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) | 41 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) |
32 if sys.platform in ('win32', 'cygwin') and depot_tools_win_toolchain: | 42 # When running on a non-Windows host, only do this if the SDK has explicitly |
33 if not os.path.exists(json_data_file): | 43 # been downloaded before (in which case json_data_file will exist). |
| 44 if ((sys.platform in ('win32', 'cygwin') or os.path.exists(json_data_file)) |
| 45 and depot_tools_win_toolchain): |
| 46 if ShouldUpdateToolchain(): |
34 Update() | 47 Update() |
35 with open(json_data_file, 'r') as tempf: | 48 with open(json_data_file, 'r') as tempf: |
36 toolchain_data = json.load(tempf) | 49 toolchain_data = json.load(tempf) |
37 | 50 |
38 toolchain = toolchain_data['path'] | 51 toolchain = toolchain_data['path'] |
39 version = toolchain_data['version'] | 52 version = toolchain_data['version'] |
40 win_sdk = toolchain_data.get('win_sdk') | 53 win_sdk = toolchain_data.get('win_sdk') |
41 if not win_sdk: | 54 if not win_sdk: |
42 win_sdk = toolchain_data['win8sdk'] | 55 win_sdk = toolchain_data['win8sdk'] |
43 wdk = toolchain_data['wdk'] | 56 wdk = toolchain_data['wdk'] |
44 # TODO(scottmg): The order unfortunately matters in these. They should be | 57 # TODO(scottmg): The order unfortunately matters in these. They should be |
45 # split into separate keys for x86 and x64. (See CopyVsRuntimeDlls call | 58 # split into separate keys for x86 and x64. (See CopyVsRuntimeDlls call |
46 # below). http://crbug.com/345992 | 59 # below). http://crbug.com/345992 |
47 vs2013_runtime_dll_dirs = toolchain_data['runtime_dirs'] | 60 vs_runtime_dll_dirs = toolchain_data['runtime_dirs'] |
48 | 61 |
49 os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain | 62 os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain |
50 os.environ['GYP_MSVS_VERSION'] = version | 63 os.environ['GYP_MSVS_VERSION'] = version |
51 # We need to make sure windows_sdk_path is set to the automated | 64 # We need to make sure windows_sdk_path is set to the automated |
52 # toolchain values in GYP_DEFINES, but don't want to override any | 65 # toolchain values in GYP_DEFINES, but don't want to override any |
53 # otheroptions.express | 66 # otheroptions.express |
54 # values there. | 67 # values there. |
55 gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES')) | 68 gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES')) |
56 gyp_defines_dict['windows_sdk_path'] = win_sdk | 69 gyp_defines_dict['windows_sdk_path'] = win_sdk |
57 os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v))) | 70 os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v))) |
58 for k, v in gyp_defines_dict.iteritems()) | 71 for k, v in gyp_defines_dict.iteritems()) |
59 os.environ['WINDOWSSDKDIR'] = win_sdk | 72 os.environ['WINDOWSSDKDIR'] = win_sdk |
60 os.environ['WDK_DIR'] = wdk | 73 os.environ['WDK_DIR'] = wdk |
61 # Include the VS runtime in the PATH in case it's not machine-installed. | 74 # Include the VS runtime in the PATH in case it's not machine-installed. |
62 runtime_path = ';'.join(vs2013_runtime_dll_dirs) | 75 runtime_path = os.path.pathsep.join(vs_runtime_dll_dirs) |
63 os.environ['PATH'] = runtime_path + ';' + os.environ['PATH'] | 76 os.environ['PATH'] = runtime_path + os.path.pathsep + os.environ['PATH'] |
64 return vs2013_runtime_dll_dirs | 77 elif sys.platform == 'win32' and not depot_tools_win_toolchain: |
| 78 if not 'GYP_MSVS_OVERRIDE_PATH' in os.environ: |
| 79 os.environ['GYP_MSVS_OVERRIDE_PATH'] = DetectVisualStudioPath() |
| 80 if not 'GYP_MSVS_VERSION' in os.environ: |
| 81 os.environ['GYP_MSVS_VERSION'] = GetVisualStudioVersion() |
| 82 |
| 83 # When using an installed toolchain these files aren't needed in the output |
| 84 # directory in order to run binaries locally, but they are needed in order |
| 85 # to create isolates or the mini_installer. Copying them to the output |
| 86 # directory ensures that they are available when needed. |
| 87 bitness = platform.architecture()[0] |
| 88 # When running 64-bit python the x64 DLLs will be in System32 |
| 89 x64_path = 'System32' if bitness == '64bit' else 'Sysnative' |
| 90 x64_path = os.path.join(r'C:\Windows', x64_path) |
| 91 vs_runtime_dll_dirs = [x64_path, r'C:\Windows\SysWOW64'] |
| 92 |
| 93 return vs_runtime_dll_dirs |
| 94 |
| 95 |
| 96 def _RegistryGetValueUsingWinReg(key, value): |
| 97 """Use the _winreg module to obtain the value of a registry key. |
| 98 |
| 99 Args: |
| 100 key: The registry key. |
| 101 value: The particular registry value to read. |
| 102 Return: |
| 103 contents of the registry key's value, or None on failure. Throws |
| 104 ImportError if _winreg is unavailable. |
| 105 """ |
| 106 import _winreg |
| 107 try: |
| 108 root, subkey = key.split('\\', 1) |
| 109 assert root == 'HKLM' # Only need HKLM for now. |
| 110 with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, subkey) as hkey: |
| 111 return _winreg.QueryValueEx(hkey, value)[0] |
| 112 except WindowsError: |
| 113 return None |
| 114 |
| 115 |
| 116 def _RegistryGetValue(key, value): |
| 117 try: |
| 118 return _RegistryGetValueUsingWinReg(key, value) |
| 119 except ImportError: |
| 120 raise Exception('The python library _winreg not found.') |
| 121 |
| 122 |
| 123 def GetVisualStudioVersion(): |
| 124 """Return GYP_MSVS_VERSION of Visual Studio. |
| 125 """ |
| 126 return os.environ.get('GYP_MSVS_VERSION', CURRENT_DEFAULT_TOOLCHAIN_VERSION) |
| 127 |
| 128 |
| 129 def DetectVisualStudioPath(): |
| 130 """Return path to the GYP_MSVS_VERSION of Visual Studio. |
| 131 """ |
| 132 |
| 133 # Note that this code is used from |
| 134 # build/toolchain/win/setup_toolchain.py as well. |
| 135 version_as_year = GetVisualStudioVersion() |
| 136 year_to_version = { |
| 137 '2013': '12.0', |
| 138 '2015': '14.0', |
| 139 } |
| 140 if version_as_year not in year_to_version: |
| 141 raise Exception(('Visual Studio version %s (from GYP_MSVS_VERSION)' |
| 142 ' not supported. Supported versions are: %s') % ( |
| 143 version_as_year, ', '.join(year_to_version.keys()))) |
| 144 version = year_to_version[version_as_year] |
| 145 keys = [r'HKLM\Software\Microsoft\VisualStudio\%s' % version, |
| 146 r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\%s' % version] |
| 147 for key in keys: |
| 148 path = _RegistryGetValue(key, 'InstallDir') |
| 149 if not path: |
| 150 continue |
| 151 path = os.path.normpath(os.path.join(path, '..', '..')) |
| 152 return path |
| 153 |
| 154 raise Exception(('Visual Studio Version %s (from GYP_MSVS_VERSION)' |
| 155 ' not found.') % (version_as_year)) |
65 | 156 |
66 | 157 |
67 def _VersionNumber(): | 158 def _VersionNumber(): |
68 """Gets the standard version number ('120', '140', etc.) based on | 159 """Gets the standard version number ('120', '140', etc.) based on |
69 GYP_MSVS_VERSION.""" | 160 GYP_MSVS_VERSION.""" |
70 if os.environ['GYP_MSVS_VERSION'] == '2013': | 161 vs_version = GetVisualStudioVersion() |
| 162 if vs_version == '2013': |
71 return '120' | 163 return '120' |
72 elif os.environ['GYP_MSVS_VERSION'] == '2015': | 164 elif vs_version == '2015': |
73 return '140' | 165 return '140' |
74 else: | 166 else: |
75 raise ValueError('Unexpected GYP_MSVS_VERSION') | 167 raise ValueError('Unexpected GYP_MSVS_VERSION') |
76 | 168 |
77 | 169 |
78 def _CopyRuntimeImpl(target, source): | 170 def _CopyRuntimeImpl(target, source, verbose=True): |
79 """Copy |source| to |target| if it doesn't already exist or if it | 171 """Copy |source| to |target| if it doesn't already exist or if it needs to be |
80 needs to be updated. | 172 updated (comparing last modified time as an approximate float match as for |
| 173 some reason the values tend to differ by ~1e-07 despite being copies of the |
| 174 same file... https://crbug.com/603603). |
81 """ | 175 """ |
82 if (os.path.isdir(os.path.dirname(target)) and | 176 if (os.path.isdir(os.path.dirname(target)) and |
83 (not os.path.isfile(target) or | 177 (not os.path.isfile(target) or |
84 os.stat(target).st_mtime != os.stat(source).st_mtime)): | 178 abs(os.stat(target).st_mtime - os.stat(source).st_mtime) >= 0.01)): |
85 print 'Copying %s to %s...' % (source, target) | 179 if verbose: |
| 180 print 'Copying %s to %s...' % (source, target) |
86 if os.path.exists(target): | 181 if os.path.exists(target): |
| 182 # Make the file writable so that we can delete it now. |
| 183 os.chmod(target, stat.S_IWRITE) |
87 os.unlink(target) | 184 os.unlink(target) |
88 shutil.copy2(source, target) | 185 shutil.copy2(source, target) |
| 186 # Make the file writable so that we can overwrite or delete it later. |
| 187 os.chmod(target, stat.S_IWRITE) |
89 | 188 |
90 | 189 |
91 def _CopyRuntime2013(target_dir, source_dir, dll_pattern): | 190 def _CopyRuntime2013(target_dir, source_dir, dll_pattern): |
92 """Copy both the msvcr and msvcp runtime DLLs, only if the target doesn't | 191 """Copy both the msvcr and msvcp runtime DLLs, only if the target doesn't |
93 exist, but the target directory does exist.""" | 192 exist, but the target directory does exist.""" |
94 for file_part in ('p', 'r'): | 193 for file_part in ('p', 'r'): |
95 dll = dll_pattern % file_part | 194 dll = dll_pattern % file_part |
96 target = os.path.join(target_dir, dll) | 195 target = os.path.join(target_dir, dll) |
97 source = os.path.join(source_dir, dll) | 196 source = os.path.join(source_dir, dll) |
98 _CopyRuntimeImpl(target, source) | 197 _CopyRuntimeImpl(target, source) |
99 | 198 |
100 | 199 |
101 def _CopyRuntime2015(target_dir, source_dir, dll_pattern): | 200 def _CopyRuntime2015(target_dir, source_dir, dll_pattern, suffix): |
102 """Copy both the msvcp and vccorlib runtime DLLs, only if the target doesn't | 201 """Copy both the msvcp and vccorlib runtime DLLs, only if the target doesn't |
103 exist, but the target directory does exist.""" | 202 exist, but the target directory does exist.""" |
104 for file_part in ('msvcp', 'vccorlib'): | 203 for file_part in ('msvcp', 'vccorlib', 'vcruntime'): |
105 dll = dll_pattern % file_part | 204 dll = dll_pattern % file_part |
106 target = os.path.join(target_dir, dll) | 205 target = os.path.join(target_dir, dll) |
107 source = os.path.join(source_dir, dll) | 206 source = os.path.join(source_dir, dll) |
108 _CopyRuntimeImpl(target, source) | 207 _CopyRuntimeImpl(target, source) |
| 208 # OS installs of Visual Studio (and all installs of Windows 10) put the |
| 209 # universal CRT files in c:\Windows\System32\downlevel - look for them there |
| 210 # to support DEPOT_TOOLS_WIN_TOOLCHAIN=0. |
| 211 if os.path.exists(os.path.join(source_dir, 'downlevel')): |
| 212 ucrt_src_glob = os.path.join(source_dir, 'downlevel', 'api-ms-win-*.dll') |
| 213 else: |
| 214 ucrt_src_glob = os.path.join(source_dir, 'api-ms-win-*.dll') |
| 215 ucrt_files = glob.glob(ucrt_src_glob) |
| 216 assert len(ucrt_files) > 0 |
| 217 for ucrt_src_file in ucrt_files: |
| 218 file_part = os.path.basename(ucrt_src_file) |
| 219 ucrt_dst_file = os.path.join(target_dir, file_part) |
| 220 _CopyRuntimeImpl(ucrt_dst_file, ucrt_src_file, False) |
| 221 _CopyRuntimeImpl(os.path.join(target_dir, 'ucrtbase' + suffix), |
| 222 os.path.join(source_dir, 'ucrtbase' + suffix)) |
| 223 |
| 224 |
| 225 def _CopyRuntime(target_dir, source_dir, target_cpu, debug): |
| 226 """Copy the VS runtime DLLs, only if the target doesn't exist, but the target |
| 227 directory does exist. Handles VS 2013 and VS 2015.""" |
| 228 suffix = "d.dll" if debug else ".dll" |
| 229 if GetVisualStudioVersion() == '2015': |
| 230 _CopyRuntime2015(target_dir, source_dir, '%s140' + suffix, suffix) |
| 231 else: |
| 232 _CopyRuntime2013(target_dir, source_dir, 'msvc%s120' + suffix) |
| 233 |
| 234 # Copy the PGO runtime library to the release directories. |
| 235 if not debug and os.environ.get('GYP_MSVS_OVERRIDE_PATH'): |
| 236 pgo_x86_runtime_dir = os.path.join(os.environ.get('GYP_MSVS_OVERRIDE_PATH'), |
| 237 'VC', 'bin') |
| 238 pgo_x64_runtime_dir = os.path.join(pgo_x86_runtime_dir, 'amd64') |
| 239 pgo_runtime_dll = 'pgort' + _VersionNumber() + '.dll' |
| 240 if target_cpu == "x86": |
| 241 source_x86 = os.path.join(pgo_x86_runtime_dir, pgo_runtime_dll) |
| 242 if os.path.exists(source_x86): |
| 243 _CopyRuntimeImpl(os.path.join(target_dir, pgo_runtime_dll), source_x86) |
| 244 elif target_cpu == "x64": |
| 245 source_x64 = os.path.join(pgo_x64_runtime_dir, pgo_runtime_dll) |
| 246 if os.path.exists(source_x64): |
| 247 _CopyRuntimeImpl(os.path.join(target_dir, pgo_runtime_dll), |
| 248 source_x64) |
| 249 else: |
| 250 raise NotImplementedError("Unexpected target_cpu value:" + target_cpu) |
109 | 251 |
110 | 252 |
111 def CopyVsRuntimeDlls(output_dir, runtime_dirs): | 253 def CopyVsRuntimeDlls(output_dir, runtime_dirs): |
112 """Copies the VS runtime DLLs from the given |runtime_dirs| to the output | 254 """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 | 255 directory so that even if not system-installed, built binaries are likely to |
114 be able to run. | 256 be able to run. |
115 | 257 |
116 This needs to be run after gyp has been run so that the expected target | 258 This needs to be run after gyp has been run so that the expected target |
117 output directories are already created. | 259 output directories are already created. |
| 260 |
| 261 This is used for the GYP build and gclient runhooks. |
118 """ | 262 """ |
119 assert sys.platform.startswith(('win32', 'cygwin')) | |
120 | |
121 x86, x64 = runtime_dirs | 263 x86, x64 = runtime_dirs |
122 out_debug = os.path.join(output_dir, 'Debug') | 264 out_debug = os.path.join(output_dir, 'Debug') |
123 out_debug_nacl64 = os.path.join(output_dir, 'Debug', 'x64') | 265 out_debug_nacl64 = os.path.join(output_dir, 'Debug', 'x64') |
124 out_release = os.path.join(output_dir, 'Release') | 266 out_release = os.path.join(output_dir, 'Release') |
125 out_release_nacl64 = os.path.join(output_dir, 'Release', 'x64') | 267 out_release_nacl64 = os.path.join(output_dir, 'Release', 'x64') |
126 out_debug_x64 = os.path.join(output_dir, 'Debug_x64') | 268 out_debug_x64 = os.path.join(output_dir, 'Debug_x64') |
127 out_release_x64 = os.path.join(output_dir, 'Release_x64') | 269 out_release_x64 = os.path.join(output_dir, 'Release_x64') |
128 | 270 |
129 if os.path.exists(out_debug) and not os.path.exists(out_debug_nacl64): | 271 if os.path.exists(out_debug) and not os.path.exists(out_debug_nacl64): |
130 os.makedirs(out_debug_nacl64) | 272 os.makedirs(out_debug_nacl64) |
131 if os.path.exists(out_release) and not os.path.exists(out_release_nacl64): | 273 if os.path.exists(out_release) and not os.path.exists(out_release_nacl64): |
132 os.makedirs(out_release_nacl64) | 274 os.makedirs(out_release_nacl64) |
133 if os.environ.get('GYP_MSVS_VERSION') == '2015': | 275 _CopyRuntime(out_debug, x86, "x86", debug=True) |
134 _CopyRuntime2015(out_debug, x86, '%s140d.dll') | 276 _CopyRuntime(out_release, x86, "x86", debug=False) |
135 _CopyRuntime2015(out_release, x86, '%s140.dll') | 277 _CopyRuntime(out_debug_x64, x64, "x64", debug=True) |
136 _CopyRuntime2015(out_debug_x64, x64, '%s140d.dll') | 278 _CopyRuntime(out_release_x64, x64, "x64", debug=False) |
137 _CopyRuntime2015(out_release_x64, x64, '%s140.dll') | 279 _CopyRuntime(out_debug_nacl64, x64, "x64", debug=True) |
138 _CopyRuntime2015(out_debug_nacl64, x64, '%s140d.dll') | 280 _CopyRuntime(out_release_nacl64, x64, "x64", debug=False) |
139 _CopyRuntime2015(out_release_nacl64, x64, '%s140.dll') | |
140 else: | |
141 # VS2013 is the default. | |
142 _CopyRuntime2013(out_debug, x86, 'msvc%s120d.dll') | |
143 _CopyRuntime2013(out_release, x86, 'msvc%s120.dll') | |
144 _CopyRuntime2013(out_debug_x64, x64, 'msvc%s120d.dll') | |
145 _CopyRuntime2013(out_release_x64, x64, 'msvc%s120.dll') | |
146 _CopyRuntime2013(out_debug_nacl64, x64, 'msvc%s120d.dll') | |
147 _CopyRuntime2013(out_release_nacl64, x64, 'msvc%s120.dll') | |
148 | |
149 # Copy the PGO runtime library to the release directories. | |
150 if os.environ.get('GYP_MSVS_OVERRIDE_PATH'): | |
151 pgo_x86_runtime_dir = os.path.join(os.environ.get('GYP_MSVS_OVERRIDE_PATH'), | |
152 'VC', 'bin') | |
153 pgo_x64_runtime_dir = os.path.join(pgo_x86_runtime_dir, 'amd64') | |
154 pgo_runtime_dll = 'pgort' + _VersionNumber() + '.dll' | |
155 source_x86 = os.path.join(pgo_x86_runtime_dir, pgo_runtime_dll) | |
156 if os.path.exists(source_x86): | |
157 _CopyRuntimeImpl(os.path.join(out_release, pgo_runtime_dll), source_x86) | |
158 source_x64 = os.path.join(pgo_x64_runtime_dir, pgo_runtime_dll) | |
159 if os.path.exists(source_x64): | |
160 _CopyRuntimeImpl(os.path.join(out_release_x64, pgo_runtime_dll), | |
161 source_x64) | |
162 | 281 |
163 | 282 |
164 def CopyDlls(target_dir, configuration, target_cpu): | 283 def CopyDlls(target_dir, configuration, target_cpu): |
165 """Copy the VS runtime DLLs into the requested directory as needed. | 284 """Copy the VS runtime DLLs into the requested directory as needed. |
166 | 285 |
167 configuration is one of 'Debug' or 'Release'. | 286 configuration is one of 'Debug' or 'Release'. |
168 target_cpu is one of 'x86' or 'x64'. | 287 target_cpu is one of 'x86' or 'x64'. |
169 | 288 |
170 The debug configuration gets both the debug and release DLLs; the | 289 The debug configuration gets both the debug and release DLLs; the |
171 release config only the latter. | 290 release config only the latter. |
| 291 |
| 292 This is used for the GN build. |
172 """ | 293 """ |
173 vs2013_runtime_dll_dirs = SetEnvironmentAndGetRuntimeDllDirs() | 294 vs_runtime_dll_dirs = SetEnvironmentAndGetRuntimeDllDirs() |
174 if not vs2013_runtime_dll_dirs: | 295 if not vs_runtime_dll_dirs: |
175 return | 296 return |
176 | 297 |
177 x64_runtime, x86_runtime = vs2013_runtime_dll_dirs | 298 x64_runtime, x86_runtime = vs_runtime_dll_dirs |
178 runtime_dir = x64_runtime if target_cpu == 'x64' else x86_runtime | 299 runtime_dir = x64_runtime if target_cpu == 'x64' else x86_runtime |
179 _CopyRuntime2013( | 300 _CopyRuntime(target_dir, runtime_dir, target_cpu, debug=False) |
180 target_dir, runtime_dir, 'msvc%s' + _VersionNumber() + '.dll') | |
181 if configuration == 'Debug': | 301 if configuration == 'Debug': |
182 _CopyRuntime2013( | 302 _CopyRuntime(target_dir, runtime_dir, target_cpu, debug=True) |
183 target_dir, runtime_dir, 'msvc%s' + _VersionNumber() + 'd.dll') | |
184 | 303 |
185 | 304 |
186 def _GetDesiredVsToolchainHashes(): | 305 def _GetDesiredVsToolchainHashes(): |
187 """Load a list of SHA1s corresponding to the toolchains that we want installed | 306 """Load a list of SHA1s corresponding to the toolchains that we want installed |
188 to build with.""" | 307 to build with.""" |
189 # TODO(scottmg): If explicitly set to VS2015 override hashes to the VS2015 RC | 308 if GetVisualStudioVersion() == '2015': |
190 # toolchain. http://crbug.com/492774. | 309 # Update 3 final with patches with 10.0.10586.0 SDK. |
191 if os.environ.get('GYP_MSVS_VERSION') == '2015': | 310 return ['d5dc33b15d1b2c086f2f6632e2fd15882f80dbd3'] |
192 return ['40721575c85171cea5d7afe5ec17bd108a94796e'] | |
193 else: | 311 else: |
194 # Default to VS2013. | 312 return ['03a4e939cd325d6bc5216af41b92d02dda1366a6'] |
195 return ['ee7d718ec60c2dc5d255bbe325909c2021a7efef'] | |
196 | 313 |
197 | 314 |
198 def Update(): | 315 def ShouldUpdateToolchain(): |
| 316 """Check if the toolchain should be upgraded.""" |
| 317 if not os.path.exists(json_data_file): |
| 318 return True |
| 319 with open(json_data_file, 'r') as tempf: |
| 320 toolchain_data = json.load(tempf) |
| 321 version = toolchain_data['version'] |
| 322 env_version = GetVisualStudioVersion() |
| 323 # If there's a mismatch between the version set in the environment and the one |
| 324 # in the json file then the toolchain should be updated. |
| 325 return version != env_version |
| 326 |
| 327 |
| 328 def Update(force=False): |
199 """Requests an update of the toolchain to the specific hashes we have at | 329 """Requests an update of the toolchain to the specific hashes we have at |
200 this revision. The update outputs a .json of the various configuration | 330 this revision. The update outputs a .json of the various configuration |
201 information required to pass to gyp which we use in |GetToolchainDir()|. | 331 information required to pass to gyp which we use in |GetToolchainDir()|. |
202 """ | 332 """ |
| 333 if force != False and force != '--force': |
| 334 print >>sys.stderr, 'Unknown parameter "%s"' % force |
| 335 return 1 |
| 336 if force == '--force' or os.path.exists(json_data_file): |
| 337 force = True |
| 338 |
203 depot_tools_win_toolchain = \ | 339 depot_tools_win_toolchain = \ |
204 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) | 340 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) |
205 if sys.platform in ('win32', 'cygwin') and depot_tools_win_toolchain: | 341 if ((sys.platform in ('win32', 'cygwin') or force) and |
| 342 depot_tools_win_toolchain): |
206 import find_depot_tools | 343 import find_depot_tools |
207 depot_tools_path = find_depot_tools.add_depot_tools_to_path() | 344 depot_tools_path = find_depot_tools.add_depot_tools_to_path() |
| 345 # Necessary so that get_toolchain_if_necessary.py will put the VS toolkit |
| 346 # in the correct directory. |
| 347 os.environ['GYP_MSVS_VERSION'] = GetVisualStudioVersion() |
208 get_toolchain_args = [ | 348 get_toolchain_args = [ |
209 sys.executable, | 349 sys.executable, |
210 os.path.join(depot_tools_path, | 350 os.path.join(depot_tools_path, |
211 'win_toolchain', | 351 'win_toolchain', |
212 'get_toolchain_if_necessary.py'), | 352 'get_toolchain_if_necessary.py'), |
213 '--output-json', json_data_file, | 353 '--output-json', json_data_file, |
214 ] + _GetDesiredVsToolchainHashes() | 354 ] + _GetDesiredVsToolchainHashes() |
| 355 if force: |
| 356 get_toolchain_args.append('--force') |
215 subprocess.check_call(get_toolchain_args) | 357 subprocess.check_call(get_toolchain_args) |
216 | 358 |
217 return 0 | 359 return 0 |
218 | 360 |
219 | 361 |
| 362 def NormalizePath(path): |
| 363 while path.endswith("\\"): |
| 364 path = path[:-1] |
| 365 return path |
| 366 |
| 367 |
220 def GetToolchainDir(): | 368 def GetToolchainDir(): |
221 """Gets location information about the current toolchain (must have been | 369 """Gets location information about the current toolchain (must have been |
222 previously updated by 'update'). This is used for the GN build.""" | 370 previously updated by 'update'). This is used for the GN build.""" |
223 runtime_dll_dirs = SetEnvironmentAndGetRuntimeDllDirs() | 371 runtime_dll_dirs = SetEnvironmentAndGetRuntimeDllDirs() |
224 | 372 |
225 # If WINDOWSSDKDIR is not set, search the default SDK path and set it. | 373 # If WINDOWSSDKDIR is not set, search the default SDK path and set it. |
226 if not 'WINDOWSSDKDIR' in os.environ: | 374 if not 'WINDOWSSDKDIR' in os.environ: |
227 default_sdk_path = 'C:\\Program Files (x86)\\Windows Kits\\8.1' | 375 default_sdk_path = 'C:\\Program Files (x86)\\Windows Kits\\10' |
228 if os.path.isdir(default_sdk_path): | 376 if os.path.isdir(default_sdk_path): |
229 os.environ['WINDOWSSDKDIR'] = default_sdk_path | 377 os.environ['WINDOWSSDKDIR'] = default_sdk_path |
230 | 378 |
231 print '''vs_path = "%s" | 379 print '''vs_path = "%s" |
232 sdk_path = "%s" | 380 sdk_path = "%s" |
233 vs_version = "%s" | 381 vs_version = "%s" |
234 wdk_dir = "%s" | 382 wdk_dir = "%s" |
235 runtime_dirs = "%s" | 383 runtime_dirs = "%s" |
236 ''' % ( | 384 ''' % ( |
237 os.environ['GYP_MSVS_OVERRIDE_PATH'], | 385 NormalizePath(os.environ['GYP_MSVS_OVERRIDE_PATH']), |
238 os.environ['WINDOWSSDKDIR'], | 386 NormalizePath(os.environ['WINDOWSSDKDIR']), |
239 os.environ['GYP_MSVS_VERSION'], | 387 GetVisualStudioVersion(), |
240 os.environ.get('WDK_DIR', ''), | 388 NormalizePath(os.environ.get('WDK_DIR', '')), |
241 ';'.join(runtime_dll_dirs or ['None'])) | 389 os.path.pathsep.join(runtime_dll_dirs or ['None'])) |
242 | 390 |
243 | 391 |
244 def main(): | 392 def main(): |
245 if not sys.platform.startswith(('win32', 'cygwin')): | |
246 return 0 | |
247 commands = { | 393 commands = { |
248 'update': Update, | 394 'update': Update, |
249 'get_toolchain_dir': GetToolchainDir, | 395 'get_toolchain_dir': GetToolchainDir, |
250 'copy_dlls': CopyDlls, | 396 'copy_dlls': CopyDlls, |
251 } | 397 } |
252 if len(sys.argv) < 2 or sys.argv[1] not in commands: | 398 if len(sys.argv) < 2 or sys.argv[1] not in commands: |
253 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) | 399 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) |
254 return 1 | 400 return 1 |
255 return commands[sys.argv[1]](*sys.argv[2:]) | 401 return commands[sys.argv[1]](*sys.argv[2:]) |
256 | 402 |
257 | 403 |
258 if __name__ == '__main__': | 404 if __name__ == '__main__': |
259 sys.exit(main()) | 405 sys.exit(main()) |
OLD | NEW |