Skip to content

Commit

Permalink
[toolchain] Update Windows VS toolchain to current Chromium one.
Browse files Browse the repository at this point in the history
Changes to the canonical are only addition of a comment header and path-setting lines:
```
chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir))

SRC_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

sys.path.insert(0, os.path.join(chrome_src, 'tools'))
```

Change-Id: I403c1d7dd56cc45fcddd93142e8929e8cd5ae75f
Reviewed-on: https://dart-review.googlesource.com/76705
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
  • Loading branch information
aam authored and commit-bot@chromium.org committed Sep 26, 2018
1 parent 0262530 commit e7d71be
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 49 deletions.
4 changes: 2 additions & 2 deletions build/gn_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def ToGNString(value, allow_dicts = True):
allow_dicts indicates if this function will allow converting dictionaries
to GN scopes. This is only possible at the top level, you can't nest a
GN scope in a list, so this should be set to False for recursive calls."""
if isinstance(value, str):
if isinstance(value, str) or isinstance(value, unicode):
if value.find('\n') >= 0:
raise GNException("Trying to print a string with a newline in it.")
return '"' + value.replace('"', '\\"') + '"'
Expand All @@ -36,4 +36,4 @@ def ToGNString(value, allow_dicts = True):
if isinstance(value, int):
return str(value)

raise GNException("Unsupported type when printing to GN.")
raise GNException("Unsupported type %s (value %s) when printing to GN." % (type(value), value))
116 changes: 69 additions & 47 deletions build/vs_toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
# https://cs.chromium.org/chromium/src/build/vs_toolchain.py
# with modifications that update paths, and remove dependencies on gyp.
# To update to a new MSVC toolchain, copy the updated script from the Chromium
# tree, and edit to make it work in the Dart tree by updating paths and removing
# dependencies on any 'import gyp' in the original script.
# tree, and edit to make it work in the Dart tree by updating paths in the original script.

import glob
import json
Expand All @@ -22,6 +21,7 @@
import stat
import subprocess
import sys
from gn_helpers import ToGNString


script_dir = os.path.dirname(os.path.realpath(__file__))
Expand Down Expand Up @@ -50,7 +50,9 @@ def SetEnvironmentAndGetRuntimeDllDirs():
if ((sys.platform in ('win32', 'cygwin') or os.path.exists(json_data_file))
and depot_tools_win_toolchain):
if ShouldUpdateToolchain():
Update()
update_result = Update()
if update_result != 0:
raise Exception('Failed to update, error code %d.' % update_result)
with open(json_data_file, 'r') as tempf:
toolchain_data = json.load(tempf)

Expand Down Expand Up @@ -86,9 +88,8 @@ def SetEnvironmentAndGetRuntimeDllDirs():
bitness = platform.architecture()[0]
# When running 64-bit python the x64 DLLs will be in System32
x64_path = 'System32' if bitness == '64bit' else 'Sysnative'
system_root = os.environ['SystemRoot']
x64_path = os.path.join(system_root, x64_path)
vs_runtime_dll_dirs = [x64_path, os.path.join(system_root, r'SysWOW64')]
x64_path = os.path.join(os.path.expandvars('%windir%'), x64_path)
vs_runtime_dll_dirs = [x64_path, os.path.expandvars('%windir%/SysWOW64')]

return vs_runtime_dll_dirs

Expand Down Expand Up @@ -134,7 +135,6 @@ def DetectVisualStudioPath():
# build/toolchain/win/setup_toolchain.py as well.
version_as_year = GetVisualStudioVersion()
year_to_version = {
'2015': '14.0',
'2017': '15.0',
}
if version_as_year not in year_to_version:
Expand All @@ -149,19 +149,14 @@ def DetectVisualStudioPath():
# For now we use a hardcoded default with an environment variable override.
for path in (
os.environ.get('vs2017_install'),
r'C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional',
r'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community'):
os.path.expandvars('%ProgramFiles(x86)%'
'/Microsoft Visual Studio/2017/Enterprise'),
os.path.expandvars('%ProgramFiles(x86)%'
'/Microsoft Visual Studio/2017/Professional'),
os.path.expandvars('%ProgramFiles(x86)%'
'/Microsoft Visual Studio/2017/Community')):
if path and os.path.exists(path):
return path
else:
keys = [r'HKLM\Software\Microsoft\VisualStudio\%s' % version,
r'HKLM\Software\Wow6432Node\Microsoft\VisualStudio\%s' % version]
for key in keys:
path = _RegistryGetValue(key, 'InstallDir')
if not path:
continue
path = os.path.normpath(os.path.join(path, '..', '..'))
return path

raise Exception(('Visual Studio Version %s (from GYP_MSVS_VERSION)'
' not found.') % (version_as_year))
Expand Down Expand Up @@ -197,14 +192,15 @@ def _CopyUCRTRuntime(target_dir, source_dir, target_cpu, dll_pattern, suffix):
target = os.path.join(target_dir, dll)
source = os.path.join(source_dir, dll)
_CopyRuntimeImpl(target, source)
# Copy the UCRT files needed by VS 2015 from the Windows SDK. This location
# includes the api-ms-win-crt-*.dll files that are not found in the Windows
# directory. These files are needed for component builds.
# If WINDOWSSDKDIR is not set use the default SDK path. This will be the case
# when DEPOT_TOOLS_WIN_TOOLCHAIN=0 and vcvarsall.bat has not been run.
# Copy the UCRT files from the Windows SDK. This location includes the
# api-ms-win-crt-*.dll files that are not found in the Windows directory.
# These files are needed for component builds. If WINDOWSSDKDIR is not set
# use the default SDK path. This will be the case when
# DEPOT_TOOLS_WIN_TOOLCHAIN=0 and vcvarsall.bat has not been run.
win_sdk_dir = os.path.normpath(
os.environ.get('WINDOWSSDKDIR',
'C:\\Program Files (x86)\\Windows Kits\\10'))
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'))
Expand Down Expand Up @@ -246,11 +242,7 @@ def _CopyPGORuntime(target_dir, target_cpu):
env_version = GetVisualStudioVersion()
# These dependencies will be in a different location depending on the version
# of the toolchain.
if env_version == '2015':
pgo_x86_runtime_dir = os.path.join(os.environ.get('GYP_MSVS_OVERRIDE_PATH'),
'VC', 'bin')
pgo_x64_runtime_dir = os.path.join(pgo_x86_runtime_dir, 'amd64')
elif env_version == '2017':
if env_version == '2017':
pgo_runtime_root = FindVCToolsRoot()
assert pgo_runtime_root
# There's no version of pgosweep.exe in HostX64/x86, so we use the copy
Expand Down Expand Up @@ -335,9 +327,11 @@ def _CopyDebugger(target_dir, target_cpu):
if is_optional:
continue
else:
# TODO(crbug.com/773476): remove version requirement.
raise Exception('%s not found in "%s"\r\nYou must install the '
'"Debugging Tools for Windows" feature from the Windows'
' 10 SDK.' % (debug_file, full_path))
' 10 SDK. You must use v10.0.17134.0. of the SDK'
% (debug_file, full_path))
target_path = os.path.join(target_dir, debug_file)
_CopyRuntimeImpl(target_path, full_path)

Expand All @@ -346,12 +340,14 @@ def _GetDesiredVsToolchainHashes():
"""Load a list of SHA1s corresponding to the toolchains that we want installed
to build with."""
env_version = GetVisualStudioVersion()
if env_version == '2015':
# Update 3 final with 10.0.15063.468 SDK and no vctip.exe.
return ['f53e4598951162bad6330f7a167486c7ae5db1e5']
if env_version == '2017':
# VS 2017 Update 3.2 with 10.0.15063.468 SDK.
return ['9bc7ccbf9f4bd50d4a3bd185e8ca94ff1618de0b']
# VS 2017 Update 7.1 (15.7.1) with 10.0.17134.12 SDK, rebuilt with
# dbghelp.dll fix.
toolchain_hash = '3bc0ec615cf20ee342f3bc29bc991b5ad66d8d2c'
# Third parties that do not have access to the canonical toolchain can map
# canonical toolchain version to their own toolchain versions.
toolchain_hash_mapping_key = 'GYP_MSVS_HASH_%s' % toolchain_hash
return [os.environ.get(toolchain_hash_mapping_key, toolchain_hash)]
raise Exception('Unsupported VS version %s' % env_version)


Expand Down Expand Up @@ -385,6 +381,31 @@ def Update(force=False):
depot_tools_win_toolchain):
import find_depot_tools
depot_tools_path = find_depot_tools.add_depot_tools_to_path()

# On Linux, the file system is usually case-sensitive while the Windows
# SDK only works on case-insensitive file systems. If it doesn't already
# exist, set up a ciopfs fuse mount to put the SDK in a case-insensitive
# part of the file system.
toolchain_dir = os.path.join(depot_tools_path, 'win_toolchain', 'vs_files')
# For testing this block, unmount existing mounts with
# fusermount -u third_party/depot_tools/win_toolchain/vs_files
if sys.platform.startswith('linux') and not os.path.ismount(toolchain_dir):
import distutils.spawn
ciopfs = distutils.spawn.find_executable('ciopfs')
if not ciopfs:
# ciopfs not found in PATH; try the one downloaded from the DEPS hook.
ciopfs = os.path.join(script_dir, 'ciopfs')
if not os.path.isdir(toolchain_dir):
os.mkdir(toolchain_dir)
if not os.path.isdir(toolchain_dir + '.ciopfs'):
os.mkdir(toolchain_dir + '.ciopfs')
# Without use_ino, clang's #pragma once and Wnonportable-include-path
# both don't work right, see https://llvm.org/PR34931
# use_ino doesn't slow down builds, so it seems there's no drawback to
# just using it always.
subprocess.check_call([
ciopfs, '-o', 'use_ino', toolchain_dir + '.ciopfs', toolchain_dir])

# Necessary so that get_toolchain_if_necessary.py will put the VS toolkit
# in the correct directory.
os.environ['GYP_MSVS_VERSION'] = GetVisualStudioVersion()
Expand Down Expand Up @@ -415,7 +436,8 @@ def SetEnvironmentAndGetSDKDir():

# If WINDOWSSDKDIR is not set, search the default SDK path and set it.
if not 'WINDOWSSDKDIR' in os.environ:
default_sdk_path = 'C:\\Program Files (x86)\\Windows Kits\\10'
default_sdk_path = os.path.expandvars('%ProgramFiles(x86)%'
'\\Windows Kits\\10')
if os.path.isdir(default_sdk_path):
os.environ['WINDOWSSDKDIR'] = default_sdk_path

Expand All @@ -428,17 +450,17 @@ def GetToolchainDir():
runtime_dll_dirs = SetEnvironmentAndGetRuntimeDllDirs()
win_sdk_dir = SetEnvironmentAndGetSDKDir()

print '''vs_path = "%s"
sdk_path = "%s"
vs_version = "%s"
wdk_dir = "%s"
runtime_dirs = "%s"
print '''vs_path = %s
sdk_path = %s
vs_version = %s
wdk_dir = %s
runtime_dirs = %s
''' % (
NormalizePath(os.environ['GYP_MSVS_OVERRIDE_PATH']),
win_sdk_dir,
GetVisualStudioVersion(),
NormalizePath(os.environ.get('WDK_DIR', '')),
os.path.pathsep.join(runtime_dll_dirs or ['None']))
ToGNString(NormalizePath(os.environ['GYP_MSVS_OVERRIDE_PATH'])),
ToGNString(win_sdk_dir),
ToGNString(GetVisualStudioVersion()),
ToGNString(NormalizePath(os.environ.get('WDK_DIR', ''))),
ToGNString(os.path.pathsep.join(runtime_dll_dirs or ['None'])))


def main():
Expand All @@ -454,4 +476,4 @@ def main():


if __name__ == '__main__':
sys.exit(main())
sys.exit(main())

0 comments on commit e7d71be

Please sign in to comment.