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 glob | 6 import glob |
7 import json | 7 import json |
8 import os | 8 import os |
9 import pipes | 9 import pipes |
10 import platform | 10 import platform |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 130 |
131 | 131 |
132 def DetectVisualStudioPath(): | 132 def DetectVisualStudioPath(): |
133 """Return path to the GYP_MSVS_VERSION of Visual Studio. | 133 """Return path to the GYP_MSVS_VERSION of Visual Studio. |
134 """ | 134 """ |
135 | 135 |
136 # Note that this code is used from | 136 # Note that this code is used from |
137 # build/toolchain/win/setup_toolchain.py as well. | 137 # build/toolchain/win/setup_toolchain.py as well. |
138 version_as_year = GetVisualStudioVersion() | 138 version_as_year = GetVisualStudioVersion() |
139 year_to_version = { | 139 year_to_version = { |
140 '2013': '12.0', | |
141 '2015': '14.0', | 140 '2015': '14.0', |
142 '2017': '15.0', | 141 '2017': '15.0', |
143 } | 142 } |
144 if version_as_year not in year_to_version: | 143 if version_as_year not in year_to_version: |
145 raise Exception(('Visual Studio version %s (from GYP_MSVS_VERSION)' | 144 raise Exception(('Visual Studio version %s (from GYP_MSVS_VERSION)' |
146 ' not supported. Supported versions are: %s') % ( | 145 ' not supported. Supported versions are: %s') % ( |
147 version_as_year, ', '.join(year_to_version.keys()))) | 146 version_as_year, ', '.join(year_to_version.keys()))) |
148 version = year_to_version[version_as_year] | 147 version = year_to_version[version_as_year] |
149 if version_as_year == '2017': | 148 if version_as_year == '2017': |
150 # The VC++ 2017 install location needs to be located using COM instead of | 149 # The VC++ 2017 install location needs to be located using COM instead of |
(...skipping 15 matching lines...) Expand all Loading... |
166 return path | 165 return path |
167 | 166 |
168 raise Exception(('Visual Studio Version %s (from GYP_MSVS_VERSION)' | 167 raise Exception(('Visual Studio Version %s (from GYP_MSVS_VERSION)' |
169 ' not found.') % (version_as_year)) | 168 ' not found.') % (version_as_year)) |
170 | 169 |
171 | 170 |
172 def _VersionNumber(): | 171 def _VersionNumber(): |
173 """Gets the standard version number ('120', '140', etc.) based on | 172 """Gets the standard version number ('120', '140', etc.) based on |
174 GYP_MSVS_VERSION.""" | 173 GYP_MSVS_VERSION.""" |
175 vs_version = GetVisualStudioVersion() | 174 vs_version = GetVisualStudioVersion() |
176 if vs_version == '2013': | |
177 return '120' | |
178 if vs_version == '2015': | 175 if vs_version == '2015': |
179 return '140' | 176 return '140' |
180 if vs_version == '2017': | 177 if vs_version == '2017': |
181 return '150' | 178 return '150' |
182 raise ValueError('Unexpected GYP_MSVS_VERSION') | 179 raise ValueError('Unexpected GYP_MSVS_VERSION') |
183 | 180 |
184 | 181 |
185 def _CopyRuntimeImpl(target, source, verbose=True): | 182 def _CopyRuntimeImpl(target, source, verbose=True): |
186 """Copy |source| to |target| if it doesn't already exist or if it needs to be | 183 """Copy |source| to |target| if it doesn't already exist or if it needs to be |
187 updated (comparing last modified time as an approximate float match as for | 184 updated (comparing last modified time as an approximate float match as for |
188 some reason the values tend to differ by ~1e-07 despite being copies of the | 185 some reason the values tend to differ by ~1e-07 despite being copies of the |
189 same file... https://crbug.com/603603). | 186 same file... https://crbug.com/603603). |
190 """ | 187 """ |
191 if (os.path.isdir(os.path.dirname(target)) and | 188 if (os.path.isdir(os.path.dirname(target)) and |
192 (not os.path.isfile(target) or | 189 (not os.path.isfile(target) or |
193 abs(os.stat(target).st_mtime - os.stat(source).st_mtime) >= 0.01)): | 190 abs(os.stat(target).st_mtime - os.stat(source).st_mtime) >= 0.01)): |
194 if verbose: | 191 if verbose: |
195 print 'Copying %s to %s...' % (source, target) | 192 print 'Copying %s to %s...' % (source, target) |
196 if os.path.exists(target): | 193 if os.path.exists(target): |
197 # Make the file writable so that we can delete it now. | 194 # Make the file writable so that we can delete it now. |
198 os.chmod(target, stat.S_IWRITE) | 195 os.chmod(target, stat.S_IWRITE) |
199 os.unlink(target) | 196 os.unlink(target) |
200 shutil.copy2(source, target) | 197 shutil.copy2(source, target) |
201 # Make the file writable so that we can overwrite or delete it later. | 198 # Make the file writable so that we can overwrite or delete it later. |
202 os.chmod(target, stat.S_IWRITE) | 199 os.chmod(target, stat.S_IWRITE) |
203 | 200 |
204 | 201 |
205 def _CopyRuntime2013(target_dir, source_dir, dll_pattern): | |
206 """Copy both the msvcr and msvcp runtime DLLs, only if the target doesn't | |
207 exist, but the target directory does exist.""" | |
208 for file_part in ('p', 'r'): | |
209 dll = dll_pattern % file_part | |
210 target = os.path.join(target_dir, dll) | |
211 source = os.path.join(source_dir, dll) | |
212 _CopyRuntimeImpl(target, source) | |
213 | |
214 | |
215 def _CopyUCRTRuntime(target_dir, source_dir, target_cpu, dll_pattern, suffix): | 202 def _CopyUCRTRuntime(target_dir, source_dir, target_cpu, dll_pattern, suffix): |
216 """Copy both the msvcp and vccorlib runtime DLLs, only if the target doesn't | 203 """Copy both the msvcp and vccorlib runtime DLLs, only if the target doesn't |
217 exist, but the target directory does exist.""" | 204 exist, but the target directory does exist.""" |
218 for file_part in ('msvcp', 'vccorlib', 'vcruntime'): | 205 for file_part in ('msvcp', 'vccorlib', 'vcruntime'): |
219 dll = dll_pattern % file_part | 206 dll = dll_pattern % file_part |
220 target = os.path.join(target_dir, dll) | 207 target = os.path.join(target_dir, dll) |
221 source = os.path.join(source_dir, dll) | 208 source = os.path.join(source_dir, dll) |
222 _CopyRuntimeImpl(target, source) | 209 _CopyRuntimeImpl(target, source) |
223 # Copy the UCRT files needed by VS 2015 from the Windows SDK. This location | 210 # Copy the UCRT files needed by VS 2015 from the Windows SDK. This location |
224 # includes the api-ms-win-crt-*.dll files that are not found in the Windows | 211 # includes the api-ms-win-crt-*.dll files that are not found in the Windows |
225 # directory. These files are needed for component builds. | 212 # directory. These files are needed for component builds. |
226 # If WINDOWSSDKDIR is not set use the default SDK path. This will be the case | 213 # If WINDOWSSDKDIR is not set use the default SDK path. This will be the case |
227 # when DEPOT_TOOLS_WIN_TOOLCHAIN=0 and vcvarsall.bat has not been run. | 214 # when DEPOT_TOOLS_WIN_TOOLCHAIN=0 and vcvarsall.bat has not been run. |
228 win_sdk_dir = os.path.normpath( | 215 win_sdk_dir = os.path.normpath( |
229 os.environ.get('WINDOWSSDKDIR', | 216 os.environ.get('WINDOWSSDKDIR', |
230 'C:\\Program Files (x86)\\Windows Kits\\10')) | 217 'C:\\Program Files (x86)\\Windows Kits\\10')) |
231 ucrt_dll_dirs = os.path.join(win_sdk_dir, r'Redist\ucrt\DLLs', target_cpu) | 218 ucrt_dll_dirs = os.path.join(win_sdk_dir, r'Redist\ucrt\DLLs', target_cpu) |
232 ucrt_files = glob.glob(os.path.join(ucrt_dll_dirs, 'api-ms-win-*.dll')) | 219 ucrt_files = glob.glob(os.path.join(ucrt_dll_dirs, 'api-ms-win-*.dll')) |
233 assert len(ucrt_files) > 0 | 220 assert len(ucrt_files) > 0 |
234 for ucrt_src_file in ucrt_files: | 221 for ucrt_src_file in ucrt_files: |
235 file_part = os.path.basename(ucrt_src_file) | 222 file_part = os.path.basename(ucrt_src_file) |
236 ucrt_dst_file = os.path.join(target_dir, file_part) | 223 ucrt_dst_file = os.path.join(target_dir, file_part) |
237 _CopyRuntimeImpl(ucrt_dst_file, ucrt_src_file, False) | 224 _CopyRuntimeImpl(ucrt_dst_file, ucrt_src_file, False) |
238 _CopyRuntimeImpl(os.path.join(target_dir, 'ucrtbase' + suffix), | 225 _CopyRuntimeImpl(os.path.join(target_dir, 'ucrtbase' + suffix), |
239 os.path.join(source_dir, 'ucrtbase' + suffix)) | 226 os.path.join(source_dir, 'ucrtbase' + suffix)) |
240 | 227 |
241 | 228 |
242 def _CopyRuntime(target_dir, source_dir, target_cpu, debug): | 229 def _CopyRuntime(target_dir, source_dir, target_cpu, debug): |
243 """Copy the VS runtime DLLs, only if the target doesn't exist, but the target | 230 """Copy the VS runtime DLLs, only if the target doesn't exist, but the target |
244 directory does exist. Handles VS 2013, VS 2015, and VS 2017.""" | 231 directory does exist. Handles VS 2015 and VS 2017.""" |
245 suffix = "d.dll" if debug else ".dll" | 232 suffix = "d.dll" if debug else ".dll" |
246 if GetVisualStudioVersion() in ['2015', '2017']: | 233 # VS 2017 uses the same CRT DLLs as VS 2015. |
247 # VS 2017 uses the same CRT DLLs as VS 2015. | 234 _CopyUCRTRuntime(target_dir, source_dir, target_cpu, '%s140' + suffix, |
248 _CopyUCRTRuntime(target_dir, source_dir, target_cpu, '%s140' + suffix, | 235 suffix) |
249 suffix) | |
250 else: | |
251 _CopyRuntime2013(target_dir, source_dir, 'msvc%s120' + suffix) | |
252 | 236 |
253 # Copy the PGO runtime library to the release directories. | 237 # Copy the PGO runtime library to the release directories. |
254 if not debug and os.environ.get('GYP_MSVS_OVERRIDE_PATH'): | 238 if not debug and os.environ.get('GYP_MSVS_OVERRIDE_PATH'): |
255 pgo_x86_runtime_dir = os.path.join(os.environ.get('GYP_MSVS_OVERRIDE_PATH'), | 239 pgo_x86_runtime_dir = os.path.join(os.environ.get('GYP_MSVS_OVERRIDE_PATH'), |
256 'VC', 'bin') | 240 'VC', 'bin') |
257 pgo_x64_runtime_dir = os.path.join(pgo_x86_runtime_dir, 'amd64') | 241 pgo_x64_runtime_dir = os.path.join(pgo_x86_runtime_dir, 'amd64') |
258 pgo_runtime_dll = 'pgort' + _VersionNumber() + '.dll' | 242 pgo_runtime_dll = 'pgort' + _VersionNumber() + '.dll' |
259 if target_cpu == "x86": | 243 if target_cpu == "x86": |
260 source_x86 = os.path.join(pgo_x86_runtime_dir, pgo_runtime_dll) | 244 source_x86 = os.path.join(pgo_x86_runtime_dir, pgo_runtime_dll) |
261 if os.path.exists(source_x86): | 245 if os.path.exists(source_x86): |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 for debug_file in debugger_files: | 324 for debug_file in debugger_files: |
341 full_path = os.path.join(win_sdk_dir, 'Debuggers', target_cpu, debug_file) | 325 full_path = os.path.join(win_sdk_dir, 'Debuggers', target_cpu, debug_file) |
342 target_path = os.path.join(target_dir, debug_file) | 326 target_path = os.path.join(target_dir, debug_file) |
343 _CopyRuntimeImpl(target_path, full_path) | 327 _CopyRuntimeImpl(target_path, full_path) |
344 | 328 |
345 | 329 |
346 def _GetDesiredVsToolchainHashes(): | 330 def _GetDesiredVsToolchainHashes(): |
347 """Load a list of SHA1s corresponding to the toolchains that we want installed | 331 """Load a list of SHA1s corresponding to the toolchains that we want installed |
348 to build with.""" | 332 to build with.""" |
349 env_version = GetVisualStudioVersion() | 333 env_version = GetVisualStudioVersion() |
350 if env_version == '2013': | |
351 return ['03a4e939cd325d6bc5216af41b92d02dda1366a6'] | |
352 if env_version == '2015': | 334 if env_version == '2015': |
353 # Update 3 final with patches with 10.0.14393.0 SDK. | 335 # Update 3 final with patches with 10.0.14393.0 SDK. |
354 return ['d3cb0e37bdd120ad0ac4650b674b09e81be45616'] | 336 return ['d3cb0e37bdd120ad0ac4650b674b09e81be45616'] |
355 if env_version == '2017': | 337 if env_version == '2017': |
356 # VS 2017 RTM with 10.0.14393.0 SDK. | 338 # VS 2017 RTM with 10.0.14393.0 SDK. |
357 return ['716b3fda0f857c3dc24d795d1a4d74e1e740face'] | 339 return ['716b3fda0f857c3dc24d795d1a4d74e1e740face'] |
358 raise Exception('Unsupported VS version %s' % env_version) | 340 raise Exception('Unsupported VS version %s' % env_version) |
359 | 341 |
360 | 342 |
361 def ShouldUpdateToolchain(): | 343 def ShouldUpdateToolchain(): |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 'copy_dlls': CopyDlls, | 433 'copy_dlls': CopyDlls, |
452 } | 434 } |
453 if len(sys.argv) < 2 or sys.argv[1] not in commands: | 435 if len(sys.argv) < 2 or sys.argv[1] not in commands: |
454 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) | 436 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) |
455 return 1 | 437 return 1 |
456 return commands[sys.argv[1]](*sys.argv[2:]) | 438 return commands[sys.argv[1]](*sys.argv[2:]) |
457 | 439 |
458 | 440 |
459 if __name__ == '__main__': | 441 if __name__ == '__main__': |
460 sys.exit(main()) | 442 sys.exit(main()) |
OLD | NEW |