| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v))) | 56 os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v))) |
| 57 for k, v in gyp_defines_dict.iteritems()) | 57 for k, v in gyp_defines_dict.iteritems()) |
| 58 os.environ['WINDOWSSDKDIR'] = win8sdk | 58 os.environ['WINDOWSSDKDIR'] = win8sdk |
| 59 os.environ['WDK_DIR'] = wdk | 59 os.environ['WDK_DIR'] = wdk |
| 60 # Include the VS runtime in the PATH in case it's not machine-installed. | 60 # Include the VS runtime in the PATH in case it's not machine-installed. |
| 61 runtime_path = ';'.join(vs2013_runtime_dll_dirs) | 61 runtime_path = ';'.join(vs2013_runtime_dll_dirs) |
| 62 os.environ['PATH'] = runtime_path + ';' + os.environ['PATH'] | 62 os.environ['PATH'] = runtime_path + ';' + os.environ['PATH'] |
| 63 return vs2013_runtime_dll_dirs | 63 return vs2013_runtime_dll_dirs |
| 64 | 64 |
| 65 | 65 |
| 66 def _CopyRuntimeImpl(target, source): |
| 67 """Copy |source| to |target| if it doesn't already exist or if it |
| 68 needs to be updated. |
| 69 """ |
| 70 if (os.path.isdir(os.path.dirname(target)) and |
| 71 (not os.path.isfile(target) or |
| 72 os.stat(target).st_mtime != os.stat(source).st_mtime)): |
| 73 print 'Copying %s to %s...' % (source, target) |
| 74 if os.path.exists(target): |
| 75 os.unlink(target) |
| 76 shutil.copy2(source, target) |
| 77 |
| 78 |
| 79 def _CopyRuntime(target_dir, source_dir, dll_pattern): |
| 80 """Copy both the msvcr and msvcp runtime DLLs, only if the target doesn't |
| 81 exist, but the target directory does exist.""" |
| 82 for which in ('p', 'r'): |
| 83 dll = dll_pattern % which |
| 84 target = os.path.join(target_dir, dll) |
| 85 source = os.path.join(source_dir, dll) |
| 86 _CopyRuntimeImpl(target, source) |
| 87 |
| 88 |
| 66 def CopyVsRuntimeDlls(output_dir, runtime_dirs): | 89 def CopyVsRuntimeDlls(output_dir, runtime_dirs): |
| 67 """Copies the VS runtime DLLs from the given |runtime_dirs| to the output | 90 """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 | 91 directory so that even if not system-installed, built binaries are likely to |
| 69 be able to run. | 92 be able to run. |
| 70 | 93 |
| 71 This needs to be run after gyp has been run so that the expected target | 94 This needs to be run after gyp has been run so that the expected target |
| 72 output directories are already created. | 95 output directories are already created. |
| 73 """ | 96 """ |
| 74 assert sys.platform.startswith(('win32', 'cygwin')) | 97 assert sys.platform.startswith(('win32', 'cygwin')) |
| 75 | 98 |
| 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 | 99 x86, x64 = runtime_dirs |
| 98 out_debug = os.path.join(output_dir, 'Debug') | 100 out_debug = os.path.join(output_dir, 'Debug') |
| 99 out_debug_nacl64 = os.path.join(output_dir, 'Debug', 'x64') | 101 out_debug_nacl64 = os.path.join(output_dir, 'Debug', 'x64') |
| 100 out_release = os.path.join(output_dir, 'Release') | 102 out_release = os.path.join(output_dir, 'Release') |
| 101 out_release_nacl64 = os.path.join(output_dir, 'Release', 'x64') | 103 out_release_nacl64 = os.path.join(output_dir, 'Release', 'x64') |
| 102 out_debug_x64 = os.path.join(output_dir, 'Debug_x64') | 104 out_debug_x64 = os.path.join(output_dir, 'Debug_x64') |
| 103 out_release_x64 = os.path.join(output_dir, 'Release_x64') | 105 out_release_x64 = os.path.join(output_dir, 'Release_x64') |
| 104 | 106 |
| 105 if os.path.exists(out_debug) and not os.path.exists(out_debug_nacl64): | 107 if os.path.exists(out_debug) and not os.path.exists(out_debug_nacl64): |
| 106 os.makedirs(out_debug_nacl64) | 108 os.makedirs(out_debug_nacl64) |
| 107 if os.path.exists(out_release) and not os.path.exists(out_release_nacl64): | 109 if os.path.exists(out_release) and not os.path.exists(out_release_nacl64): |
| 108 os.makedirs(out_release_nacl64) | 110 os.makedirs(out_release_nacl64) |
| 109 copy_runtime(out_debug, x86, 'msvc%s120d.dll') | 111 _CopyRuntime(out_debug, x86, 'msvc%s120d.dll') |
| 110 copy_runtime(out_release, x86, 'msvc%s120.dll') | 112 _CopyRuntime(out_release, x86, 'msvc%s120.dll') |
| 111 copy_runtime(out_debug_x64, x64, 'msvc%s120d.dll') | 113 _CopyRuntime(out_debug_x64, x64, 'msvc%s120d.dll') |
| 112 copy_runtime(out_release_x64, x64, 'msvc%s120.dll') | 114 _CopyRuntime(out_release_x64, x64, 'msvc%s120.dll') |
| 113 copy_runtime(out_debug_nacl64, x64, 'msvc%s120d.dll') | 115 _CopyRuntime(out_debug_nacl64, x64, 'msvc%s120d.dll') |
| 114 copy_runtime(out_release_nacl64, x64, 'msvc%s120.dll') | 116 _CopyRuntime(out_release_nacl64, x64, 'msvc%s120.dll') |
| 115 | 117 |
| 116 # Copy the PGO runtime library to the release directories. | 118 # Copy the PGO runtime library to the release directories. |
| 117 if os.environ.get('GYP_MSVS_OVERRIDE_PATH'): | 119 if os.environ.get('GYP_MSVS_OVERRIDE_PATH'): |
| 118 pgo_x86_runtime_dir = os.path.join(os.environ.get('GYP_MSVS_OVERRIDE_PATH'), | 120 pgo_x86_runtime_dir = os.path.join(os.environ.get('GYP_MSVS_OVERRIDE_PATH'), |
| 119 'VC', 'bin') | 121 'VC', 'bin') |
| 120 pgo_x64_runtime_dir = os.path.join(pgo_x86_runtime_dir, 'amd64') | 122 pgo_x64_runtime_dir = os.path.join(pgo_x86_runtime_dir, 'amd64') |
| 121 pgo_runtime_dll = 'pgort120.dll' | 123 pgo_runtime_dll = 'pgort120.dll' |
| 122 source_x86 = os.path.join(pgo_x86_runtime_dir, pgo_runtime_dll) | 124 source_x86 = os.path.join(pgo_x86_runtime_dir, pgo_runtime_dll) |
| 123 if os.path.exists(source_x86): | 125 if os.path.exists(source_x86): |
| 124 copy_runtime_impl(os.path.join(out_release, pgo_runtime_dll), source_x86) | 126 _CopyRuntimeImpl(os.path.join(out_release, pgo_runtime_dll), source_x86) |
| 125 source_x64 = os.path.join(pgo_x64_runtime_dir, pgo_runtime_dll) | 127 source_x64 = os.path.join(pgo_x64_runtime_dir, pgo_runtime_dll) |
| 126 if os.path.exists(source_x64): | 128 if os.path.exists(source_x64): |
| 127 copy_runtime_impl(os.path.join(out_release_x64, pgo_runtime_dll), | 129 _CopyRuntimeImpl(os.path.join(out_release_x64, pgo_runtime_dll), |
| 128 source_x64) | 130 source_x64) |
| 131 |
| 132 |
| 133 def CopyDlls(target_dir, configuration, cpu_arch): |
| 134 """Copy the VS runtime DLLs into the requested directory as needed. |
| 135 |
| 136 configuration is one of 'Debug' or 'Release'. |
| 137 cpu_arch is one of 'x86' or 'x64'. |
| 138 |
| 139 The debug configuration gets both the debug and release DLLs; the |
| 140 release config only the latter. |
| 141 """ |
| 142 vs2013_runtime_dll_dirs = SetEnvironmentAndGetRuntimeDllDirs() |
| 143 if not vs2013_runtime_dll_dirs: |
| 144 return |
| 145 |
| 146 x64_runtime, x86_runtime = vs2013_runtime_dll_dirs |
| 147 runtime_dir = x64_runtime if cpu_arch == 'x64' else x86_runtime |
| 148 _CopyRuntime(target_dir, runtime_dir, 'msvc%s120.dll') |
| 149 if configuration == 'Debug': |
| 150 _CopyRuntime(target_dir, runtime_dir, 'msvc%s120d.dll') |
| 129 | 151 |
| 130 | 152 |
| 131 def _GetDesiredVsToolchainHashes(): | 153 def _GetDesiredVsToolchainHashes(): |
| 132 """Load a list of SHA1s corresponding to the toolchains that we want installed | 154 """Load a list of SHA1s corresponding to the toolchains that we want installed |
| 133 to build with.""" | 155 to build with.""" |
| 134 sha1path = os.path.join(script_dir, | 156 sha1path = os.path.join(script_dir, 'toolchain_vs2013.hash') |
| 135 '..', 'buildtools', 'toolchain_vs2013.hash') | |
| 136 with open(sha1path, 'rb') as f: | 157 with open(sha1path, 'rb') as f: |
| 137 return f.read().strip().splitlines() | 158 return f.read().strip().splitlines() |
| 138 | 159 |
| 139 | 160 |
| 140 def Update(): | 161 def Update(): |
| 141 """Requests an update of the toolchain to the specific hashes we have at | 162 """Requests an update of the toolchain to the specific hashes we have at |
| 142 this revision. The update outputs a .json of the various configuration | 163 this revision. The update outputs a .json of the various configuration |
| 143 information required to pass to gyp which we use in |GetToolchainDir()|. | 164 information required to pass to gyp which we use in |GetToolchainDir()|. |
| 144 """ | 165 """ |
| 145 depot_tools_win_toolchain = \ | 166 depot_tools_win_toolchain = \ |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 os.environ['GYP_MSVS_VERSION'], | 202 os.environ['GYP_MSVS_VERSION'], |
| 182 os.environ.get('WDK_DIR', '')) | 203 os.environ.get('WDK_DIR', '')) |
| 183 | 204 |
| 184 | 205 |
| 185 def main(): | 206 def main(): |
| 186 if not sys.platform.startswith(('win32', 'cygwin')): | 207 if not sys.platform.startswith(('win32', 'cygwin')): |
| 187 return 0 | 208 return 0 |
| 188 commands = { | 209 commands = { |
| 189 'update': Update, | 210 'update': Update, |
| 190 'get_toolchain_dir': GetToolchainDir, | 211 'get_toolchain_dir': GetToolchainDir, |
| 191 # TODO(scottmg): Add copy_dlls for GN builds (gyp_chromium calls | 212 'copy_dlls': CopyDlls, |
| 192 # CopyVsRuntimeDlls via import, currently). | |
| 193 } | 213 } |
| 194 if len(sys.argv) < 2 or sys.argv[1] not in commands: | 214 if len(sys.argv) < 2 or sys.argv[1] not in commands: |
| 195 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) | 215 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) |
| 196 return 1 | 216 return 1 |
| 197 return commands[sys.argv[1]]() | 217 return commands[sys.argv[1]](*sys.argv[2:]) |
| 198 | 218 |
| 199 | 219 |
| 200 if __name__ == '__main__': | 220 if __name__ == '__main__': |
| 201 sys.exit(main()) | 221 sys.exit(main()) |
| OLD | NEW |