| 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 json | 6 import json |
| 7 import os | 7 import os |
| 8 import pipes | 8 import pipes |
| 9 import shutil | 9 import shutil |
| 10 import subprocess | 10 import subprocess |
| 11 import sys | 11 import sys |
| 12 | 12 |
| 13 | 13 |
| 14 script_dir = os.path.dirname(os.path.realpath(__file__)) | 14 script_dir = os.path.dirname(os.path.realpath(__file__)) |
| 15 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir)) | 15 chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir)) |
| 16 SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 16 SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 17 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib')) | 17 sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib')) |
| 18 json_data_file = os.path.join(script_dir, 'win_toolchain.json') | 18 json_data_file = os.path.join(script_dir, 'win_toolchain.json') |
| 19 | 19 |
| 20 | 20 |
| 21 import gyp | 21 import gyp |
| 22 | 22 |
| 23 | 23 |
| 24 def SetEnvironmentAndGetRuntimeDllDirs(): | 24 def SetEnvironmentAndGetRuntimeDllDirs(): |
| 25 """Sets up os.environ to use the depot_tools VS toolchain with gyp, and | 25 """Sets up os.environ to use the depot_tools VS toolchain with gyp, and |
| 26 returns the location of the VS runtime DLLs so they can be copied into | 26 returns the location of the VS runtime DLLs so they can be copied into |
| 27 the output directory after gyp generation. | 27 the output directory after gyp generation. |
| 28 """ | 28 """ |
| 29 vs2013_runtime_dll_dirs = None | 29 vs_runtime_dll_dirs = None |
| 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 # When running on a non-Windows host, only do this if the SDK has explicitly | 32 # When running on a non-Windows host, only do this if the SDK has explicitly |
| 33 # been downloaded before (in which case json_data_file will exist). | 33 # been downloaded before (in which case json_data_file will exist). |
| 34 if ((sys.platform in ('win32', 'cygwin') or os.path.exists(json_data_file)) | 34 if ((sys.platform in ('win32', 'cygwin') or os.path.exists(json_data_file)) |
| 35 and depot_tools_win_toolchain): | 35 and depot_tools_win_toolchain): |
| 36 if not os.path.exists(json_data_file): | 36 if not os.path.exists(json_data_file): |
| 37 Update() | 37 Update() |
| 38 with open(json_data_file, 'r') as tempf: | 38 with open(json_data_file, 'r') as tempf: |
| 39 toolchain_data = json.load(tempf) | 39 toolchain_data = json.load(tempf) |
| 40 | 40 |
| 41 toolchain = toolchain_data['path'] | 41 toolchain = toolchain_data['path'] |
| 42 version = toolchain_data['version'] | 42 version = toolchain_data['version'] |
| 43 win_sdk = toolchain_data.get('win_sdk') | 43 win_sdk = toolchain_data.get('win_sdk') |
| 44 if not win_sdk: | 44 if not win_sdk: |
| 45 win_sdk = toolchain_data['win8sdk'] | 45 win_sdk = toolchain_data['win8sdk'] |
| 46 wdk = toolchain_data['wdk'] | 46 wdk = toolchain_data['wdk'] |
| 47 # TODO(scottmg): The order unfortunately matters in these. They should be | 47 # TODO(scottmg): The order unfortunately matters in these. They should be |
| 48 # split into separate keys for x86 and x64. (See CopyVsRuntimeDlls call | 48 # split into separate keys for x86 and x64. (See CopyVsRuntimeDlls call |
| 49 # below). http://crbug.com/345992 | 49 # below). http://crbug.com/345992 |
| 50 vs2013_runtime_dll_dirs = toolchain_data['runtime_dirs'] | 50 vs_runtime_dll_dirs = toolchain_data['runtime_dirs'] |
| 51 | 51 |
| 52 os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain | 52 os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain |
| 53 os.environ['GYP_MSVS_VERSION'] = version | 53 os.environ['GYP_MSVS_VERSION'] = version |
| 54 # We need to make sure windows_sdk_path is set to the automated | 54 # We need to make sure windows_sdk_path is set to the automated |
| 55 # toolchain values in GYP_DEFINES, but don't want to override any | 55 # toolchain values in GYP_DEFINES, but don't want to override any |
| 56 # otheroptions.express | 56 # otheroptions.express |
| 57 # values there. | 57 # values there. |
| 58 gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES')) | 58 gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES')) |
| 59 gyp_defines_dict['windows_sdk_path'] = win_sdk | 59 gyp_defines_dict['windows_sdk_path'] = win_sdk |
| 60 os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v))) | 60 os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v))) |
| 61 for k, v in gyp_defines_dict.iteritems()) | 61 for k, v in gyp_defines_dict.iteritems()) |
| 62 os.environ['WINDOWSSDKDIR'] = win_sdk | 62 os.environ['WINDOWSSDKDIR'] = win_sdk |
| 63 os.environ['WDK_DIR'] = wdk | 63 os.environ['WDK_DIR'] = wdk |
| 64 # Include the VS runtime in the PATH in case it's not machine-installed. | 64 # Include the VS runtime in the PATH in case it's not machine-installed. |
| 65 runtime_path = ';'.join(vs2013_runtime_dll_dirs) | 65 runtime_path = ';'.join(vs_runtime_dll_dirs) |
| 66 os.environ['PATH'] = runtime_path + ';' + os.environ['PATH'] | 66 os.environ['PATH'] = runtime_path + ';' + os.environ['PATH'] |
| 67 return vs2013_runtime_dll_dirs | 67 return vs_runtime_dll_dirs |
| 68 | 68 |
| 69 | 69 |
| 70 def _VersionNumber(): | 70 def _VersionNumber(): |
| 71 """Gets the standard version number ('120', '140', etc.) based on | 71 """Gets the standard version number ('120', '140', etc.) based on |
| 72 GYP_MSVS_VERSION.""" | 72 GYP_MSVS_VERSION.""" |
| 73 if os.environ['GYP_MSVS_VERSION'] == '2013': | 73 if os.environ['GYP_MSVS_VERSION'] == '2013': |
| 74 return '120' | 74 return '120' |
| 75 elif os.environ['GYP_MSVS_VERSION'] == '2015': | 75 elif os.environ['GYP_MSVS_VERSION'] == '2015': |
| 76 return '140' | 76 return '140' |
| 77 else: | 77 else: |
| (...skipping 26 matching lines...) Expand all Loading... |
| 104 def _CopyRuntime2015(target_dir, source_dir, dll_pattern): | 104 def _CopyRuntime2015(target_dir, source_dir, dll_pattern): |
| 105 """Copy both the msvcp and vccorlib runtime DLLs, only if the target doesn't | 105 """Copy both the msvcp and vccorlib runtime DLLs, only if the target doesn't |
| 106 exist, but the target directory does exist.""" | 106 exist, but the target directory does exist.""" |
| 107 for file_part in ('msvcp', 'vccorlib'): | 107 for file_part in ('msvcp', 'vccorlib'): |
| 108 dll = dll_pattern % file_part | 108 dll = dll_pattern % file_part |
| 109 target = os.path.join(target_dir, dll) | 109 target = os.path.join(target_dir, dll) |
| 110 source = os.path.join(source_dir, dll) | 110 source = os.path.join(source_dir, dll) |
| 111 _CopyRuntimeImpl(target, source) | 111 _CopyRuntimeImpl(target, source) |
| 112 | 112 |
| 113 | 113 |
| 114 def _CopyRuntime(target_dir, source_dir, target_cpu, debug): |
| 115 """Copy the VS runtime DLLs, only if the target doesn't exist, but the target |
| 116 directory does exist. Handles VS 2013 and VS 2015.""" |
| 117 suffix = "d.dll" if debug else ".dll" |
| 118 if os.environ.get('GYP_MSVS_VERSION') == '2015': |
| 119 _CopyRuntime2015(target_dir, source_dir, '%s140' + suffix) |
| 120 else: |
| 121 _CopyRuntime2013(target_dir, source_dir, 'msvc%s120' + suffix) |
| 122 |
| 123 # Copy the PGO runtime library to the release directories. |
| 124 if not debug and os.environ.get('GYP_MSVS_OVERRIDE_PATH'): |
| 125 pgo_x86_runtime_dir = os.path.join(os.environ.get('GYP_MSVS_OVERRIDE_PATH'), |
| 126 'VC', 'bin') |
| 127 pgo_x64_runtime_dir = os.path.join(pgo_x86_runtime_dir, 'amd64') |
| 128 pgo_runtime_dll = 'pgort' + _VersionNumber() + '.dll' |
| 129 if target_cpu == "x86": |
| 130 source_x86 = os.path.join(pgo_x86_runtime_dir, pgo_runtime_dll) |
| 131 if os.path.exists(source_x86): |
| 132 _CopyRuntimeImpl(os.path.join(target_dir, pgo_runtime_dll), source_x86) |
| 133 elif target_cpu == "x64": |
| 134 source_x64 = os.path.join(pgo_x64_runtime_dir, pgo_runtime_dll) |
| 135 if os.path.exists(source_x64): |
| 136 _CopyRuntimeImpl(os.path.join(target_dir, pgo_runtime_dll), |
| 137 source_x64) |
| 138 else: |
| 139 raise NotImplementedError("Unexpected target_cpu value:" + target_cpu) |
| 140 |
| 141 |
| 114 def CopyVsRuntimeDlls(output_dir, runtime_dirs): | 142 def CopyVsRuntimeDlls(output_dir, runtime_dirs): |
| 115 """Copies the VS runtime DLLs from the given |runtime_dirs| to the output | 143 """Copies the VS runtime DLLs from the given |runtime_dirs| to the output |
| 116 directory so that even if not system-installed, built binaries are likely to | 144 directory so that even if not system-installed, built binaries are likely to |
| 117 be able to run. | 145 be able to run. |
| 118 | 146 |
| 119 This needs to be run after gyp has been run so that the expected target | 147 This needs to be run after gyp has been run so that the expected target |
| 120 output directories are already created. | 148 output directories are already created. |
| 149 |
| 150 This is used for the GYP build and gclient runhooks. |
| 121 """ | 151 """ |
| 122 x86, x64 = runtime_dirs | 152 x86, x64 = runtime_dirs |
| 123 out_debug = os.path.join(output_dir, 'Debug') | 153 out_debug = os.path.join(output_dir, 'Debug') |
| 124 out_debug_nacl64 = os.path.join(output_dir, 'Debug', 'x64') | 154 out_debug_nacl64 = os.path.join(output_dir, 'Debug', 'x64') |
| 125 out_release = os.path.join(output_dir, 'Release') | 155 out_release = os.path.join(output_dir, 'Release') |
| 126 out_release_nacl64 = os.path.join(output_dir, 'Release', 'x64') | 156 out_release_nacl64 = os.path.join(output_dir, 'Release', 'x64') |
| 127 out_debug_x64 = os.path.join(output_dir, 'Debug_x64') | 157 out_debug_x64 = os.path.join(output_dir, 'Debug_x64') |
| 128 out_release_x64 = os.path.join(output_dir, 'Release_x64') | 158 out_release_x64 = os.path.join(output_dir, 'Release_x64') |
| 129 | 159 |
| 130 if os.path.exists(out_debug) and not os.path.exists(out_debug_nacl64): | 160 if os.path.exists(out_debug) and not os.path.exists(out_debug_nacl64): |
| 131 os.makedirs(out_debug_nacl64) | 161 os.makedirs(out_debug_nacl64) |
| 132 if os.path.exists(out_release) and not os.path.exists(out_release_nacl64): | 162 if os.path.exists(out_release) and not os.path.exists(out_release_nacl64): |
| 133 os.makedirs(out_release_nacl64) | 163 os.makedirs(out_release_nacl64) |
| 134 if os.environ.get('GYP_MSVS_VERSION') == '2015': | 164 _CopyRuntime(out_debug, x86, "x86", debug=True) |
| 135 _CopyRuntime2015(out_debug, x86, '%s140d.dll') | 165 _CopyRuntime(out_release, x86, "x86", debug=False) |
| 136 _CopyRuntime2015(out_release, x86, '%s140.dll') | 166 _CopyRuntime(out_debug_x64, x64, "x64", debug=True) |
| 137 _CopyRuntime2015(out_debug_x64, x64, '%s140d.dll') | 167 _CopyRuntime(out_release_x64, x64, "x64", debug=False) |
| 138 _CopyRuntime2015(out_release_x64, x64, '%s140.dll') | 168 _CopyRuntime(out_debug_nacl64, x64, "x64", debug=True) |
| 139 _CopyRuntime2015(out_debug_nacl64, x64, '%s140d.dll') | 169 _CopyRuntime(out_release_nacl64, x64, "x64", debug=False) |
| 140 _CopyRuntime2015(out_release_nacl64, x64, '%s140.dll') | |
| 141 else: | |
| 142 # VS2013 is the default. | |
| 143 _CopyRuntime2013(out_debug, x86, 'msvc%s120d.dll') | |
| 144 _CopyRuntime2013(out_release, x86, 'msvc%s120.dll') | |
| 145 _CopyRuntime2013(out_debug_x64, x64, 'msvc%s120d.dll') | |
| 146 _CopyRuntime2013(out_release_x64, x64, 'msvc%s120.dll') | |
| 147 _CopyRuntime2013(out_debug_nacl64, x64, 'msvc%s120d.dll') | |
| 148 _CopyRuntime2013(out_release_nacl64, x64, 'msvc%s120.dll') | |
| 149 | |
| 150 # Copy the PGO runtime library to the release directories. | |
| 151 if os.environ.get('GYP_MSVS_OVERRIDE_PATH'): | |
| 152 pgo_x86_runtime_dir = os.path.join(os.environ.get('GYP_MSVS_OVERRIDE_PATH'), | |
| 153 'VC', 'bin') | |
| 154 pgo_x64_runtime_dir = os.path.join(pgo_x86_runtime_dir, 'amd64') | |
| 155 pgo_runtime_dll = 'pgort' + _VersionNumber() + '.dll' | |
| 156 source_x86 = os.path.join(pgo_x86_runtime_dir, pgo_runtime_dll) | |
| 157 if os.path.exists(source_x86): | |
| 158 _CopyRuntimeImpl(os.path.join(out_release, pgo_runtime_dll), source_x86) | |
| 159 source_x64 = os.path.join(pgo_x64_runtime_dir, pgo_runtime_dll) | |
| 160 if os.path.exists(source_x64): | |
| 161 _CopyRuntimeImpl(os.path.join(out_release_x64, pgo_runtime_dll), | |
| 162 source_x64) | |
| 163 | 170 |
| 164 | 171 |
| 165 def CopyDlls(target_dir, configuration, target_cpu): | 172 def CopyDlls(target_dir, configuration, target_cpu): |
| 166 """Copy the VS runtime DLLs into the requested directory as needed. | 173 """Copy the VS runtime DLLs into the requested directory as needed. |
| 167 | 174 |
| 168 configuration is one of 'Debug' or 'Release'. | 175 configuration is one of 'Debug' or 'Release'. |
| 169 target_cpu is one of 'x86' or 'x64'. | 176 target_cpu is one of 'x86' or 'x64'. |
| 170 | 177 |
| 171 The debug configuration gets both the debug and release DLLs; the | 178 The debug configuration gets both the debug and release DLLs; the |
| 172 release config only the latter. | 179 release config only the latter. |
| 180 |
| 181 This is used for the GN build. |
| 173 """ | 182 """ |
| 174 vs2013_runtime_dll_dirs = SetEnvironmentAndGetRuntimeDllDirs() | 183 vs_runtime_dll_dirs = SetEnvironmentAndGetRuntimeDllDirs() |
| 175 if not vs2013_runtime_dll_dirs: | 184 if not vs_runtime_dll_dirs: |
| 176 return | 185 return |
| 177 | 186 |
| 178 x64_runtime, x86_runtime = vs2013_runtime_dll_dirs | 187 x64_runtime, x86_runtime = vs_runtime_dll_dirs |
| 179 runtime_dir = x64_runtime if target_cpu == 'x64' else x86_runtime | 188 runtime_dir = x64_runtime if target_cpu == 'x64' else x86_runtime |
| 180 _CopyRuntime2013( | 189 _CopyRuntime(target_dir, runtime_dir, target_cpu, debug=False) |
| 181 target_dir, runtime_dir, 'msvc%s' + _VersionNumber() + '.dll') | |
| 182 if configuration == 'Debug': | 190 if configuration == 'Debug': |
| 183 _CopyRuntime2013( | 191 _CopyRuntime(target_dir, runtime_dir, target_cpu, debug=True) |
| 184 target_dir, runtime_dir, 'msvc%s' + _VersionNumber() + 'd.dll') | |
| 185 | 192 |
| 186 | 193 |
| 187 def _GetDesiredVsToolchainHashes(): | 194 def _GetDesiredVsToolchainHashes(): |
| 188 """Load a list of SHA1s corresponding to the toolchains that we want installed | 195 """Load a list of SHA1s corresponding to the toolchains that we want installed |
| 189 to build with.""" | 196 to build with.""" |
| 190 if os.environ.get('GYP_MSVS_VERSION') == '2015': | 197 if os.environ.get('GYP_MSVS_VERSION') == '2015': |
| 191 return ['49ae4b60d898182fc3f521c2fcda82c453915011'] | 198 return ['49ae4b60d898182fc3f521c2fcda82c453915011'] |
| 192 else: | 199 else: |
| 193 # Default to VS2013. | 200 # Default to VS2013. |
| 194 return ['ee7d718ec60c2dc5d255bbe325909c2021a7efef'] | 201 return ['ee7d718ec60c2dc5d255bbe325909c2021a7efef'] |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 'copy_dlls': CopyDlls, | 263 'copy_dlls': CopyDlls, |
| 257 } | 264 } |
| 258 if len(sys.argv) < 2 or sys.argv[1] not in commands: | 265 if len(sys.argv) < 2 or sys.argv[1] not in commands: |
| 259 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) | 266 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands) |
| 260 return 1 | 267 return 1 |
| 261 return commands[sys.argv[1]](*sys.argv[2:]) | 268 return commands[sys.argv[1]](*sys.argv[2:]) |
| 262 | 269 |
| 263 | 270 |
| 264 if __name__ == '__main__': | 271 if __name__ == '__main__': |
| 265 sys.exit(main()) | 272 sys.exit(main()) |
| OLD | NEW |