summaryrefslogtreecommitdiff
path: root/chromium/build/vs_toolchain.py
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/build/vs_toolchain.py')
-rwxr-xr-xchromium/build/vs_toolchain.py118
1 files changed, 96 insertions, 22 deletions
diff --git a/chromium/build/vs_toolchain.py b/chromium/build/vs_toolchain.py
index 32bad7f469b..e613b88e535 100755
--- a/chromium/build/vs_toolchain.py
+++ b/chromium/build/vs_toolchain.py
@@ -13,6 +13,7 @@ import shutil
import stat
import subprocess
import sys
+
from gn_helpers import ToGNString
@@ -26,10 +27,12 @@ CURRENT_DEFAULT_TOOLCHAIN_VERSION = '2017'
def SetEnvironmentAndGetRuntimeDllDirs():
"""Sets up os.environ to use the depot_tools VS toolchain with gyp, and
- returns the location of the VS runtime DLLs so they can be copied into
+ returns the location of the VC runtime DLLs so they can be copied into
the output directory after gyp generation.
- Return value is [x64path, x86path] or None
+ Return value is [x64path, x86path, 'Arm64Unused'] or None. arm64path is
+ generated separately because there are multiple folders for the arm64 VC
+ runtime.
"""
vs_runtime_dll_dirs = None
depot_tools_win_toolchain = \
@@ -52,9 +55,14 @@ def SetEnvironmentAndGetRuntimeDllDirs():
win_sdk = toolchain_data['win8sdk']
wdk = toolchain_data['wdk']
# TODO(scottmg): The order unfortunately matters in these. They should be
- # split into separate keys for x86 and x64. (See CopyDlls call below).
+ # split into separate keys for x64/x86/arm64. (See CopyDlls call below).
# http://crbug.com/345992
vs_runtime_dll_dirs = toolchain_data['runtime_dirs']
+ # The number of runtime_dirs in the toolchain_data was two (x64/x86) but
+ # changed to three (x64/x86/arm64) and this code needs to handle both
+ # possibilities, which can change independently from this code.
+ if len(vs_runtime_dll_dirs) == 2:
+ vs_runtime_dll_dirs.append('Arm64Unused')
os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain
os.environ['GYP_MSVS_VERSION'] = version
@@ -76,9 +84,14 @@ def SetEnvironmentAndGetRuntimeDllDirs():
# directory ensures that they are available when needed.
bitness = platform.architecture()[0]
# When running 64-bit python the x64 DLLs will be in System32
+ # ARM64 binaries will not be available in the system directories because we
+ # don't build on ARM64 machines.
x64_path = 'System32' if bitness == '64bit' else 'Sysnative'
x64_path = os.path.join(os.path.expandvars('%windir%'), x64_path)
- vs_runtime_dll_dirs = [x64_path, os.path.expandvars('%windir%/SysWOW64')]
+ vs_runtime_dll_dirs = [x64_path,
+ os.path.join(os.path.expandvars('%windir%'),
+ 'SysWOW64'),
+ 'Arm64Unused']
return vs_runtime_dll_dirs
@@ -130,7 +143,6 @@ def DetectVisualStudioPath():
raise Exception(('Visual Studio version %s (from GYP_MSVS_VERSION)'
' not supported. Supported versions are: %s') % (
version_as_year, ', '.join(year_to_version.keys())))
- version = year_to_version[version_as_year]
if version_as_year == '2017':
# The VC++ 2017 install location needs to be located using COM instead of
# the registry. For details see:
@@ -176,6 +188,16 @@ def _CopyRuntimeImpl(target, source, verbose=True):
def _CopyUCRTRuntime(target_dir, source_dir, target_cpu, dll_pattern, suffix):
"""Copy both the msvcp and vccorlib runtime DLLs, only if the target doesn't
exist, but the target directory does exist."""
+ if target_cpu == 'arm64':
+ # Windows ARM64 VCRuntime is located at {toolchain_root}/VC/Redist/MSVC/
+ # {x.y.z}/[debug_nonredist/]arm64/Microsoft.VC141.CRT/.
+ vc_redist_root = FindVCRedistRoot()
+ if suffix.startswith('.'):
+ source_dir = os.path.join(vc_redist_root,
+ 'arm64', 'Microsoft.VC141.CRT')
+ else:
+ source_dir = os.path.join(vc_redist_root, 'debug_nonredist',
+ 'arm64', 'Microsoft.VC141.DebugCRT')
for file_part in ('msvcp', 'vccorlib', 'vcruntime'):
dll = dll_pattern % file_part
target = os.path.join(target_dir, dll)
@@ -190,16 +212,35 @@ def _CopyUCRTRuntime(target_dir, source_dir, target_cpu, dll_pattern, suffix):
os.environ.get('WINDOWSSDKDIR',
os.path.expandvars('%ProgramFiles(x86)%'
'\\Windows Kits\\10')))
- ucrt_dll_dirs = os.path.join(win_sdk_dir, 'Redist', 'ucrt', 'DLLs',
- target_cpu)
- ucrt_files = glob.glob(os.path.join(ucrt_dll_dirs, 'api-ms-win-*.dll'))
- assert len(ucrt_files) > 0
- for ucrt_src_file in ucrt_files:
- file_part = os.path.basename(ucrt_src_file)
- ucrt_dst_file = os.path.join(target_dir, file_part)
- _CopyRuntimeImpl(ucrt_dst_file, ucrt_src_file, False)
- _CopyRuntimeImpl(os.path.join(target_dir, 'ucrtbase' + suffix),
- os.path.join(source_dir, 'ucrtbase' + suffix))
+ # ARM64 doesn't have a redist for the ucrt DLLs because they are always
+ # present in the OS.
+ if target_cpu != 'arm64':
+ ucrt_dll_dirs = os.path.join(win_sdk_dir, 'Redist', 'ucrt', 'DLLs',
+ target_cpu)
+ ucrt_files = glob.glob(os.path.join(ucrt_dll_dirs, 'api-ms-win-*.dll'))
+ assert len(ucrt_files) > 0
+ for ucrt_src_file in ucrt_files:
+ file_part = os.path.basename(ucrt_src_file)
+ ucrt_dst_file = os.path.join(target_dir, file_part)
+ _CopyRuntimeImpl(ucrt_dst_file, ucrt_src_file, False)
+ # We must copy ucrtbase.dll for x64/x86, and ucrtbased.dll for all CPU types.
+ if target_cpu != 'arm64' or not suffix.startswith('.'):
+ if not suffix.startswith('.'):
+ # ucrtbased.dll is located at {win_sdk_dir}/bin/{a.b.c.d}/{target_cpu}/
+ # ucrt/.
+ sdk_redist_root = os.path.join(win_sdk_dir, 'bin')
+ sdk_bin_sub_dirs = os.listdir(sdk_redist_root)
+ # Select the most recent SDK if there are multiple versions installed.
+ sdk_bin_sub_dirs.sort(reverse=True)
+ for directory in sdk_bin_sub_dirs:
+ sdk_redist_root_version = os.path.join(sdk_redist_root, directory)
+ if not os.path.isdir(sdk_redist_root_version):
+ continue
+ if re.match('10\.\d+\.\d+\.\d+', directory):
+ source_dir = os.path.join(sdk_redist_root_version, target_cpu, 'ucrt')
+ break
+ _CopyRuntimeImpl(os.path.join(target_dir, 'ucrtbase' + suffix),
+ os.path.join(source_dir, 'ucrtbase' + suffix))
def FindVCToolsRoot():
@@ -225,6 +266,29 @@ def FindVCToolsRoot():
raise Exception('Unable to find the VC tools directory.')
+def FindVCRedistRoot():
+ """In VS2017, Redist binaries are located in
+ {toolchain_root}/VC/Redist/MSVC/{x.y.z}/{target_cpu}/, the {version_number}
+ part is likely to change in case of minor update of the toolchain so we don't
+ hardcode this value here (except for the major number).
+
+ This returns the '{toolchain_root}/VC/Redist/MSVC/{x.y.z}/' path.
+
+ This function should only be called when using VS2017.
+ """
+ assert GetVisualStudioVersion() == '2017'
+ SetEnvironmentAndGetRuntimeDllDirs()
+ assert ('GYP_MSVS_OVERRIDE_PATH' in os.environ)
+ vc_redist_msvc_root = os.path.join(os.environ['GYP_MSVS_OVERRIDE_PATH'],
+ 'VC', 'Redist', 'MSVC')
+ for directory in os.listdir(vc_redist_msvc_root):
+ if not os.path.isdir(os.path.join(vc_redist_msvc_root, directory)):
+ continue
+ if re.match('14\.\d+\.\d+', directory):
+ return os.path.join(vc_redist_msvc_root, directory)
+ raise Exception('Unable to find the VC redist directory')
+
+
def _CopyPGORuntime(target_dir, target_cpu):
"""Copy the runtime dependencies required during a PGO build.
"""
@@ -238,6 +302,7 @@ def _CopyPGORuntime(target_dir, target_cpu):
# from HostX86/x86.
pgo_x86_runtime_dir = os.path.join(pgo_runtime_root, 'HostX86', 'x86')
pgo_x64_runtime_dir = os.path.join(pgo_runtime_root, 'HostX64', 'x64')
+ pgo_arm64_runtime_dir = os.path.join(pgo_runtime_root, 'arm64')
else:
raise Exception('Unexpected toolchain version: %s.' % env_version)
@@ -250,8 +315,10 @@ def _CopyPGORuntime(target_dir, target_cpu):
source = os.path.join(pgo_x86_runtime_dir, runtime)
elif target_cpu == 'x64':
source = os.path.join(pgo_x64_runtime_dir, runtime)
+ elif target_cpu == 'arm64':
+ source = os.path.join(pgo_arm64_runtime_dir, runtime)
else:
- raise NotImplementedError("Unexpected target_cpu value: " + target_cpu)
+ raise NotImplementedError('Unexpected target_cpu value: ' + target_cpu)
if not os.path.exists(source):
raise Exception('Unable to find %s.' % source)
_CopyRuntimeImpl(os.path.join(target_dir, runtime), source)
@@ -260,7 +327,7 @@ def _CopyPGORuntime(target_dir, target_cpu):
def _CopyRuntime(target_dir, source_dir, target_cpu, debug):
"""Copy the VS runtime DLLs, only if the target doesn't exist, but the target
directory does exist. Handles VS 2015 and VS 2017."""
- suffix = "d.dll" if debug else ".dll"
+ suffix = 'd.dll' if debug else '.dll'
# VS 2017 uses the same CRT DLLs as VS 2015.
_CopyUCRTRuntime(target_dir, source_dir, target_cpu, '%s140' + suffix,
suffix)
@@ -270,7 +337,7 @@ def CopyDlls(target_dir, configuration, target_cpu):
"""Copy the VS runtime DLLs into the requested directory as needed.
configuration is one of 'Debug' or 'Release'.
- target_cpu is one of 'x86' or 'x64'.
+ target_cpu is one of 'x86', 'x64' or 'arm64'.
The debug configuration gets both the debug and release DLLs; the
release config only the latter.
@@ -279,8 +346,15 @@ def CopyDlls(target_dir, configuration, target_cpu):
if not vs_runtime_dll_dirs:
return
- x64_runtime, x86_runtime = vs_runtime_dll_dirs
- runtime_dir = x64_runtime if target_cpu == 'x64' else x86_runtime
+ x64_runtime, x86_runtime, arm64_runtime = vs_runtime_dll_dirs
+ if target_cpu == 'x64':
+ runtime_dir = x64_runtime
+ elif target_cpu == 'x86':
+ runtime_dir = x86_runtime
+ elif target_cpu == 'arm64':
+ runtime_dir = arm64_runtime
+ else:
+ raise Exception('Unknown target_cpu: ' + target_cpu)
_CopyRuntime(target_dir, runtime_dir, target_cpu, debug=False)
if configuration == 'Debug':
_CopyRuntime(target_dir, runtime_dir, target_cpu, debug=True)
@@ -293,7 +367,7 @@ def CopyDlls(target_dir, configuration, target_cpu):
def _CopyDebugger(target_dir, target_cpu):
"""Copy dbghelp.dll and dbgcore.dll into the requested directory as needed.
- target_cpu is one of 'x86' or 'x64'.
+ target_cpu is one of 'x86', 'x64' or 'arm64'.
dbghelp.dll is used when Chrome needs to symbolize stacks. Copying this file
from the SDK directory avoids using the system copy of dbghelp.dll which then
@@ -413,7 +487,7 @@ def Update(force=False):
def NormalizePath(path):
- while path.endswith("\\"):
+ while path.endswith('\\'):
path = path[:-1]
return path