blob: e131a0db2b428084884a72ac7caaca4ddb378a1d [file] [log] [blame]
thakis4f4b1372015-08-11 22:25:001#!/usr/bin/env python
[email protected]4e8a2472014-03-19 22:01:392# Copyright 2014 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
brucedawsond5273dd2016-02-09 04:27:526import glob
[email protected]4e8a2472014-03-19 22:01:397import json
8import os
9import pipes
brucedawsone7bd0342016-06-01 18:37:1810import platform
sebmarchand79a9cbd2017-05-12 15:29:2611import re
[email protected]4e8a2472014-03-19 22:01:3912import shutil
brucedawsone7bd0342016-06-01 18:37:1813import stat
[email protected]4e8a2472014-03-19 22:01:3914import subprocess
15import sys
[email protected]4e8a2472014-03-19 22:01:3916
17
18script_dir = os.path.dirname(os.path.realpath(__file__))
19chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir))
20SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
[email protected]4e8a2472014-03-19 22:01:3921sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib'))
[email protected]c71d3282014-04-09 01:56:2022json_data_file = os.path.join(script_dir, 'win_toolchain.json')
[email protected]4e8a2472014-03-19 22:01:3923
24
thakis5ea57992017-05-29 15:14:3025# Use MSVS2015 as the default toolchain.
brucedawsoneb339abb2017-06-18 23:25:5026CURRENT_DEFAULT_TOOLCHAIN_VERSION = '2015'
sebmarchande44b02e2016-01-15 22:29:5727
28
[email protected]c71d3282014-04-09 01:56:2029def SetEnvironmentAndGetRuntimeDllDirs():
30 """Sets up os.environ to use the depot_tools VS toolchain with gyp, and
31 returns the location of the VS runtime DLLs so they can be copied into
32 the output directory after gyp generation.
brucedawsone7bd0342016-06-01 18:37:1833
34 Return value is [x64path, x86path] or None
[email protected]4e8a2472014-03-19 22:01:3935 """
brucedawsonaaff8dc2015-11-21 02:21:5236 vs_runtime_dll_dirs = None
[email protected]4e8a2472014-03-19 22:01:3937 depot_tools_win_toolchain = \
38 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1')))
thakis4f4b1372015-08-11 22:25:0039 # When running on a non-Windows host, only do this if the SDK has explicitly
40 # been downloaded before (in which case json_data_file will exist).
scottmg05eac9c02015-08-25 23:03:3541 if ((sys.platform in ('win32', 'cygwin') or os.path.exists(json_data_file))
42 and depot_tools_win_toolchain):
sebmarchande44b02e2016-01-15 22:29:5743 if ShouldUpdateToolchain():
[email protected]9372bec2014-08-14 14:03:3044 Update()
[email protected]c71d3282014-04-09 01:56:2045 with open(json_data_file, 'r') as tempf:
[email protected]4e8a2472014-03-19 22:01:3946 toolchain_data = json.load(tempf)
[email protected]4e8a2472014-03-19 22:01:3947
48 toolchain = toolchain_data['path']
49 version = toolchain_data['version']
scottmg54e45062015-06-02 01:15:4450 win_sdk = toolchain_data.get('win_sdk')
51 if not win_sdk:
52 win_sdk = toolchain_data['win8sdk']
[email protected]4e8a2472014-03-19 22:01:3953 wdk = toolchain_data['wdk']
54 # TODO(scottmg): The order unfortunately matters in these. They should be
sebmarchand79a9cbd2017-05-12 15:29:2655 # split into separate keys for x86 and x64. (See CopyDlls call below).
56 # http://crbug.com/345992
brucedawsonaaff8dc2015-11-21 02:21:5257 vs_runtime_dll_dirs = toolchain_data['runtime_dirs']
[email protected]4e8a2472014-03-19 22:01:3958
59 os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain
60 os.environ['GYP_MSVS_VERSION'] = version
thestig9b24fa52017-03-11 01:46:4261
62 # Limit the scope of the gyp import to only where it is used. This
63 # potentially lets build configs that never execute this block to drop
64 # their GYP checkout.
65 import gyp
66
[email protected]4e8a2472014-03-19 22:01:3967 # We need to make sure windows_sdk_path is set to the automated
68 # toolchain values in GYP_DEFINES, but don't want to override any
69 # otheroptions.express
70 # values there.
71 gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES'))
scottmg54e45062015-06-02 01:15:4472 gyp_defines_dict['windows_sdk_path'] = win_sdk
[email protected]4e8a2472014-03-19 22:01:3973 os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v)))
74 for k, v in gyp_defines_dict.iteritems())
thestig9b24fa52017-03-11 01:46:4275
scottmg54e45062015-06-02 01:15:4476 os.environ['WINDOWSSDKDIR'] = win_sdk
[email protected]4e8a2472014-03-19 22:01:3977 os.environ['WDK_DIR'] = wdk
78 # Include the VS runtime in the PATH in case it's not machine-installed.
thakis44a40f82016-02-15 18:18:0179 runtime_path = os.path.pathsep.join(vs_runtime_dll_dirs)
80 os.environ['PATH'] = runtime_path + os.path.pathsep + os.environ['PATH']
bratellc7af8792016-01-07 16:30:1281 elif sys.platform == 'win32' and not depot_tools_win_toolchain:
82 if not 'GYP_MSVS_OVERRIDE_PATH' in os.environ:
83 os.environ['GYP_MSVS_OVERRIDE_PATH'] = DetectVisualStudioPath()
lwchkg833a437f2016-01-19 00:39:0884 if not 'GYP_MSVS_VERSION' in os.environ:
85 os.environ['GYP_MSVS_VERSION'] = GetVisualStudioVersion()
bratellc7af8792016-01-07 16:30:1286
brucedawsone7bd0342016-06-01 18:37:1887 # When using an installed toolchain these files aren't needed in the output
88 # directory in order to run binaries locally, but they are needed in order
89 # to create isolates or the mini_installer. Copying them to the output
90 # directory ensures that they are available when needed.
91 bitness = platform.architecture()[0]
92 # When running 64-bit python the x64 DLLs will be in System32
93 x64_path = 'System32' if bitness == '64bit' else 'Sysnative'
94 x64_path = os.path.join(r'C:\Windows', x64_path)
95 vs_runtime_dll_dirs = [x64_path, r'C:\Windows\SysWOW64']
96
brucedawsonaaff8dc2015-11-21 02:21:5297 return vs_runtime_dll_dirs
[email protected]4e8a2472014-03-19 22:01:3998
99
bratellc7af8792016-01-07 16:30:12100def _RegistryGetValueUsingWinReg(key, value):
101 """Use the _winreg module to obtain the value of a registry key.
102
103 Args:
104 key: The registry key.
105 value: The particular registry value to read.
106 Return:
107 contents of the registry key's value, or None on failure. Throws
108 ImportError if _winreg is unavailable.
109 """
110 import _winreg
111 try:
112 root, subkey = key.split('\\', 1)
113 assert root == 'HKLM' # Only need HKLM for now.
114 with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, subkey) as hkey:
115 return _winreg.QueryValueEx(hkey, value)[0]
116 except WindowsError:
117 return None
118
119
120def _RegistryGetValue(key, value):
121 try:
122 return _RegistryGetValueUsingWinReg(key, value)
123 except ImportError:
124 raise Exception('The python library _winreg not found.')
125
126
halton.huo815e1772016-01-13 02:23:30127def GetVisualStudioVersion():
sebmarchande44b02e2016-01-15 22:29:57128 """Return GYP_MSVS_VERSION of Visual Studio.
halton.huo815e1772016-01-13 02:23:30129 """
sebmarchande44b02e2016-01-15 22:29:57130 return os.environ.get('GYP_MSVS_VERSION', CURRENT_DEFAULT_TOOLCHAIN_VERSION)
halton.huo815e1772016-01-13 02:23:30131
132
bratellc7af8792016-01-07 16:30:12133def DetectVisualStudioPath():
134 """Return path to the GYP_MSVS_VERSION of Visual Studio.
135 """
136
137 # Note that this code is used from
138 # build/toolchain/win/setup_toolchain.py as well.
halton.huo815e1772016-01-13 02:23:30139 version_as_year = GetVisualStudioVersion()
bratellc7af8792016-01-07 16:30:12140 year_to_version = {
bratellc7af8792016-01-07 16:30:12141 '2015': '14.0',
brucedawsonadddab42017-01-23 06:57:21142 '2017': '15.0',
bratellc7af8792016-01-07 16:30:12143 }
144 if version_as_year not in year_to_version:
145 raise Exception(('Visual Studio version %s (from GYP_MSVS_VERSION)'
146 ' not supported. Supported versions are: %s') % (
147 version_as_year, ', '.join(year_to_version.keys())))
148 version = year_to_version[version_as_year]
brucedawsonadddab42017-01-23 06:57:21149 if version_as_year == '2017':
150 # The VC++ 2017 install location needs to be located using COM instead of
151 # the registry. For details see:
152 # https://blogs.msdn.microsoft.com/heaths/2016/09/15/changes-to-visual-studio-15-setup/
153 # For now we use a hardcoded default with an environment variable override.
drbasic461b3292017-04-14 02:13:01154 for path in (
155 os.environ.get('vs2017_install'),
156 r'C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional',
157 r'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community'):
158 if path and os.path.exists(path):
159 return path
brucedawsonadddab42017-01-23 06:57:21160 else:
161 keys = [r'HKLM\Software\Microsoft\VisualStudio\%s' % version,
162 r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\%s' % version]
163 for key in keys:
164 path = _RegistryGetValue(key, 'InstallDir')
165 if not path:
166 continue
167 path = os.path.normpath(os.path.join(path, '..', '..'))
168 return path
bratellc7af8792016-01-07 16:30:12169
170 raise Exception(('Visual Studio Version %s (from GYP_MSVS_VERSION)'
171 ' not found.') % (version_as_year))
172
173
brucedawsond5273dd2016-02-09 04:27:52174def _CopyRuntimeImpl(target, source, verbose=True):
gab381d9f172016-04-18 15:29:14175 """Copy |source| to |target| if it doesn't already exist or if it needs to be
176 updated (comparing last modified time as an approximate float match as for
177 some reason the values tend to differ by ~1e-07 despite being copies of the
178 same file... https://crbug.com/603603).
dpranke0b951952014-11-15 00:09:14179 """
180 if (os.path.isdir(os.path.dirname(target)) and
181 (not os.path.isfile(target) or
gab381d9f172016-04-18 15:29:14182 abs(os.stat(target).st_mtime - os.stat(source).st_mtime) >= 0.01)):
brucedawsond5273dd2016-02-09 04:27:52183 if verbose:
184 print 'Copying %s to %s...' % (source, target)
dpranke0b951952014-11-15 00:09:14185 if os.path.exists(target):
brucedawsone7bd0342016-06-01 18:37:18186 # Make the file writable so that we can delete it now.
187 os.chmod(target, stat.S_IWRITE)
dpranke0b951952014-11-15 00:09:14188 os.unlink(target)
189 shutil.copy2(source, target)
brucedawsone7bd0342016-06-01 18:37:18190 # Make the file writable so that we can overwrite or delete it later.
191 os.chmod(target, stat.S_IWRITE)
dpranke0b951952014-11-15 00:09:14192
193
brucedawson46cd6d932017-03-13 21:12:31194def _CopyUCRTRuntime(target_dir, source_dir, target_cpu, dll_pattern, suffix):
scottmg54e45062015-06-02 01:15:44195 """Copy both the msvcp and vccorlib runtime DLLs, only if the target doesn't
196 exist, but the target directory does exist."""
sebmarchand7cebe212015-12-17 20:44:35197 for file_part in ('msvcp', 'vccorlib', 'vcruntime'):
scottmg54e45062015-06-02 01:15:44198 dll = dll_pattern % file_part
199 target = os.path.join(target_dir, dll)
200 source = os.path.join(source_dir, dll)
201 _CopyRuntimeImpl(target, source)
brucedawson46cd6d932017-03-13 21:12:31202 # Copy the UCRT files needed by VS 2015 from the Windows SDK. This location
203 # includes the api-ms-win-crt-*.dll files that are not found in the Windows
204 # directory. These files are needed for component builds.
205 # If WINDOWSSDKDIR is not set use the default SDK path. This will be the case
206 # when DEPOT_TOOLS_WIN_TOOLCHAIN=0 and vcvarsall.bat has not been run.
207 win_sdk_dir = os.path.normpath(
208 os.environ.get('WINDOWSSDKDIR',
209 'C:\\Program Files (x86)\\Windows Kits\\10'))
210 ucrt_dll_dirs = os.path.join(win_sdk_dir, r'Redist\ucrt\DLLs', target_cpu)
211 ucrt_files = glob.glob(os.path.join(ucrt_dll_dirs, 'api-ms-win-*.dll'))
brucedawsone7bd0342016-06-01 18:37:18212 assert len(ucrt_files) > 0
213 for ucrt_src_file in ucrt_files:
brucedawsonc6f6c692016-02-22 23:09:18214 file_part = os.path.basename(ucrt_src_file)
215 ucrt_dst_file = os.path.join(target_dir, file_part)
216 _CopyRuntimeImpl(ucrt_dst_file, ucrt_src_file, False)
217 _CopyRuntimeImpl(os.path.join(target_dir, 'ucrtbase' + suffix),
218 os.path.join(source_dir, 'ucrtbase' + suffix))
dpranke0b951952014-11-15 00:09:14219
220
sebmarchandab3a1822017-05-20 15:00:06221def FindVCToolsRoot():
222 """In VS2017 the PGO runtime dependencies are located in
223 {toolchain_root}/VC/Tools/MSVC/{x.y.z}/bin/Host{target_cpu}/{target_cpu}/, the
224 {version_number} part is likely to change in case of a minor update of the
225 toolchain so we don't hardcode this value here (except for the major number).
226
227 This returns the '{toolchain_root}/VC/Tools/MSVC/{x.y.z}/bin/' path.
228
229 This function should only be called when using VS2017.
230 """
231 assert GetVisualStudioVersion() == '2017'
sebmarchandf44f50c2017-05-23 02:08:31232 SetEnvironmentAndGetRuntimeDllDirs()
sebmarchandab3a1822017-05-20 15:00:06233 assert ('GYP_MSVS_OVERRIDE_PATH' in os.environ)
234 vc_tools_msvc_root = os.path.join(os.environ['GYP_MSVS_OVERRIDE_PATH'],
235 'VC', 'Tools', 'MSVC')
236 for directory in os.listdir(vc_tools_msvc_root):
237 if not os.path.isdir(os.path.join(vc_tools_msvc_root, directory)):
238 continue
239 if re.match('14\.\d+\.\d+', directory):
240 return os.path.join(vc_tools_msvc_root, directory, 'bin')
241 raise Exception('Unable to find the VC tools directory.')
242
243
sebmarchand79a9cbd2017-05-12 15:29:26244def _CopyPGORuntime(target_dir, target_cpu):
245 """Copy the runtime dependencies required during a PGO build.
246 """
247 env_version = GetVisualStudioVersion()
248 # These dependencies will be in a different location depending on the version
249 # of the toolchain.
250 if env_version == '2015':
251 pgo_x86_runtime_dir = os.path.join(os.environ.get('GYP_MSVS_OVERRIDE_PATH'),
252 'VC', 'bin')
253 pgo_x64_runtime_dir = os.path.join(pgo_x86_runtime_dir, 'amd64')
254 elif env_version == '2017':
sebmarchandab3a1822017-05-20 15:00:06255 pgo_runtime_root = FindVCToolsRoot()
sebmarchand79a9cbd2017-05-12 15:29:26256 assert pgo_runtime_root
257 # There's no version of pgosweep.exe in HostX64/x86, so we use the copy
258 # from HostX86/x86.
259 pgo_x86_runtime_dir = os.path.join(pgo_runtime_root, 'HostX86', 'x86')
260 pgo_x64_runtime_dir = os.path.join(pgo_runtime_root, 'HostX64', 'x64')
261 else:
262 raise Exception('Unexpected toolchain version: %s.' % env_version)
263
264 # We need to copy 2 runtime dependencies used during the profiling step:
265 # - pgort140.dll: runtime library required to run the instrumented image.
266 # - pgosweep.exe: executable used to collect the profiling data
267 pgo_runtimes = ['pgort140.dll', 'pgosweep.exe']
268 for runtime in pgo_runtimes:
269 if target_cpu == 'x86':
270 source = os.path.join(pgo_x86_runtime_dir, runtime)
271 elif target_cpu == 'x64':
272 source = os.path.join(pgo_x64_runtime_dir, runtime)
273 else:
274 raise NotImplementedError("Unexpected target_cpu value: " + target_cpu)
275 if not os.path.exists(source):
276 raise Exception('Unable to find %s.' % source)
277 _CopyRuntimeImpl(os.path.join(target_dir, runtime), source)
278
279
brucedawsonaaff8dc2015-11-21 02:21:52280def _CopyRuntime(target_dir, source_dir, target_cpu, debug):
281 """Copy the VS runtime DLLs, only if the target doesn't exist, but the target
brucedawsone7c0d992017-03-27 20:59:15282 directory does exist. Handles VS 2015 and VS 2017."""
brucedawsonaaff8dc2015-11-21 02:21:52283 suffix = "d.dll" if debug else ".dll"
brucedawsone7c0d992017-03-27 20:59:15284 # VS 2017 uses the same CRT DLLs as VS 2015.
285 _CopyUCRTRuntime(target_dir, source_dir, target_cpu, '%s140' + suffix,
286 suffix)
brucedawsonaaff8dc2015-11-21 02:21:52287
dpranke0b951952014-11-15 00:09:14288
dpranke43276212015-02-20 02:55:19289def CopyDlls(target_dir, configuration, target_cpu):
dpranke0b951952014-11-15 00:09:14290 """Copy the VS runtime DLLs into the requested directory as needed.
291
292 configuration is one of 'Debug' or 'Release'.
dpranke43276212015-02-20 02:55:19293 target_cpu is one of 'x86' or 'x64'.
dpranke0b951952014-11-15 00:09:14294
295 The debug configuration gets both the debug and release DLLs; the
296 release config only the latter.
297 """
brucedawsonaaff8dc2015-11-21 02:21:52298 vs_runtime_dll_dirs = SetEnvironmentAndGetRuntimeDllDirs()
299 if not vs_runtime_dll_dirs:
dpranke0b951952014-11-15 00:09:14300 return
301
brucedawsonaaff8dc2015-11-21 02:21:52302 x64_runtime, x86_runtime = vs_runtime_dll_dirs
dpranke43276212015-02-20 02:55:19303 runtime_dir = x64_runtime if target_cpu == 'x64' else x86_runtime
brucedawsonaaff8dc2015-11-21 02:21:52304 _CopyRuntime(target_dir, runtime_dir, target_cpu, debug=False)
dpranke0b951952014-11-15 00:09:14305 if configuration == 'Debug':
brucedawsonaaff8dc2015-11-21 02:21:52306 _CopyRuntime(target_dir, runtime_dir, target_cpu, debug=True)
sebmarchand79a9cbd2017-05-12 15:29:26307 else:
308 _CopyPGORuntime(target_dir, target_cpu)
[email protected]33222522014-07-22 00:18:32309
brucedawson6db4113f2017-04-19 22:27:40310 _CopyDebugger(target_dir, target_cpu)
311
312
313def _CopyDebugger(target_dir, target_cpu):
sebmarchand47525892017-06-29 22:24:39314 """Copy dbghelp.dll and dbgcore.dll into the requested directory as needed.
brucedawson6db4113f2017-04-19 22:27:40315
316 target_cpu is one of 'x86' or 'x64'.
317
318 dbghelp.dll is used when Chrome needs to symbolize stacks. Copying this file
319 from the SDK directory avoids using the system copy of dbghelp.dll which then
320 ensures compatibility with recent debug information formats, such as VS
321 2017 /debug:fastlink PDBs.
sebmarchand47525892017-06-29 22:24:39322
323 dbgcore.dll is needed when using some functions from dbghelp.dll (like
324 MinidumpWriteDump).
brucedawson6db4113f2017-04-19 22:27:40325 """
326 win_sdk_dir = SetEnvironmentAndGetSDKDir()
327 if not win_sdk_dir:
328 return
329
sebmarchand47525892017-06-29 22:24:39330 debug_files = ['dbghelp.dll', 'dbgcore.dll']
331 for debug_file in debug_files:
332 full_path = os.path.join(win_sdk_dir, 'Debuggers', target_cpu, debug_file)
333 if not os.path.exists(full_path):
334 raise Exception('%s not found in "%s"\r\nYou must install the '
335 '"Debugging Tools for Windows" feature from the Windows '
336 '10 SDK.' % (debug_file, full_path))
337 target_path = os.path.join(target_dir, debug_file)
338 _CopyRuntimeImpl(target_path, full_path)
brucedawson6db4113f2017-04-19 22:27:40339
[email protected]4e8a2472014-03-19 22:01:39340
[email protected]c71d3282014-04-09 01:56:20341def _GetDesiredVsToolchainHashes():
342 """Load a list of SHA1s corresponding to the toolchains that we want installed
343 to build with."""
thestig9b24fa52017-03-11 01:46:42344 env_version = GetVisualStudioVersion()
thestig9b24fa52017-03-11 01:46:42345 if env_version == '2015':
brucedawson48c3f86f2017-06-22 17:40:42346 # Update 3 final with 10.0.15063.468 SDK and no vctip.exe.
347 return ['f53e4598951162bad6330f7a167486c7ae5db1e5']
brucedawson560bb952017-03-24 23:10:01348 if env_version == '2017':
brucedawson64603712017-06-15 00:31:12349 # VS 2017 Update 3 Preview 2 with 10.0.15063.0 SDK and patched event.h.
350 return ['425bd64734a387734dfcf445b285a7c5073e4262']
thestig9b24fa52017-03-11 01:46:42351 raise Exception('Unsupported VS version %s' % env_version)
[email protected]c71d3282014-04-09 01:56:20352
353
sebmarchande44b02e2016-01-15 22:29:57354def ShouldUpdateToolchain():
355 """Check if the toolchain should be upgraded."""
356 if not os.path.exists(json_data_file):
357 return True
358 with open(json_data_file, 'r') as tempf:
359 toolchain_data = json.load(tempf)
360 version = toolchain_data['version']
361 env_version = GetVisualStudioVersion()
362 # If there's a mismatch between the version set in the environment and the one
363 # in the json file then the toolchain should be updated.
364 return version != env_version
365
366
thakis4f4b1372015-08-11 22:25:00367def Update(force=False):
[email protected]c71d3282014-04-09 01:56:20368 """Requests an update of the toolchain to the specific hashes we have at
369 this revision. The update outputs a .json of the various configuration
370 information required to pass to gyp which we use in |GetToolchainDir()|.
371 """
thakis4f4b1372015-08-11 22:25:00372 if force != False and force != '--force':
373 print >>sys.stderr, 'Unknown parameter "%s"' % force
374 return 1
375 if force == '--force' or os.path.exists(json_data_file):
376 force = True
377
[email protected]c71d3282014-04-09 01:56:20378 depot_tools_win_toolchain = \
379 bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1')))
thakis4f4b1372015-08-11 22:25:00380 if ((sys.platform in ('win32', 'cygwin') or force) and
381 depot_tools_win_toolchain):
[email protected]c71d3282014-04-09 01:56:20382 import find_depot_tools
383 depot_tools_path = find_depot_tools.add_depot_tools_to_path()
brucedawson2b33e7e2016-03-11 19:55:25384 # Necessary so that get_toolchain_if_necessary.py will put the VS toolkit
385 # in the correct directory.
386 os.environ['GYP_MSVS_VERSION'] = GetVisualStudioVersion()
[email protected]c71d3282014-04-09 01:56:20387 get_toolchain_args = [
388 sys.executable,
389 os.path.join(depot_tools_path,
390 'win_toolchain',
391 'get_toolchain_if_necessary.py'),
392 '--output-json', json_data_file,
393 ] + _GetDesiredVsToolchainHashes()
thakis4f4b1372015-08-11 22:25:00394 if force:
395 get_toolchain_args.append('--force')
[email protected]c71d3282014-04-09 01:56:20396 subprocess.check_call(get_toolchain_args)
397
[email protected]4e8a2472014-03-19 22:01:39398 return 0
399
[email protected]ffe205622014-03-20 17:42:25400
brucedawson12bbca42016-03-23 00:58:06401def NormalizePath(path):
402 while path.endswith("\\"):
403 path = path[:-1]
404 return path
405
406
jochen6c29ace2017-02-15 22:45:26407def SetEnvironmentAndGetSDKDir():
408 """Gets location information about the current sdk (must have been
[email protected]308a6cae2014-05-28 20:32:01409 previously updated by 'update'). This is used for the GN build."""
tikuta6d749aec2017-05-02 06:12:31410 SetEnvironmentAndGetRuntimeDllDirs()
ckocagilfc8d7f232014-09-30 19:31:43411
412 # If WINDOWSSDKDIR is not set, search the default SDK path and set it.
413 if not 'WINDOWSSDKDIR' in os.environ:
brucedawson953e3762016-01-21 23:35:35414 default_sdk_path = 'C:\\Program Files (x86)\\Windows Kits\\10'
ckocagilfc8d7f232014-09-30 19:31:43415 if os.path.isdir(default_sdk_path):
416 os.environ['WINDOWSSDKDIR'] = default_sdk_path
417
jochen6c29ace2017-02-15 22:45:26418 return NormalizePath(os.environ['WINDOWSSDKDIR'])
419
420
421def GetToolchainDir():
422 """Gets location information about the current toolchain (must have been
423 previously updated by 'update'). This is used for the GN build."""
424 runtime_dll_dirs = SetEnvironmentAndGetRuntimeDllDirs()
425 win_sdk_dir = SetEnvironmentAndGetSDKDir()
426
[email protected]308a6cae2014-05-28 20:32:01427 print '''vs_path = "%s"
428sdk_path = "%s"
429vs_version = "%s"
430wdk_dir = "%s"
scottmg9bf8fb32014-11-19 19:33:28431runtime_dirs = "%s"
[email protected]308a6cae2014-05-28 20:32:01432''' % (
brucedawson12bbca42016-03-23 00:58:06433 NormalizePath(os.environ['GYP_MSVS_OVERRIDE_PATH']),
jochen6c29ace2017-02-15 22:45:26434 win_sdk_dir,
halton.huo815e1772016-01-13 02:23:30435 GetVisualStudioVersion(),
brucedawson12bbca42016-03-23 00:58:06436 NormalizePath(os.environ.get('WDK_DIR', '')),
thakis44a40f82016-02-15 18:18:01437 os.path.pathsep.join(runtime_dll_dirs or ['None']))
[email protected]c71d3282014-04-09 01:56:20438
439
440def main():
[email protected]c71d3282014-04-09 01:56:20441 commands = {
442 'update': Update,
443 'get_toolchain_dir': GetToolchainDir,
dpranke0b951952014-11-15 00:09:14444 'copy_dlls': CopyDlls,
[email protected]c71d3282014-04-09 01:56:20445 }
446 if len(sys.argv) < 2 or sys.argv[1] not in commands:
447 print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands)
448 return 1
dpranke0b951952014-11-15 00:09:14449 return commands[sys.argv[1]](*sys.argv[2:])
[email protected]c71d3282014-04-09 01:56:20450
451
[email protected]4e8a2472014-03-19 22:01:39452if __name__ == '__main__':
453 sys.exit(main())