| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 def CopyVsRuntimeDlls(output_dir, runtime_dirs): | 64 def CopyVsRuntimeDlls(output_dir, runtime_dirs): |
| 65 """Copies the VS runtime DLLs from the given |runtime_dirs| to the output | 65 """Copies the VS runtime DLLs from the given |runtime_dirs| to the output |
| 66 directory so that even if not system-installed, built binaries are likely to | 66 directory so that even if not system-installed, built binaries are likely to |
| 67 be able to run. | 67 be able to run. |
| 68 | 68 |
| 69 This needs to be run after gyp has been run so that the expected target | 69 This needs to be run after gyp has been run so that the expected target |
| 70 output directories are already created. | 70 output directories are already created. |
| 71 """ | 71 """ |
| 72 assert sys.platform.startswith(('win32', 'cygwin')) | 72 assert sys.platform.startswith(('win32', 'cygwin')) |
| 73 | 73 |
| 74 def copy_runtime_impl(target, source): | |
| 75 """Copy |source| to |target| if it doesn't already exist or if it need to be | |
| 76 updated. | |
| 77 """ | |
| 78 if (os.path.isdir(os.path.dirname(target)) and | |
| 79 (not os.path.isfile(target) or | |
| 80 os.stat(target).st_mtime != os.stat(source).st_mtime)): | |
| 81 print 'Copying %s to %s...' % (source, target) | |
| 82 if os.path.exists(target): | |
| 83 os.unlink(target) | |
| 84 shutil.copy2(source, target) | |
| 85 | |
| 86 def copy_runtime(target_dir, source_dir, dll_pattern): | 74 def copy_runtime(target_dir, source_dir, dll_pattern): |
| 87 """Copy both the msvcr and msvcp runtime DLLs, only if the target doesn't | 75 """Copy both the msvcr and msvcp runtime DLLs, only if the target doesn't |
| 88 exist, but the target directory does exist.""" | 76 exist, but the target directory does exist.""" |
| 89 for which in ('p', 'r'): | 77 for which in ('p', 'r'): |
| 90 dll = dll_pattern % which | 78 dll = dll_pattern % which |
| 91 target = os.path.join(target_dir, dll) | 79 target = os.path.join(target_dir, dll) |
| 92 source = os.path.join(source_dir, dll) | 80 source = os.path.join(source_dir, dll) |
| 93 copy_runtime_impl(target, source) | 81 # If gyp generated to that output dir, and the runtime isn't already |
| 82 # there, then copy it over. |
| 83 if (os.path.isdir(target_dir) and |
| 84 (not os.path.isfile(target) or |
| 85 os.stat(target).st_mtime != os.stat(source).st_mtime)): |
| 86 print 'Copying %s to %s...' % (source, target) |
| 87 if os.path.exists(target): |
| 88 os.unlink(target) |
| 89 shutil.copy2(source, target) |
| 94 | 90 |
| 95 x86, x64 = runtime_dirs | 91 x86, x64 = runtime_dirs |
| 96 out_debug = os.path.join(output_dir, 'Debug') | 92 out_debug = os.path.join(output_dir, 'Debug') |
| 97 out_debug_nacl64 = os.path.join(output_dir, 'Debug', 'x64') | 93 out_debug_nacl64 = os.path.join(output_dir, 'Debug', 'x64') |
| 98 out_release = os.path.join(output_dir, 'Release') | 94 out_release = os.path.join(output_dir, 'Release') |
| 99 out_release_nacl64 = os.path.join(output_dir, 'Release', 'x64') | 95 out_release_nacl64 = os.path.join(output_dir, 'Release', 'x64') |
| 100 out_debug_x64 = os.path.join(output_dir, 'Debug_x64') | 96 out_debug_x64 = os.path.join(output_dir, 'Debug_x64') |
| 101 out_release_x64 = os.path.join(output_dir, 'Release_x64') | 97 out_release_x64 = os.path.join(output_dir, 'Release_x64') |
| 102 | 98 |
| 103 if os.path.exists(out_debug) and not os.path.exists(out_debug_nacl64): | 99 if os.path.exists(out_debug) and not os.path.exists(out_debug_nacl64): |
| 104 os.makedirs(out_debug_nacl64) | 100 os.makedirs(out_debug_nacl64) |
| 105 if os.path.exists(out_release) and not os.path.exists(out_release_nacl64): | 101 if os.path.exists(out_release) and not os.path.exists(out_release_nacl64): |
| 106 os.makedirs(out_release_nacl64) | 102 os.makedirs(out_release_nacl64) |
| 107 copy_runtime(out_debug, x86, 'msvc%s120d.dll') | 103 copy_runtime(out_debug, x86, 'msvc%s120d.dll') |
| 108 copy_runtime(out_release, x86, 'msvc%s120.dll') | 104 copy_runtime(out_release, x86, 'msvc%s120.dll') |
| 109 copy_runtime(out_debug_x64, x64, 'msvc%s120d.dll') | 105 copy_runtime(out_debug_x64, x64, 'msvc%s120d.dll') |
| 110 copy_runtime(out_release_x64, x64, 'msvc%s120.dll') | 106 copy_runtime(out_release_x64, x64, 'msvc%s120.dll') |
| 111 copy_runtime(out_debug_nacl64, x64, 'msvc%s120d.dll') | 107 copy_runtime(out_debug_nacl64, x64, 'msvc%s120d.dll') |
| 112 copy_runtime(out_release_nacl64, x64, 'msvc%s120.dll') | 108 copy_runtime(out_release_nacl64, x64, 'msvc%s120.dll') |
| 113 | 109 |
| 114 # Copy the PGO runtime library to the release directories. | |
| 115 if os.environ.get('GYP_MSVS_OVERRIDE_PATH'): | |
| 116 pgo_x86_runtime_dir = os.path.join(os.environ.get('GYP_MSVS_OVERRIDE_PATH'), | |
| 117 'VC', 'bin') | |
| 118 pgo_x64_runtime_dir = os.path.join(pgo_x86_runtime_dir, 'amd64') | |
| 119 pgo_runtime_dll = 'pgort120.dll' | |
| 120 copy_runtime_impl(os.path.join(out_release, pgo_runtime_dll), | |
| 121 os.path.join(pgo_x86_runtime_dir, pgo_runtime_dll)) | |
| 122 copy_runtime_impl(os.path.join(out_release_x64, pgo_runtime_dll), | |
| 123 os.path.join(pgo_x64_runtime_dir, pgo_runtime_dll)) | |
| 124 | |
| 125 | 110 |
| 126 def _GetDesiredVsToolchainHashes(): | 111 def _GetDesiredVsToolchainHashes(): |
| 127 """Load a list of SHA1s corresponding to the toolchains that we want installed | 112 """Load a list of SHA1s corresponding to the toolchains that we want installed |
| 128 to build with.""" | 113 to build with.""" |
| 129 sha1path = os.path.join(script_dir, 'toolchain_vs2013.hash') | 114 sha1path = os.path.join(script_dir, 'toolchain_vs2013.hash') |
| 130 with open(sha1path, 'rb') as f: | 115 with open(sha1path, 'rb') as f: |
| 131 return f.read().strip().splitlines() | 116 return f.read().strip().splitlines() |
| 132 | 117 |
| 133 | 118 |
| 134 def Update(): | 119 def Update(): |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 # CopyVsRuntimeDlls via import, currently). | 164 # CopyVsRuntimeDlls via import, currently). |
| 180 } | 165 } |
| 181 if len(sys.argv) < 2 or sys.argv[1] not in commands: | 166 if len(sys.argv) < 2 or sys.argv[1] not in commands: |
| 182 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) | 167 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) |
| 183 return 1 | 168 return 1 |
| 184 return commands[sys.argv[1]]() | 169 return commands[sys.argv[1]]() |
| 185 | 170 |
| 186 | 171 |
| 187 if __name__ == '__main__': | 172 if __name__ == '__main__': |
| 188 sys.exit(main()) | 173 sys.exit(main()) |
| OLD | NEW |