| 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 shutil | 11 import shutil |
| 12 import stat |
| 11 import subprocess | 13 import subprocess |
| 12 import sys | 14 import sys |
| 13 | 15 |
| 14 | 16 |
| 15 script_dir = os.path.dirname(os.path.realpath(__file__)) | 17 script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 16 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)) |
| 17 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__))) |
| 18 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib')) | 20 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib')) |
| 19 json_data_file = os.path.join(script_dir, 'win_toolchain.json') | 21 json_data_file = os.path.join(script_dir, 'win_toolchain.json') |
| 20 | 22 |
| 21 | 23 |
| 22 import gyp | 24 import gyp |
| 23 | 25 |
| 24 | 26 |
| 25 # Use MSVS2015 as the default toolchain. | 27 # Use MSVS2015 as the default toolchain. |
| 26 CURRENT_DEFAULT_TOOLCHAIN_VERSION = '2015' | 28 CURRENT_DEFAULT_TOOLCHAIN_VERSION = '2015' |
| 27 | 29 |
| 28 | 30 |
| 29 def SetEnvironmentAndGetRuntimeDllDirs(): | 31 def SetEnvironmentAndGetRuntimeDllDirs(): |
| 30 """Sets up os.environ to use the depot_tools VS toolchain with gyp, and | 32 """Sets up os.environ to use the depot_tools VS toolchain with gyp, and |
| 31 returns the location of the VS runtime DLLs so they can be copied into | 33 returns the location of the VS runtime DLLs so they can be copied into |
| 32 the output directory after gyp generation. | 34 the output directory after gyp generation. |
| 35 |
| 36 Return value is [x64path, x86path] or None |
| 33 """ | 37 """ |
| 34 vs_runtime_dll_dirs = None | 38 vs_runtime_dll_dirs = None |
| 35 depot_tools_win_toolchain = \ | 39 depot_tools_win_toolchain = \ |
| 36 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) | 40 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) |
| 37 # When running on a non-Windows host, only do this if the SDK has explicitly | 41 # When running on a non-Windows host, only do this if the SDK has explicitly |
| 38 # been downloaded before (in which case json_data_file will exist). | 42 # been downloaded before (in which case json_data_file will exist). |
| 39 if ((sys.platform in ('win32', 'cygwin') or os.path.exists(json_data_file)) | 43 if ((sys.platform in ('win32', 'cygwin') or os.path.exists(json_data_file)) |
| 40 and depot_tools_win_toolchain): | 44 and depot_tools_win_toolchain): |
| 41 if ShouldUpdateToolchain(): | 45 if ShouldUpdateToolchain(): |
| 42 Update() | 46 Update() |
| (...skipping 25 matching lines...) Expand all Loading... |
| 68 os.environ['WDK_DIR'] = wdk | 72 os.environ['WDK_DIR'] = wdk |
| 69 # Include the VS runtime in the PATH in case it's not machine-installed. | 73 # Include the VS runtime in the PATH in case it's not machine-installed. |
| 70 runtime_path = os.path.pathsep.join(vs_runtime_dll_dirs) | 74 runtime_path = os.path.pathsep.join(vs_runtime_dll_dirs) |
| 71 os.environ['PATH'] = runtime_path + os.path.pathsep + os.environ['PATH'] | 75 os.environ['PATH'] = runtime_path + os.path.pathsep + os.environ['PATH'] |
| 72 elif sys.platform == 'win32' and not depot_tools_win_toolchain: | 76 elif sys.platform == 'win32' and not depot_tools_win_toolchain: |
| 73 if not 'GYP_MSVS_OVERRIDE_PATH' in os.environ: | 77 if not 'GYP_MSVS_OVERRIDE_PATH' in os.environ: |
| 74 os.environ['GYP_MSVS_OVERRIDE_PATH'] = DetectVisualStudioPath() | 78 os.environ['GYP_MSVS_OVERRIDE_PATH'] = DetectVisualStudioPath() |
| 75 if not 'GYP_MSVS_VERSION' in os.environ: | 79 if not 'GYP_MSVS_VERSION' in os.environ: |
| 76 os.environ['GYP_MSVS_VERSION'] = GetVisualStudioVersion() | 80 os.environ['GYP_MSVS_VERSION'] = GetVisualStudioVersion() |
| 77 | 81 |
| 82 # When using an installed toolchain these files aren't needed in the output |
| 83 # directory in order to run binaries locally, but they are needed in order |
| 84 # to create isolates or the mini_installer. Copying them to the output |
| 85 # directory ensures that they are available when needed. |
| 86 bitness = platform.architecture()[0] |
| 87 # When running 64-bit python the x64 DLLs will be in System32 |
| 88 x64_path = 'System32' if bitness == '64bit' else 'Sysnative' |
| 89 x64_path = os.path.join(r'C:\Windows', x64_path) |
| 90 vs_runtime_dll_dirs = [x64_path, r'C:\Windows\SysWOW64'] |
| 91 |
| 78 return vs_runtime_dll_dirs | 92 return vs_runtime_dll_dirs |
| 79 | 93 |
| 80 | 94 |
| 81 def _RegistryGetValueUsingWinReg(key, value): | 95 def _RegistryGetValueUsingWinReg(key, value): |
| 82 """Use the _winreg module to obtain the value of a registry key. | 96 """Use the _winreg module to obtain the value of a registry key. |
| 83 | 97 |
| 84 Args: | 98 Args: |
| 85 key: The registry key. | 99 key: The registry key. |
| 86 value: The particular registry value to read. | 100 value: The particular registry value to read. |
| 87 Return: | 101 Return: |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 updated (comparing last modified time as an approximate float match as for | 171 updated (comparing last modified time as an approximate float match as for |
| 158 some reason the values tend to differ by ~1e-07 despite being copies of the | 172 some reason the values tend to differ by ~1e-07 despite being copies of the |
| 159 same file... https://crbug.com/603603). | 173 same file... https://crbug.com/603603). |
| 160 """ | 174 """ |
| 161 if (os.path.isdir(os.path.dirname(target)) and | 175 if (os.path.isdir(os.path.dirname(target)) and |
| 162 (not os.path.isfile(target) or | 176 (not os.path.isfile(target) or |
| 163 abs(os.stat(target).st_mtime - os.stat(source).st_mtime) >= 0.01)): | 177 abs(os.stat(target).st_mtime - os.stat(source).st_mtime) >= 0.01)): |
| 164 if verbose: | 178 if verbose: |
| 165 print 'Copying %s to %s...' % (source, target) | 179 print 'Copying %s to %s...' % (source, target) |
| 166 if os.path.exists(target): | 180 if os.path.exists(target): |
| 181 # Make the file writable so that we can delete it now. |
| 182 os.chmod(target, stat.S_IWRITE) |
| 167 os.unlink(target) | 183 os.unlink(target) |
| 168 shutil.copy2(source, target) | 184 shutil.copy2(source, target) |
| 185 # Make the file writable so that we can overwrite or delete it later. |
| 186 os.chmod(target, stat.S_IWRITE) |
| 169 | 187 |
| 170 | 188 |
| 171 def _CopyRuntime2013(target_dir, source_dir, dll_pattern): | 189 def _CopyRuntime2013(target_dir, source_dir, dll_pattern): |
| 172 """Copy both the msvcr and msvcp runtime DLLs, only if the target doesn't | 190 """Copy both the msvcr and msvcp runtime DLLs, only if the target doesn't |
| 173 exist, but the target directory does exist.""" | 191 exist, but the target directory does exist.""" |
| 174 for file_part in ('p', 'r'): | 192 for file_part in ('p', 'r'): |
| 175 dll = dll_pattern % file_part | 193 dll = dll_pattern % file_part |
| 176 target = os.path.join(target_dir, dll) | 194 target = os.path.join(target_dir, dll) |
| 177 source = os.path.join(source_dir, dll) | 195 source = os.path.join(source_dir, dll) |
| 178 _CopyRuntimeImpl(target, source) | 196 _CopyRuntimeImpl(target, source) |
| 179 | 197 |
| 180 | 198 |
| 181 def _CopyRuntime2015(target_dir, source_dir, dll_pattern, suffix): | 199 def _CopyRuntime2015(target_dir, source_dir, dll_pattern, suffix): |
| 182 """Copy both the msvcp and vccorlib runtime DLLs, only if the target doesn't | 200 """Copy both the msvcp and vccorlib runtime DLLs, only if the target doesn't |
| 183 exist, but the target directory does exist.""" | 201 exist, but the target directory does exist.""" |
| 184 for file_part in ('msvcp', 'vccorlib', 'vcruntime'): | 202 for file_part in ('msvcp', 'vccorlib', 'vcruntime'): |
| 185 dll = dll_pattern % file_part | 203 dll = dll_pattern % file_part |
| 186 target = os.path.join(target_dir, dll) | 204 target = os.path.join(target_dir, dll) |
| 187 source = os.path.join(source_dir, dll) | 205 source = os.path.join(source_dir, dll) |
| 188 _CopyRuntimeImpl(target, source) | 206 _CopyRuntimeImpl(target, source) |
| 189 ucrt_src_dir = os.path.join(source_dir, 'api-ms-win-*.dll') | 207 # OS installs of Visual Studio (and all installs of Windows 10) put the |
| 190 for ucrt_src_file in glob.glob(ucrt_src_dir): | 208 # universal CRT files in c:\Windows\System32\downlevel - look for them there |
| 209 # to support DEPOT_TOOLS_WIN_TOOLCHAIN=0. |
| 210 if os.path.exists(os.path.join(source_dir, 'downlevel')): |
| 211 ucrt_src_glob = os.path.join(source_dir, 'downlevel', 'api-ms-win-*.dll') |
| 212 else: |
| 213 ucrt_src_glob = os.path.join(source_dir, 'api-ms-win-*.dll') |
| 214 ucrt_files = glob.glob(ucrt_src_glob) |
| 215 assert len(ucrt_files) > 0 |
| 216 for ucrt_src_file in ucrt_files: |
| 191 file_part = os.path.basename(ucrt_src_file) | 217 file_part = os.path.basename(ucrt_src_file) |
| 192 ucrt_dst_file = os.path.join(target_dir, file_part) | 218 ucrt_dst_file = os.path.join(target_dir, file_part) |
| 193 _CopyRuntimeImpl(ucrt_dst_file, ucrt_src_file, False) | 219 _CopyRuntimeImpl(ucrt_dst_file, ucrt_src_file, False) |
| 194 _CopyRuntimeImpl(os.path.join(target_dir, 'ucrtbase' + suffix), | 220 _CopyRuntimeImpl(os.path.join(target_dir, 'ucrtbase' + suffix), |
| 195 os.path.join(source_dir, 'ucrtbase' + suffix)) | 221 os.path.join(source_dir, 'ucrtbase' + suffix)) |
| 196 | 222 |
| 197 | 223 |
| 198 def _CopyRuntime(target_dir, source_dir, target_cpu, debug): | 224 def _CopyRuntime(target_dir, source_dir, target_cpu, debug): |
| 199 """Copy the VS runtime DLLs, only if the target doesn't exist, but the target | 225 """Copy the VS runtime DLLs, only if the target doesn't exist, but the target |
| 200 directory does exist. Handles VS 2013 and VS 2015.""" | 226 directory does exist. Handles VS 2013 and VS 2015.""" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 'copy_dlls': CopyDlls, | 399 'copy_dlls': CopyDlls, |
| 374 } | 400 } |
| 375 if len(sys.argv) < 2 or sys.argv[1] not in commands: | 401 if len(sys.argv) < 2 or sys.argv[1] not in commands: |
| 376 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) | 402 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) |
| 377 return 1 | 403 return 1 |
| 378 return commands[sys.argv[1]](*sys.argv[2:]) | 404 return commands[sys.argv[1]](*sys.argv[2:]) |
| 379 | 405 |
| 380 | 406 |
| 381 if __name__ == '__main__': | 407 if __name__ == '__main__': |
| 382 sys.exit(main()) | 408 sys.exit(main()) |
| OLD | NEW |