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 19 matching lines...) Expand all Loading... | |
| 30 depot_tools_win_toolchain = \ | 30 depot_tools_win_toolchain = \ |
| 31 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) | 31 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) |
| 32 if sys.platform in ('win32', 'cygwin') and depot_tools_win_toolchain: | 32 if sys.platform in ('win32', 'cygwin') and depot_tools_win_toolchain: |
| 33 if not os.path.exists(json_data_file): | 33 if not os.path.exists(json_data_file): |
| 34 Update() | 34 Update() |
| 35 with open(json_data_file, 'r') as tempf: | 35 with open(json_data_file, 'r') as tempf: |
| 36 toolchain_data = json.load(tempf) | 36 toolchain_data = json.load(tempf) |
| 37 | 37 |
| 38 toolchain = toolchain_data['path'] | 38 toolchain = toolchain_data['path'] |
| 39 version = toolchain_data['version'] | 39 version = toolchain_data['version'] |
| 40 win8sdk = toolchain_data['win8sdk'] | 40 win_sdk = toolchain_data.get('win_sdk') |
| 41 if not win_sdk: | |
| 42 win_sdk = toolchain_data['win8sdk'] | |
| 41 wdk = toolchain_data['wdk'] | 43 wdk = toolchain_data['wdk'] |
| 42 # TODO(scottmg): The order unfortunately matters in these. They should be | 44 # TODO(scottmg): The order unfortunately matters in these. They should be |
| 43 # split into separate keys for x86 and x64. (See CopyVsRuntimeDlls call | 45 # split into separate keys for x86 and x64. (See CopyVsRuntimeDlls call |
| 44 # below). http://crbug.com/345992 | 46 # below). http://crbug.com/345992 |
| 45 vs2013_runtime_dll_dirs = toolchain_data['runtime_dirs'] | 47 vs2013_runtime_dll_dirs = toolchain_data['runtime_dirs'] |
| 46 | 48 |
| 47 os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain | 49 os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain |
| 48 os.environ['GYP_MSVS_VERSION'] = version | 50 os.environ['GYP_MSVS_VERSION'] = version |
| 49 # We need to make sure windows_sdk_path is set to the automated | 51 # We need to make sure windows_sdk_path is set to the automated |
| 50 # toolchain values in GYP_DEFINES, but don't want to override any | 52 # toolchain values in GYP_DEFINES, but don't want to override any |
| 51 # otheroptions.express | 53 # otheroptions.express |
| 52 # values there. | 54 # values there. |
| 53 gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES')) | 55 gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES')) |
| 54 gyp_defines_dict['windows_sdk_path'] = win8sdk | 56 gyp_defines_dict['windows_sdk_path'] = win_sdk |
| 55 os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v))) | 57 os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v))) |
| 56 for k, v in gyp_defines_dict.iteritems()) | 58 for k, v in gyp_defines_dict.iteritems()) |
| 57 os.environ['WINDOWSSDKDIR'] = win8sdk | 59 os.environ['WINDOWSSDKDIR'] = win_sdk |
| 58 os.environ['WDK_DIR'] = wdk | 60 os.environ['WDK_DIR'] = wdk |
| 59 # Include the VS runtime in the PATH in case it's not machine-installed. | 61 # Include the VS runtime in the PATH in case it's not machine-installed. |
| 60 runtime_path = ';'.join(vs2013_runtime_dll_dirs) | 62 runtime_path = ';'.join(vs2013_runtime_dll_dirs) |
| 61 os.environ['PATH'] = runtime_path + ';' + os.environ['PATH'] | 63 os.environ['PATH'] = runtime_path + ';' + os.environ['PATH'] |
| 62 return vs2013_runtime_dll_dirs | 64 return vs2013_runtime_dll_dirs |
| 63 | 65 |
| 64 | 66 |
| 67 def _VersionNumber(): | |
| 68 """Gets the standard version number ('120', '140', etc.) based on | |
| 69 GYP_MSVS_VERSION.""" | |
| 70 if os.environ['GYP_MSVS_VERSION'] == '2013': | |
| 71 return '120' | |
| 72 elif os.environ['GYP_MSVS_VERSION'] == '2015': | |
| 73 return '140' | |
| 74 else: | |
| 75 raise ValueError('Unexpected GYP_MSVS_VERSION') | |
| 76 | |
| 77 | |
| 65 def _CopyRuntimeImpl(target, source): | 78 def _CopyRuntimeImpl(target, source): |
| 66 """Copy |source| to |target| if it doesn't already exist or if it | 79 """Copy |source| to |target| if it doesn't already exist or if it |
| 67 needs to be updated. | 80 needs to be updated. |
| 68 """ | 81 """ |
| 69 if (os.path.isdir(os.path.dirname(target)) and | 82 if (os.path.isdir(os.path.dirname(target)) and |
| 70 (not os.path.isfile(target) or | 83 (not os.path.isfile(target) or |
| 71 os.stat(target).st_mtime != os.stat(source).st_mtime)): | 84 os.stat(target).st_mtime != os.stat(source).st_mtime)): |
| 72 print 'Copying %s to %s...' % (source, target) | 85 print 'Copying %s to %s...' % (source, target) |
| 73 if os.path.exists(target): | 86 if os.path.exists(target): |
| 74 os.unlink(target) | 87 os.unlink(target) |
| 75 shutil.copy2(source, target) | 88 shutil.copy2(source, target) |
| 76 | 89 |
| 77 | 90 |
| 78 def _CopyRuntime(target_dir, source_dir, dll_pattern): | 91 def _CopyRuntime2013(target_dir, source_dir, dll_pattern): |
| 79 """Copy both the msvcr and msvcp runtime DLLs, only if the target doesn't | 92 """Copy both the msvcr and msvcp runtime DLLs, only if the target doesn't |
| 80 exist, but the target directory does exist.""" | 93 exist, but the target directory does exist.""" |
| 81 for which in ('p', 'r'): | 94 for file_part in ('p', 'r'): |
| 82 dll = dll_pattern % which | 95 dll = dll_pattern % file_part |
| 83 target = os.path.join(target_dir, dll) | 96 target = os.path.join(target_dir, dll) |
| 84 source = os.path.join(source_dir, dll) | 97 source = os.path.join(source_dir, dll) |
| 85 _CopyRuntimeImpl(target, source) | 98 _CopyRuntimeImpl(target, source) |
| 99 | |
| 100 | |
| 101 def _CopyRuntime2015(target_dir, source_dir, dll_pattern): | |
| 102 """Copy both the msvcp and vccorlib runtime DLLs, only if the target doesn't | |
| 103 exist, but the target directory does exist.""" | |
| 104 for file_part in ('msvcp', 'vccorlib'): | |
| 105 dll = dll_pattern % file_part | |
| 106 target = os.path.join(target_dir, dll) | |
| 107 source = os.path.join(source_dir, dll) | |
| 108 _CopyRuntimeImpl(target, source) | |
| 86 | 109 |
| 87 | 110 |
| 88 def CopyVsRuntimeDlls(output_dir, runtime_dirs): | 111 def CopyVsRuntimeDlls(output_dir, runtime_dirs): |
| 89 """Copies the VS runtime DLLs from the given |runtime_dirs| to the output | 112 """Copies the VS runtime DLLs from the given |runtime_dirs| to the output |
| 90 directory so that even if not system-installed, built binaries are likely to | 113 directory so that even if not system-installed, built binaries are likely to |
| 91 be able to run. | 114 be able to run. |
| 92 | 115 |
| 93 This needs to be run after gyp has been run so that the expected target | 116 This needs to be run after gyp has been run so that the expected target |
| 94 output directories are already created. | 117 output directories are already created. |
| 95 """ | 118 """ |
| 96 assert sys.platform.startswith(('win32', 'cygwin')) | 119 assert sys.platform.startswith(('win32', 'cygwin')) |
| 97 | 120 |
| 98 x86, x64 = runtime_dirs | 121 x86, x64 = runtime_dirs |
| 99 out_debug = os.path.join(output_dir, 'Debug') | 122 out_debug = os.path.join(output_dir, 'Debug') |
| 100 out_debug_nacl64 = os.path.join(output_dir, 'Debug', 'x64') | 123 out_debug_nacl64 = os.path.join(output_dir, 'Debug', 'x64') |
| 101 out_release = os.path.join(output_dir, 'Release') | 124 out_release = os.path.join(output_dir, 'Release') |
| 102 out_release_nacl64 = os.path.join(output_dir, 'Release', 'x64') | 125 out_release_nacl64 = os.path.join(output_dir, 'Release', 'x64') |
| 103 out_debug_x64 = os.path.join(output_dir, 'Debug_x64') | 126 out_debug_x64 = os.path.join(output_dir, 'Debug_x64') |
| 104 out_release_x64 = os.path.join(output_dir, 'Release_x64') | 127 out_release_x64 = os.path.join(output_dir, 'Release_x64') |
| 105 | 128 |
| 106 if os.path.exists(out_debug) and not os.path.exists(out_debug_nacl64): | 129 if os.path.exists(out_debug) and not os.path.exists(out_debug_nacl64): |
| 107 os.makedirs(out_debug_nacl64) | 130 os.makedirs(out_debug_nacl64) |
| 108 if os.path.exists(out_release) and not os.path.exists(out_release_nacl64): | 131 if os.path.exists(out_release) and not os.path.exists(out_release_nacl64): |
| 109 os.makedirs(out_release_nacl64) | 132 os.makedirs(out_release_nacl64) |
| 110 _CopyRuntime(out_debug, x86, 'msvc%s120d.dll') | 133 if os.environ.get('GYP_MSVS_VERSION') == '2015': |
| 111 _CopyRuntime(out_release, x86, 'msvc%s120.dll') | 134 _CopyRuntime2015(out_debug, x86, '%s140d.dll') |
| 112 _CopyRuntime(out_debug_x64, x64, 'msvc%s120d.dll') | 135 _CopyRuntime2015(out_release, x86, '%s140.dll') |
| 113 _CopyRuntime(out_release_x64, x64, 'msvc%s120.dll') | 136 _CopyRuntime2015(out_debug_x64, x64, '%s140d.dll') |
| 114 _CopyRuntime(out_debug_nacl64, x64, 'msvc%s120d.dll') | 137 _CopyRuntime2015(out_release_x64, x64, '%s140.dll') |
| 115 _CopyRuntime(out_release_nacl64, x64, 'msvc%s120.dll') | 138 _CopyRuntime2015(out_debug_nacl64, x64, '%s140d.dll') |
| 139 _CopyRuntime2015(out_release_nacl64, x64, '%s140.dll') | |
| 140 else: | |
| 141 # VS2013 is the default. | |
| 142 _CopyRuntime2013(out_debug, x86, 'msvc%s120d.dll') | |
| 143 _CopyRuntime2013(out_release, x86, 'msvc%s120.dll') | |
| 144 _CopyRuntime2013(out_debug_x64, x64, 'msvc%s120d.dll') | |
| 145 _CopyRuntime2013(out_release_x64, x64, 'msvc%s120.dll') | |
| 146 _CopyRuntime2013(out_debug_nacl64, x64, 'msvc%s120d.dll') | |
| 147 _CopyRuntime2013(out_release_nacl64, x64, 'msvc%s120.dll') | |
| 116 | 148 |
| 117 # Copy the PGO runtime library to the release directories. | 149 # Copy the PGO runtime library to the release directories. |
| 118 if os.environ.get('GYP_MSVS_OVERRIDE_PATH'): | 150 if os.environ.get('GYP_MSVS_OVERRIDE_PATH'): |
| 119 pgo_x86_runtime_dir = os.path.join(os.environ.get('GYP_MSVS_OVERRIDE_PATH'), | 151 pgo_x86_runtime_dir = os.path.join(os.environ.get('GYP_MSVS_OVERRIDE_PATH'), |
| 120 'VC', 'bin') | 152 'VC', 'bin') |
| 121 pgo_x64_runtime_dir = os.path.join(pgo_x86_runtime_dir, 'amd64') | 153 pgo_x64_runtime_dir = os.path.join(pgo_x86_runtime_dir, 'amd64') |
| 122 pgo_runtime_dll = 'pgort120.dll' | 154 pgo_runtime_dll = 'pgort' + _VersionNumber() + '.dll' |
| 123 source_x86 = os.path.join(pgo_x86_runtime_dir, pgo_runtime_dll) | 155 source_x86 = os.path.join(pgo_x86_runtime_dir, pgo_runtime_dll) |
| 124 if os.path.exists(source_x86): | 156 if os.path.exists(source_x86): |
| 125 _CopyRuntimeImpl(os.path.join(out_release, pgo_runtime_dll), source_x86) | 157 _CopyRuntimeImpl(os.path.join(out_release, pgo_runtime_dll), source_x86) |
| 126 source_x64 = os.path.join(pgo_x64_runtime_dir, pgo_runtime_dll) | 158 source_x64 = os.path.join(pgo_x64_runtime_dir, pgo_runtime_dll) |
| 127 if os.path.exists(source_x64): | 159 if os.path.exists(source_x64): |
| 128 _CopyRuntimeImpl(os.path.join(out_release_x64, pgo_runtime_dll), | 160 _CopyRuntimeImpl(os.path.join(out_release_x64, pgo_runtime_dll), |
| 129 source_x64) | 161 source_x64) |
| 130 | 162 |
| 131 | 163 |
| 132 def CopyDlls(target_dir, configuration, target_cpu): | 164 def CopyDlls(target_dir, configuration, target_cpu): |
| 133 """Copy the VS runtime DLLs into the requested directory as needed. | 165 """Copy the VS runtime DLLs into the requested directory as needed. |
| 134 | 166 |
| 135 configuration is one of 'Debug' or 'Release'. | 167 configuration is one of 'Debug' or 'Release'. |
| 136 target_cpu is one of 'x86' or 'x64'. | 168 target_cpu is one of 'x86' or 'x64'. |
| 137 | 169 |
| 138 The debug configuration gets both the debug and release DLLs; the | 170 The debug configuration gets both the debug and release DLLs; the |
| 139 release config only the latter. | 171 release config only the latter. |
| 140 """ | 172 """ |
| 141 vs2013_runtime_dll_dirs = SetEnvironmentAndGetRuntimeDllDirs() | 173 vs2013_runtime_dll_dirs = SetEnvironmentAndGetRuntimeDllDirs() |
| 142 if not vs2013_runtime_dll_dirs: | 174 if not vs2013_runtime_dll_dirs: |
| 143 return | 175 return |
| 144 | 176 |
| 145 x64_runtime, x86_runtime = vs2013_runtime_dll_dirs | 177 x64_runtime, x86_runtime = vs2013_runtime_dll_dirs |
| 146 runtime_dir = x64_runtime if target_cpu == 'x64' else x86_runtime | 178 runtime_dir = x64_runtime if target_cpu == 'x64' else x86_runtime |
| 147 _CopyRuntime(target_dir, runtime_dir, 'msvc%s120.dll') | 179 _CopyRuntime2013( |
| 180 target_dir, runtime_dir, 'msvc%s' + _VersionNumber() + '.dll') | |
| 148 if configuration == 'Debug': | 181 if configuration == 'Debug': |
| 149 _CopyRuntime(target_dir, runtime_dir, 'msvc%s120d.dll') | 182 _CopyRuntime2013( |
| 183 target_dir, runtime_dir, 'msvc%s' + _VersionNumber() + 'd.dll') | |
| 150 | 184 |
| 151 | 185 |
| 152 def _GetDesiredVsToolchainHashes(): | 186 def _GetDesiredVsToolchainHashes(): |
| 153 """Load a list of SHA1s corresponding to the toolchains that we want installed | 187 """Load a list of SHA1s corresponding to the toolchains that we want installed |
| 154 to build with.""" | 188 to build with.""" |
| 155 sha1path = os.path.join(script_dir, 'toolchain_vs2013.hash') | 189 # TODO(scottmg): If explicitly set to VS2015 override hashes to the VS2015 RC |
| 190 # toolchain. http://crbug.com/492774. | |
| 191 if os.environ.get('GYP_MSVS_VERSION') == '2015': | |
| 192 return ['89341a333306b216e0121fcf2495d04ccbb8c4fc'] | |
| 193 else: | |
| 194 # Default to VS2013. | |
| 195 return ['ee7d718ec60c2dc5d255bbe325909c2021a7efef'] | |
| 196 | |
| 197 sha1path = os.path.join(script_dir, 'win_toolchain.hash') | |
| 156 with open(sha1path, 'rb') as f: | 198 with open(sha1path, 'rb') as f: |
| 157 return f.read().strip().splitlines() | 199 return f.read().strip().splitlines() |
|
Dirk Pranke
2015/06/01 22:53:54
presumably you should delete lines 197-199, yes?
scottmg
2015/06/01 22:55:07
Doh! Thanks.
| |
| 158 | 200 |
| 159 | 201 |
| 160 def Update(): | 202 def Update(): |
| 161 """Requests an update of the toolchain to the specific hashes we have at | 203 """Requests an update of the toolchain to the specific hashes we have at |
| 162 this revision. The update outputs a .json of the various configuration | 204 this revision. The update outputs a .json of the various configuration |
| 163 information required to pass to gyp which we use in |GetToolchainDir()|. | 205 information required to pass to gyp which we use in |GetToolchainDir()|. |
| 164 """ | 206 """ |
| 165 depot_tools_win_toolchain = \ | 207 depot_tools_win_toolchain = \ |
| 166 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) | 208 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1'))) |
| 167 if sys.platform in ('win32', 'cygwin') and depot_tools_win_toolchain: | 209 if sys.platform in ('win32', 'cygwin') and depot_tools_win_toolchain: |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 'copy_dlls': CopyDlls, | 254 'copy_dlls': CopyDlls, |
| 213 } | 255 } |
| 214 if len(sys.argv) < 2 or sys.argv[1] not in commands: | 256 if len(sys.argv) < 2 or sys.argv[1] not in commands: |
| 215 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) | 257 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) |
| 216 return 1 | 258 return 1 |
| 217 return commands[sys.argv[1]](*sys.argv[2:]) | 259 return commands[sys.argv[1]](*sys.argv[2:]) |
| 218 | 260 |
| 219 | 261 |
| 220 if __name__ == '__main__': | 262 if __name__ == '__main__': |
| 221 sys.exit(main()) | 263 sys.exit(main()) |
| OLD | NEW |