Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import json | 5 import json |
| 6 import os | 6 import os |
| 7 import pipes | 7 import pipes |
| 8 import shutil | 8 import shutil |
| 9 import subprocess | 9 import subprocess |
| 10 import sys | 10 import sys |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 def CopyVsRuntimeDlls(output_dir, runtime_dirs): | 66 def CopyVsRuntimeDlls(output_dir, runtime_dirs): |
| 67 """Copies the VS runtime DLLs from the given |runtime_dirs| to the output | 67 """Copies the VS runtime DLLs from the given |runtime_dirs| to the output |
| 68 directory so that even if not system-installed, built binaries are likely to | 68 directory so that even if not system-installed, built binaries are likely to |
| 69 be able to run. | 69 be able to run. |
| 70 | 70 |
| 71 This needs to be run after gyp has been run so that the expected target | 71 This needs to be run after gyp has been run so that the expected target |
| 72 output directories are already created. | 72 output directories are already created. |
| 73 """ | 73 """ |
| 74 assert sys.platform.startswith(('win32', 'cygwin')) | 74 assert sys.platform.startswith(('win32', 'cygwin')) |
| 75 | 75 |
| 76 def copy_runtime_impl(target, source): | |
| 77 """Copy |source| to |target| if it doesn't already exist or if it need to be | |
| 78 updated. | |
| 79 """ | |
| 80 if (os.path.isdir(os.path.dirname(target)) and | |
| 81 (not os.path.isfile(target) or | |
| 82 os.stat(target).st_mtime != os.stat(source).st_mtime)): | |
| 83 print 'Copying %s to %s...' % (source, target) | |
| 84 if os.path.exists(target): | |
| 85 os.unlink(target) | |
| 86 shutil.copy2(source, target) | |
| 87 | |
| 88 def copy_runtime(target_dir, source_dir, dll_pattern): | |
| 89 """Copy both the msvcr and msvcp runtime DLLs, only if the target doesn't | |
| 90 exist, but the target directory does exist.""" | |
| 91 for which in ('p', 'r'): | |
| 92 dll = dll_pattern % which | |
| 93 target = os.path.join(target_dir, dll) | |
| 94 source = os.path.join(source_dir, dll) | |
| 95 copy_runtime_impl(target, source) | |
| 96 | |
| 97 x86, x64 = runtime_dirs | 76 x86, x64 = runtime_dirs |
| 98 out_debug = os.path.join(output_dir, 'Debug') | 77 out_debug = os.path.join(output_dir, 'Debug') |
| 99 out_debug_nacl64 = os.path.join(output_dir, 'Debug', 'x64') | 78 out_debug_nacl64 = os.path.join(output_dir, 'Debug', 'x64') |
| 100 out_release = os.path.join(output_dir, 'Release') | 79 out_release = os.path.join(output_dir, 'Release') |
| 101 out_release_nacl64 = os.path.join(output_dir, 'Release', 'x64') | 80 out_release_nacl64 = os.path.join(output_dir, 'Release', 'x64') |
| 102 out_debug_x64 = os.path.join(output_dir, 'Debug_x64') | 81 out_debug_x64 = os.path.join(output_dir, 'Debug_x64') |
| 103 out_release_x64 = os.path.join(output_dir, 'Release_x64') | 82 out_release_x64 = os.path.join(output_dir, 'Release_x64') |
| 104 | 83 |
| 105 if os.path.exists(out_debug) and not os.path.exists(out_debug_nacl64): | 84 if os.path.exists(out_debug) and not os.path.exists(out_debug_nacl64): |
| 106 os.makedirs(out_debug_nacl64) | 85 os.makedirs(out_debug_nacl64) |
| 107 if os.path.exists(out_release) and not os.path.exists(out_release_nacl64): | 86 if os.path.exists(out_release) and not os.path.exists(out_release_nacl64): |
| 108 os.makedirs(out_release_nacl64) | 87 os.makedirs(out_release_nacl64) |
| 109 copy_runtime(out_debug, x86, 'msvc%s120d.dll') | 88 _CopyRuntime(out_debug, x86, 'msvc%s120d.dll') |
| 110 copy_runtime(out_release, x86, 'msvc%s120.dll') | 89 _CopyRuntime(out_release, x86, 'msvc%s120.dll') |
| 111 copy_runtime(out_debug_x64, x64, 'msvc%s120d.dll') | 90 _CopyRuntime(out_debug_x64, x64, 'msvc%s120d.dll') |
| 112 copy_runtime(out_release_x64, x64, 'msvc%s120.dll') | 91 _CopyRuntime(out_release_x64, x64, 'msvc%s120.dll') |
| 113 copy_runtime(out_debug_nacl64, x64, 'msvc%s120d.dll') | 92 _CopyRuntime(out_debug_nacl64, x64, 'msvc%s120d.dll') |
| 114 copy_runtime(out_release_nacl64, x64, 'msvc%s120.dll') | 93 _CopyRuntime(out_release_nacl64, x64, 'msvc%s120.dll') |
| 115 | 94 |
| 116 # Copy the PGO runtime library to the release directories. | 95 # Copy the PGO runtime library to the release directories. |
| 117 if os.environ.get('GYP_MSVS_OVERRIDE_PATH'): | 96 if os.environ.get('GYP_MSVS_OVERRIDE_PATH'): |
| 118 pgo_x86_runtime_dir = os.path.join(os.environ.get('GYP_MSVS_OVERRIDE_PATH'), | 97 pgo_x86_runtime_dir = os.path.join(os.environ.get('GYP_MSVS_OVERRIDE_PATH'), |
| 119 'VC', 'bin') | 98 'VC', 'bin') |
| 120 pgo_x64_runtime_dir = os.path.join(pgo_x86_runtime_dir, 'amd64') | 99 pgo_x64_runtime_dir = os.path.join(pgo_x86_runtime_dir, 'amd64') |
| 121 pgo_runtime_dll = 'pgort120.dll' | 100 pgo_runtime_dll = 'pgort120.dll' |
| 122 source_x86 = os.path.join(pgo_x86_runtime_dir, pgo_runtime_dll) | 101 source_x86 = os.path.join(pgo_x86_runtime_dir, pgo_runtime_dll) |
| 123 if os.path.exists(source_x86): | 102 if os.path.exists(source_x86): |
| 124 copy_runtime_impl(os.path.join(out_release, pgo_runtime_dll), source_x86) | 103 copy_runtime_impl(os.path.join(out_release, pgo_runtime_dll), source_x86) |
|
scottmg
2014/11/13 03:49:59
this will be broken
Dirk Pranke
2014/11/13 05:49:36
Good catch. Will fix. I thought I searched for oth
| |
| 125 source_x64 = os.path.join(pgo_x64_runtime_dir, pgo_runtime_dll) | 104 source_x64 = os.path.join(pgo_x64_runtime_dir, pgo_runtime_dll) |
| 126 if os.path.exists(source_x64): | 105 if os.path.exists(source_x64): |
| 127 copy_runtime_impl(os.path.join(out_release_x64, pgo_runtime_dll), | 106 copy_runtime_impl(os.path.join(out_release_x64, pgo_runtime_dll), |
| 128 source_x64) | 107 source_x64) |
| 129 | 108 |
| 130 | 109 |
| 110 def CopyDlls(target_dir, configuration, cpu_arch): | |
| 111 """Copy the VS runtime DLLs into the requested directory as needed. | |
| 112 | |
| 113 configuration is one of 'Debug' or 'Release'. | |
| 114 cpu_arch is one of 'x86' or 'x64'. | |
| 115 | |
| 116 The debug configuration gets both the debug and release DLLs; the | |
| 117 release config only the latter. | |
|
scottmg
2014/11/13 03:49:59
add a note to see the gyp version above, and note
Dirk Pranke
2014/11/13 05:49:36
Will do.
| |
| 118 """ | |
|
scottmg
2014/11/13 03:49:59
add a note that this will mean nacl tests will fai
Dirk Pranke
2014/11/13 05:49:36
I'm not sure what you're referring to here. Which
Nick Bray (chromium)
2014/11/13 20:10:53
Reading between the lines: NaCl will need x64 dlls
| |
| 119 vs2013_runtime_dll_dirs = SetEnvironmentAndGetRuntimeDllDirs() | |
| 120 if not vs2013_runtime_dll_dirs: | |
| 121 return | |
| 122 | |
| 123 x64_runtime, x86_runtime = vs2013_runtime_dll_dirs | |
| 124 runtime_dir = x64_runtime if cpu_arch == 'x64' else x86_runtime | |
| 125 _CopyRuntime(target_dir, runtime_dir, 'msvc%s120.dll') | |
| 126 if configuration == 'Debug': | |
| 127 _CopyRuntime(target_dir, runtime_dir, 'msvc%s120d.dll') | |
| 128 | |
| 129 | |
| 131 def _GetDesiredVsToolchainHashes(): | 130 def _GetDesiredVsToolchainHashes(): |
| 132 """Load a list of SHA1s corresponding to the toolchains that we want installed | 131 """Load a list of SHA1s corresponding to the toolchains that we want installed |
| 133 to build with.""" | 132 to build with.""" |
| 134 sha1path = os.path.join(script_dir, | 133 sha1path = os.path.join(script_dir, |
| 135 '..', 'buildtools', 'toolchain_vs2013.hash') | 134 '..', 'buildtools', 'toolchain_vs2013.hash') |
| 136 with open(sha1path, 'rb') as f: | 135 with open(sha1path, 'rb') as f: |
| 137 return f.read().strip().splitlines() | 136 return f.read().strip().splitlines() |
| 138 | 137 |
| 139 | 138 |
| 140 def Update(): | 139 def Update(): |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 os.environ['GYP_MSVS_VERSION'], | 180 os.environ['GYP_MSVS_VERSION'], |
| 182 os.environ.get('WDK_DIR', '')) | 181 os.environ.get('WDK_DIR', '')) |
| 183 | 182 |
| 184 | 183 |
| 185 def main(): | 184 def main(): |
| 186 if not sys.platform.startswith(('win32', 'cygwin')): | 185 if not sys.platform.startswith(('win32', 'cygwin')): |
| 187 return 0 | 186 return 0 |
| 188 commands = { | 187 commands = { |
| 189 'update': Update, | 188 'update': Update, |
| 190 'get_toolchain_dir': GetToolchainDir, | 189 'get_toolchain_dir': GetToolchainDir, |
| 191 # TODO(scottmg): Add copy_dlls for GN builds (gyp_chromium calls | 190 'copy_dlls': CopyDlls, |
| 192 # CopyVsRuntimeDlls via import, currently). | |
| 193 } | 191 } |
| 194 if len(sys.argv) < 2 or sys.argv[1] not in commands: | 192 if len(sys.argv) < 2 or sys.argv[1] not in commands: |
| 195 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) | 193 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) |
| 196 return 1 | 194 return 1 |
| 197 return commands[sys.argv[1]]() | 195 return commands[sys.argv[1]](*sys.argv[2:]) |
| 196 | |
| 197 | |
| 198 def _CopyRuntime(target_dir, source_dir, dll_pattern): | |
|
scottmg
2014/11/13 03:49:59
nit; move this up to before where it's used
Dirk Pranke
2014/11/13 05:49:36
Will do.
Dirk Pranke
2014/11/14 23:03:22
Done.
| |
| 199 """Copy both the msvcr and msvcp runtime DLLs, only if the target doesn't | |
| 200 exist, but the target directory does exist.""" | |
| 201 def copy_runtime_impl(target, source): | |
| 202 """Copy |source| to |target| if it doesn't already exist or if it | |
| 203 needs to be updated. | |
| 204 """ | |
| 205 if (os.path.isdir(os.path.dirname(target)) and | |
| 206 (not os.path.isfile(target) or | |
| 207 os.stat(target).st_mtime != os.stat(source).st_mtime)): | |
| 208 print 'Copying %s to %s...' % (source, target) | |
| 209 if os.path.exists(target): | |
| 210 os.unlink(target) | |
| 211 shutil.copy2(source, target) | |
| 212 | |
| 213 for which in ('p', 'r'): | |
| 214 dll = dll_pattern % which | |
| 215 target = os.path.join(target_dir, dll) | |
| 216 source = os.path.join(source_dir, dll) | |
| 217 copy_runtime_impl(target, source) | |
| 198 | 218 |
| 199 | 219 |
| 200 if __name__ == '__main__': | 220 if __name__ == '__main__': |
| 201 sys.exit(main()) | 221 sys.exit(main()) |
| OLD | NEW |