2015-08-12 01:25:00 +03:00
|
|
|
#!/usr/bin/env python
|
2014-03-20 02:01:39 +04:00
|
|
|
# Copyright 2014 The Chromium Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
2016-02-09 07:27:52 +03:00
|
|
|
import glob
|
2014-03-20 02:01:39 +04:00
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import pipes
|
2016-06-01 21:37:18 +03:00
|
|
|
import platform
|
2017-05-12 18:29:26 +03:00
|
|
|
import re
|
2014-03-20 02:01:39 +04:00
|
|
|
import shutil
|
2016-06-01 21:37:18 +03:00
|
|
|
import stat
|
2014-03-20 02:01:39 +04:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
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', 'gyp', 'pylib'))
|
2014-04-09 05:56:20 +04:00
|
|
|
json_data_file = os.path.join(script_dir, 'win_toolchain.json')
|
2014-03-20 02:01:39 +04:00
|
|
|
|
|
|
|
|
2017-09-23 03:35:11 +03:00
|
|
|
# Use MSVS2017 as the default toolchain.
|
|
|
|
CURRENT_DEFAULT_TOOLCHAIN_VERSION = '2017'
|
2016-01-16 01:29:57 +03:00
|
|
|
|
|
|
|
|
2014-04-09 05:56:20 +04:00
|
|
|
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
|
|
|
|
the output directory after gyp generation.
|
2016-06-01 21:37:18 +03:00
|
|
|
|
|
|
|
Return value is [x64path, x86path] or None
|
2014-03-20 02:01:39 +04:00
|
|
|
"""
|
2015-11-21 05:21:52 +03:00
|
|
|
vs_runtime_dll_dirs = None
|
2014-03-20 02:01:39 +04:00
|
|
|
depot_tools_win_toolchain = \
|
|
|
|
bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1')))
|
2015-08-12 01:25:00 +03:00
|
|
|
# When running on a non-Windows host, only do this if the SDK has explicitly
|
|
|
|
# been downloaded before (in which case json_data_file will exist).
|
2015-08-26 02:03:35 +03:00
|
|
|
if ((sys.platform in ('win32', 'cygwin') or os.path.exists(json_data_file))
|
|
|
|
and depot_tools_win_toolchain):
|
2016-01-16 01:29:57 +03:00
|
|
|
if ShouldUpdateToolchain():
|
2017-10-13 00:44:37 +03:00
|
|
|
update_result = Update()
|
|
|
|
if update_result != 0:
|
|
|
|
raise Exception('Failed to update, error code %d.' % update_result)
|
2014-04-09 05:56:20 +04:00
|
|
|
with open(json_data_file, 'r') as tempf:
|
2014-03-20 02:01:39 +04:00
|
|
|
toolchain_data = json.load(tempf)
|
|
|
|
|
|
|
|
toolchain = toolchain_data['path']
|
|
|
|
version = toolchain_data['version']
|
2015-06-02 04:15:44 +03:00
|
|
|
win_sdk = toolchain_data.get('win_sdk')
|
|
|
|
if not win_sdk:
|
|
|
|
win_sdk = toolchain_data['win8sdk']
|
2014-03-20 02:01:39 +04:00
|
|
|
wdk = toolchain_data['wdk']
|
|
|
|
# TODO(scottmg): The order unfortunately matters in these. They should be
|
2017-05-12 18:29:26 +03:00
|
|
|
# split into separate keys for x86 and x64. (See CopyDlls call below).
|
|
|
|
# http://crbug.com/345992
|
2015-11-21 05:21:52 +03:00
|
|
|
vs_runtime_dll_dirs = toolchain_data['runtime_dirs']
|
2014-03-20 02:01:39 +04:00
|
|
|
|
|
|
|
os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain
|
|
|
|
os.environ['GYP_MSVS_VERSION'] = version
|
2017-03-11 04:46:42 +03:00
|
|
|
|
|
|
|
# Limit the scope of the gyp import to only where it is used. This
|
|
|
|
# potentially lets build configs that never execute this block to drop
|
|
|
|
# their GYP checkout.
|
|
|
|
import gyp
|
|
|
|
|
2014-03-20 02:01:39 +04:00
|
|
|
# We need to make sure windows_sdk_path is set to the automated
|
|
|
|
# toolchain values in GYP_DEFINES, but don't want to override any
|
|
|
|
# otheroptions.express
|
|
|
|
# values there.
|
|
|
|
gyp_defines_dict = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES'))
|
2015-06-02 04:15:44 +03:00
|
|
|
gyp_defines_dict['windows_sdk_path'] = win_sdk
|
2014-03-20 02:01:39 +04:00
|
|
|
os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v)))
|
|
|
|
for k, v in gyp_defines_dict.iteritems())
|
2017-03-11 04:46:42 +03:00
|
|
|
|
2015-06-02 04:15:44 +03:00
|
|
|
os.environ['WINDOWSSDKDIR'] = win_sdk
|
2014-03-20 02:01:39 +04:00
|
|
|
os.environ['WDK_DIR'] = wdk
|
|
|
|
# Include the VS runtime in the PATH in case it's not machine-installed.
|
2016-02-15 21:18:01 +03:00
|
|
|
runtime_path = os.path.pathsep.join(vs_runtime_dll_dirs)
|
|
|
|
os.environ['PATH'] = runtime_path + os.path.pathsep + os.environ['PATH']
|
2016-01-07 19:30:12 +03:00
|
|
|
elif sys.platform == 'win32' and not depot_tools_win_toolchain:
|
|
|
|
if not 'GYP_MSVS_OVERRIDE_PATH' in os.environ:
|
|
|
|
os.environ['GYP_MSVS_OVERRIDE_PATH'] = DetectVisualStudioPath()
|
2016-01-19 03:39:08 +03:00
|
|
|
if not 'GYP_MSVS_VERSION' in os.environ:
|
|
|
|
os.environ['GYP_MSVS_VERSION'] = GetVisualStudioVersion()
|
2016-01-07 19:30:12 +03:00
|
|
|
|
2016-06-01 21:37:18 +03:00
|
|
|
# When using an installed toolchain these files aren't needed in the output
|
|
|
|
# directory in order to run binaries locally, but they are needed in order
|
|
|
|
# to create isolates or the mini_installer. Copying them to the output
|
|
|
|
# directory ensures that they are available when needed.
|
|
|
|
bitness = platform.architecture()[0]
|
|
|
|
# When running 64-bit python the x64 DLLs will be in System32
|
|
|
|
x64_path = 'System32' if bitness == '64bit' else 'Sysnative'
|
|
|
|
x64_path = os.path.join(r'C:\Windows', x64_path)
|
|
|
|
vs_runtime_dll_dirs = [x64_path, r'C:\Windows\SysWOW64']
|
|
|
|
|
2015-11-21 05:21:52 +03:00
|
|
|
return vs_runtime_dll_dirs
|
2014-03-20 02:01:39 +04:00
|
|
|
|
|
|
|
|
2016-01-07 19:30:12 +03:00
|
|
|
def _RegistryGetValueUsingWinReg(key, value):
|
|
|
|
"""Use the _winreg module to obtain the value of a registry key.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
key: The registry key.
|
|
|
|
value: The particular registry value to read.
|
|
|
|
Return:
|
|
|
|
contents of the registry key's value, or None on failure. Throws
|
|
|
|
ImportError if _winreg is unavailable.
|
|
|
|
"""
|
|
|
|
import _winreg
|
|
|
|
try:
|
|
|
|
root, subkey = key.split('\\', 1)
|
|
|
|
assert root == 'HKLM' # Only need HKLM for now.
|
|
|
|
with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, subkey) as hkey:
|
|
|
|
return _winreg.QueryValueEx(hkey, value)[0]
|
|
|
|
except WindowsError:
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def _RegistryGetValue(key, value):
|
|
|
|
try:
|
|
|
|
return _RegistryGetValueUsingWinReg(key, value)
|
|
|
|
except ImportError:
|
|
|
|
raise Exception('The python library _winreg not found.')
|
|
|
|
|
|
|
|
|
2016-01-13 05:23:30 +03:00
|
|
|
def GetVisualStudioVersion():
|
2016-01-16 01:29:57 +03:00
|
|
|
"""Return GYP_MSVS_VERSION of Visual Studio.
|
2016-01-13 05:23:30 +03:00
|
|
|
"""
|
2016-01-16 01:29:57 +03:00
|
|
|
return os.environ.get('GYP_MSVS_VERSION', CURRENT_DEFAULT_TOOLCHAIN_VERSION)
|
2016-01-13 05:23:30 +03:00
|
|
|
|
|
|
|
|
2016-01-07 19:30:12 +03:00
|
|
|
def DetectVisualStudioPath():
|
|
|
|
"""Return path to the GYP_MSVS_VERSION of Visual Studio.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Note that this code is used from
|
|
|
|
# build/toolchain/win/setup_toolchain.py as well.
|
2016-01-13 05:23:30 +03:00
|
|
|
version_as_year = GetVisualStudioVersion()
|
2016-01-07 19:30:12 +03:00
|
|
|
year_to_version = {
|
2017-01-23 09:57:21 +03:00
|
|
|
'2017': '15.0',
|
2016-01-07 19:30:12 +03:00
|
|
|
}
|
|
|
|
if version_as_year not in year_to_version:
|
|
|
|
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]
|
2017-01-23 09:57:21 +03:00
|
|
|
if version_as_year == '2017':
|
|
|
|
# The VC++ 2017 install location needs to be located using COM instead of
|
|
|
|
# the registry. For details see:
|
|
|
|
# https://blogs.msdn.microsoft.com/heaths/2016/09/15/changes-to-visual-studio-15-setup/
|
|
|
|
# For now we use a hardcoded default with an environment variable override.
|
2017-04-14 05:13:01 +03:00
|
|
|
for path in (
|
|
|
|
os.environ.get('vs2017_install'),
|
2017-09-29 20:54:33 +03:00
|
|
|
r'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise',
|
2017-04-14 05:13:01 +03:00
|
|
|
r'C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional',
|
|
|
|
r'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community'):
|
|
|
|
if path and os.path.exists(path):
|
|
|
|
return path
|
2016-01-07 19:30:12 +03:00
|
|
|
|
|
|
|
raise Exception(('Visual Studio Version %s (from GYP_MSVS_VERSION)'
|
|
|
|
' not found.') % (version_as_year))
|
|
|
|
|
|
|
|
|
2016-02-09 07:27:52 +03:00
|
|
|
def _CopyRuntimeImpl(target, source, verbose=True):
|
2016-04-18 18:29:14 +03:00
|
|
|
"""Copy |source| to |target| if it doesn't already exist or if it needs to be
|
|
|
|
updated (comparing last modified time as an approximate float match as for
|
|
|
|
some reason the values tend to differ by ~1e-07 despite being copies of the
|
|
|
|
same file... https://crbug.com/603603).
|
Rework win_toolchains a bit and copy the vs runtime DLLs as needed.
In order to run both the visual studio tools and the binaries built
by them (and ninja), we need to ensure that the VS runtime DLLs
are available in the path.
In the GYP build, we accomplish this by copying them into the
Debug and Debug_x64 dirs as appropriate inside the gyp_chromium
script.
In the pure-GN build, then, things would be broken, so we need to
modify the GN build to do the copy as well, or we need to inject
a step somewhere that happens after GN runs but before Ninja tries
to run (since none of the toolchain binaries will work).
This patch accomplishes this by calling out to vs_toolchain.py to
copy the DLLs as neede when the toolchain is defined. This is somewhat
less than ideal (makes 'gn gen' slower) but seems better than forcing
devs to have to run an additional command.
In addition, the GYP build writes targets into Debug and Debug_x64
concurrently. This doesn't really carry over into GN correctly, and
we probably only ever want to write targets into Debug and Debug/64
(or some such).
However, the way the toolchains are currently implemented, it's not
clear if this really works and the interplay between 32-bit and 64-bit
is weird (we apparently normally "force" 32-bit even if we set cpu_arch
to 64-bit, and require you to specify force_win64). To work around this
and make sure that we copy the right DLLs for the right arch into the
outer Debug/ directory, this patch temporarily disables the cross-arch
part of the build, forcing the host_toolchain to match the target_toolchain.
This likely means that 'cpu_arch="x86"' works (the default), but the 'host'
binaries like image_diff and mksnapshot will be compiled in 32-bit mode,
not 64-bit mode. 'cpu_arch="x64" force_win64=true' should also work, and
produce all-64-bit binaries. 'cpu_arch="x64"' does not work at all and
won't until we can clean up the above stuff.
R=scottmg@chromium.org, brettw@chromium.org
BUG=430661
Review URL: https://codereview.chromium.org/722723004
Cr-Original-Commit-Position: refs/heads/master@{#304310}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 0b95195e49489b7a4d87048d2ce4b747173a5b8a
2014-11-15 03:09:14 +03:00
|
|
|
"""
|
|
|
|
if (os.path.isdir(os.path.dirname(target)) and
|
|
|
|
(not os.path.isfile(target) or
|
2016-04-18 18:29:14 +03:00
|
|
|
abs(os.stat(target).st_mtime - os.stat(source).st_mtime) >= 0.01)):
|
2016-02-09 07:27:52 +03:00
|
|
|
if verbose:
|
|
|
|
print 'Copying %s to %s...' % (source, target)
|
Rework win_toolchains a bit and copy the vs runtime DLLs as needed.
In order to run both the visual studio tools and the binaries built
by them (and ninja), we need to ensure that the VS runtime DLLs
are available in the path.
In the GYP build, we accomplish this by copying them into the
Debug and Debug_x64 dirs as appropriate inside the gyp_chromium
script.
In the pure-GN build, then, things would be broken, so we need to
modify the GN build to do the copy as well, or we need to inject
a step somewhere that happens after GN runs but before Ninja tries
to run (since none of the toolchain binaries will work).
This patch accomplishes this by calling out to vs_toolchain.py to
copy the DLLs as neede when the toolchain is defined. This is somewhat
less than ideal (makes 'gn gen' slower) but seems better than forcing
devs to have to run an additional command.
In addition, the GYP build writes targets into Debug and Debug_x64
concurrently. This doesn't really carry over into GN correctly, and
we probably only ever want to write targets into Debug and Debug/64
(or some such).
However, the way the toolchains are currently implemented, it's not
clear if this really works and the interplay between 32-bit and 64-bit
is weird (we apparently normally "force" 32-bit even if we set cpu_arch
to 64-bit, and require you to specify force_win64). To work around this
and make sure that we copy the right DLLs for the right arch into the
outer Debug/ directory, this patch temporarily disables the cross-arch
part of the build, forcing the host_toolchain to match the target_toolchain.
This likely means that 'cpu_arch="x86"' works (the default), but the 'host'
binaries like image_diff and mksnapshot will be compiled in 32-bit mode,
not 64-bit mode. 'cpu_arch="x64" force_win64=true' should also work, and
produce all-64-bit binaries. 'cpu_arch="x64"' does not work at all and
won't until we can clean up the above stuff.
R=scottmg@chromium.org, brettw@chromium.org
BUG=430661
Review URL: https://codereview.chromium.org/722723004
Cr-Original-Commit-Position: refs/heads/master@{#304310}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 0b95195e49489b7a4d87048d2ce4b747173a5b8a
2014-11-15 03:09:14 +03:00
|
|
|
if os.path.exists(target):
|
2017-09-06 02:30:13 +03:00
|
|
|
# Make the file writable so that we can delete it now, and keep it
|
|
|
|
# readable.
|
|
|
|
os.chmod(target, stat.S_IWRITE | stat.S_IREAD)
|
Rework win_toolchains a bit and copy the vs runtime DLLs as needed.
In order to run both the visual studio tools and the binaries built
by them (and ninja), we need to ensure that the VS runtime DLLs
are available in the path.
In the GYP build, we accomplish this by copying them into the
Debug and Debug_x64 dirs as appropriate inside the gyp_chromium
script.
In the pure-GN build, then, things would be broken, so we need to
modify the GN build to do the copy as well, or we need to inject
a step somewhere that happens after GN runs but before Ninja tries
to run (since none of the toolchain binaries will work).
This patch accomplishes this by calling out to vs_toolchain.py to
copy the DLLs as neede when the toolchain is defined. This is somewhat
less than ideal (makes 'gn gen' slower) but seems better than forcing
devs to have to run an additional command.
In addition, the GYP build writes targets into Debug and Debug_x64
concurrently. This doesn't really carry over into GN correctly, and
we probably only ever want to write targets into Debug and Debug/64
(or some such).
However, the way the toolchains are currently implemented, it's not
clear if this really works and the interplay between 32-bit and 64-bit
is weird (we apparently normally "force" 32-bit even if we set cpu_arch
to 64-bit, and require you to specify force_win64). To work around this
and make sure that we copy the right DLLs for the right arch into the
outer Debug/ directory, this patch temporarily disables the cross-arch
part of the build, forcing the host_toolchain to match the target_toolchain.
This likely means that 'cpu_arch="x86"' works (the default), but the 'host'
binaries like image_diff and mksnapshot will be compiled in 32-bit mode,
not 64-bit mode. 'cpu_arch="x64" force_win64=true' should also work, and
produce all-64-bit binaries. 'cpu_arch="x64"' does not work at all and
won't until we can clean up the above stuff.
R=scottmg@chromium.org, brettw@chromium.org
BUG=430661
Review URL: https://codereview.chromium.org/722723004
Cr-Original-Commit-Position: refs/heads/master@{#304310}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 0b95195e49489b7a4d87048d2ce4b747173a5b8a
2014-11-15 03:09:14 +03:00
|
|
|
os.unlink(target)
|
|
|
|
shutil.copy2(source, target)
|
2017-09-06 02:30:13 +03:00
|
|
|
# Make the file writable so that we can overwrite or delete it later,
|
|
|
|
# keep it readable.
|
|
|
|
os.chmod(target, stat.S_IWRITE | stat.S_IREAD)
|
Rework win_toolchains a bit and copy the vs runtime DLLs as needed.
In order to run both the visual studio tools and the binaries built
by them (and ninja), we need to ensure that the VS runtime DLLs
are available in the path.
In the GYP build, we accomplish this by copying them into the
Debug and Debug_x64 dirs as appropriate inside the gyp_chromium
script.
In the pure-GN build, then, things would be broken, so we need to
modify the GN build to do the copy as well, or we need to inject
a step somewhere that happens after GN runs but before Ninja tries
to run (since none of the toolchain binaries will work).
This patch accomplishes this by calling out to vs_toolchain.py to
copy the DLLs as neede when the toolchain is defined. This is somewhat
less than ideal (makes 'gn gen' slower) but seems better than forcing
devs to have to run an additional command.
In addition, the GYP build writes targets into Debug and Debug_x64
concurrently. This doesn't really carry over into GN correctly, and
we probably only ever want to write targets into Debug and Debug/64
(or some such).
However, the way the toolchains are currently implemented, it's not
clear if this really works and the interplay between 32-bit and 64-bit
is weird (we apparently normally "force" 32-bit even if we set cpu_arch
to 64-bit, and require you to specify force_win64). To work around this
and make sure that we copy the right DLLs for the right arch into the
outer Debug/ directory, this patch temporarily disables the cross-arch
part of the build, forcing the host_toolchain to match the target_toolchain.
This likely means that 'cpu_arch="x86"' works (the default), but the 'host'
binaries like image_diff and mksnapshot will be compiled in 32-bit mode,
not 64-bit mode. 'cpu_arch="x64" force_win64=true' should also work, and
produce all-64-bit binaries. 'cpu_arch="x64"' does not work at all and
won't until we can clean up the above stuff.
R=scottmg@chromium.org, brettw@chromium.org
BUG=430661
Review URL: https://codereview.chromium.org/722723004
Cr-Original-Commit-Position: refs/heads/master@{#304310}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 0b95195e49489b7a4d87048d2ce4b747173a5b8a
2014-11-15 03:09:14 +03:00
|
|
|
|
|
|
|
|
2017-03-14 00:12:31 +03:00
|
|
|
def _CopyUCRTRuntime(target_dir, source_dir, target_cpu, dll_pattern, suffix):
|
2015-06-02 04:15:44 +03:00
|
|
|
"""Copy both the msvcp and vccorlib runtime DLLs, only if the target doesn't
|
|
|
|
exist, but the target directory does exist."""
|
2015-12-17 23:44:35 +03:00
|
|
|
for file_part in ('msvcp', 'vccorlib', 'vcruntime'):
|
2015-06-02 04:15:44 +03:00
|
|
|
dll = dll_pattern % file_part
|
|
|
|
target = os.path.join(target_dir, dll)
|
|
|
|
source = os.path.join(source_dir, dll)
|
|
|
|
_CopyRuntimeImpl(target, source)
|
2017-12-06 00:09:47 +03:00
|
|
|
# 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.
|
2017-03-14 00:12:31 +03:00
|
|
|
win_sdk_dir = os.path.normpath(
|
|
|
|
os.environ.get('WINDOWSSDKDIR',
|
|
|
|
'C:\\Program Files (x86)\\Windows Kits\\10'))
|
2017-07-25 01:23:12 +03:00
|
|
|
ucrt_dll_dirs = os.path.join(win_sdk_dir, 'Redist', 'ucrt', 'DLLs',
|
|
|
|
target_cpu)
|
2017-03-14 00:12:31 +03:00
|
|
|
ucrt_files = glob.glob(os.path.join(ucrt_dll_dirs, 'api-ms-win-*.dll'))
|
2016-06-01 21:37:18 +03:00
|
|
|
assert len(ucrt_files) > 0
|
|
|
|
for ucrt_src_file in ucrt_files:
|
2016-02-23 02:09:18 +03:00
|
|
|
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))
|
Rework win_toolchains a bit and copy the vs runtime DLLs as needed.
In order to run both the visual studio tools and the binaries built
by them (and ninja), we need to ensure that the VS runtime DLLs
are available in the path.
In the GYP build, we accomplish this by copying them into the
Debug and Debug_x64 dirs as appropriate inside the gyp_chromium
script.
In the pure-GN build, then, things would be broken, so we need to
modify the GN build to do the copy as well, or we need to inject
a step somewhere that happens after GN runs but before Ninja tries
to run (since none of the toolchain binaries will work).
This patch accomplishes this by calling out to vs_toolchain.py to
copy the DLLs as neede when the toolchain is defined. This is somewhat
less than ideal (makes 'gn gen' slower) but seems better than forcing
devs to have to run an additional command.
In addition, the GYP build writes targets into Debug and Debug_x64
concurrently. This doesn't really carry over into GN correctly, and
we probably only ever want to write targets into Debug and Debug/64
(or some such).
However, the way the toolchains are currently implemented, it's not
clear if this really works and the interplay between 32-bit and 64-bit
is weird (we apparently normally "force" 32-bit even if we set cpu_arch
to 64-bit, and require you to specify force_win64). To work around this
and make sure that we copy the right DLLs for the right arch into the
outer Debug/ directory, this patch temporarily disables the cross-arch
part of the build, forcing the host_toolchain to match the target_toolchain.
This likely means that 'cpu_arch="x86"' works (the default), but the 'host'
binaries like image_diff and mksnapshot will be compiled in 32-bit mode,
not 64-bit mode. 'cpu_arch="x64" force_win64=true' should also work, and
produce all-64-bit binaries. 'cpu_arch="x64"' does not work at all and
won't until we can clean up the above stuff.
R=scottmg@chromium.org, brettw@chromium.org
BUG=430661
Review URL: https://codereview.chromium.org/722723004
Cr-Original-Commit-Position: refs/heads/master@{#304310}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 0b95195e49489b7a4d87048d2ce4b747173a5b8a
2014-11-15 03:09:14 +03:00
|
|
|
|
|
|
|
|
2017-05-20 18:00:06 +03:00
|
|
|
def FindVCToolsRoot():
|
|
|
|
"""In VS2017 the PGO runtime dependencies are located in
|
|
|
|
{toolchain_root}/VC/Tools/MSVC/{x.y.z}/bin/Host{target_cpu}/{target_cpu}/, the
|
|
|
|
{version_number} part is likely to change in case of a minor update of the
|
|
|
|
toolchain so we don't hardcode this value here (except for the major number).
|
|
|
|
|
|
|
|
This returns the '{toolchain_root}/VC/Tools/MSVC/{x.y.z}/bin/' path.
|
|
|
|
|
|
|
|
This function should only be called when using VS2017.
|
|
|
|
"""
|
|
|
|
assert GetVisualStudioVersion() == '2017'
|
2017-05-23 05:08:31 +03:00
|
|
|
SetEnvironmentAndGetRuntimeDllDirs()
|
2017-05-20 18:00:06 +03:00
|
|
|
assert ('GYP_MSVS_OVERRIDE_PATH' in os.environ)
|
|
|
|
vc_tools_msvc_root = os.path.join(os.environ['GYP_MSVS_OVERRIDE_PATH'],
|
|
|
|
'VC', 'Tools', 'MSVC')
|
|
|
|
for directory in os.listdir(vc_tools_msvc_root):
|
|
|
|
if not os.path.isdir(os.path.join(vc_tools_msvc_root, directory)):
|
|
|
|
continue
|
|
|
|
if re.match('14\.\d+\.\d+', directory):
|
|
|
|
return os.path.join(vc_tools_msvc_root, directory, 'bin')
|
|
|
|
raise Exception('Unable to find the VC tools directory.')
|
|
|
|
|
|
|
|
|
2017-05-12 18:29:26 +03:00
|
|
|
def _CopyPGORuntime(target_dir, target_cpu):
|
|
|
|
"""Copy the runtime dependencies required during a PGO build.
|
|
|
|
"""
|
|
|
|
env_version = GetVisualStudioVersion()
|
|
|
|
# These dependencies will be in a different location depending on the version
|
|
|
|
# of the toolchain.
|
2017-12-06 00:09:47 +03:00
|
|
|
if env_version == '2017':
|
2017-05-20 18:00:06 +03:00
|
|
|
pgo_runtime_root = FindVCToolsRoot()
|
2017-05-12 18:29:26 +03:00
|
|
|
assert pgo_runtime_root
|
|
|
|
# There's no version of pgosweep.exe in HostX64/x86, so we use the copy
|
|
|
|
# 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')
|
|
|
|
else:
|
|
|
|
raise Exception('Unexpected toolchain version: %s.' % env_version)
|
|
|
|
|
|
|
|
# We need to copy 2 runtime dependencies used during the profiling step:
|
|
|
|
# - pgort140.dll: runtime library required to run the instrumented image.
|
|
|
|
# - pgosweep.exe: executable used to collect the profiling data
|
|
|
|
pgo_runtimes = ['pgort140.dll', 'pgosweep.exe']
|
|
|
|
for runtime in pgo_runtimes:
|
|
|
|
if target_cpu == 'x86':
|
|
|
|
source = os.path.join(pgo_x86_runtime_dir, runtime)
|
|
|
|
elif target_cpu == 'x64':
|
|
|
|
source = os.path.join(pgo_x64_runtime_dir, runtime)
|
|
|
|
else:
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2015-11-21 05:21:52 +03:00
|
|
|
def _CopyRuntime(target_dir, source_dir, target_cpu, debug):
|
|
|
|
"""Copy the VS runtime DLLs, only if the target doesn't exist, but the target
|
2017-03-27 23:59:15 +03:00
|
|
|
directory does exist. Handles VS 2015 and VS 2017."""
|
2015-11-21 05:21:52 +03:00
|
|
|
suffix = "d.dll" if debug else ".dll"
|
2017-03-27 23:59:15 +03:00
|
|
|
# VS 2017 uses the same CRT DLLs as VS 2015.
|
|
|
|
_CopyUCRTRuntime(target_dir, source_dir, target_cpu, '%s140' + suffix,
|
|
|
|
suffix)
|
2015-11-21 05:21:52 +03:00
|
|
|
|
Rework win_toolchains a bit and copy the vs runtime DLLs as needed.
In order to run both the visual studio tools and the binaries built
by them (and ninja), we need to ensure that the VS runtime DLLs
are available in the path.
In the GYP build, we accomplish this by copying them into the
Debug and Debug_x64 dirs as appropriate inside the gyp_chromium
script.
In the pure-GN build, then, things would be broken, so we need to
modify the GN build to do the copy as well, or we need to inject
a step somewhere that happens after GN runs but before Ninja tries
to run (since none of the toolchain binaries will work).
This patch accomplishes this by calling out to vs_toolchain.py to
copy the DLLs as neede when the toolchain is defined. This is somewhat
less than ideal (makes 'gn gen' slower) but seems better than forcing
devs to have to run an additional command.
In addition, the GYP build writes targets into Debug and Debug_x64
concurrently. This doesn't really carry over into GN correctly, and
we probably only ever want to write targets into Debug and Debug/64
(or some such).
However, the way the toolchains are currently implemented, it's not
clear if this really works and the interplay between 32-bit and 64-bit
is weird (we apparently normally "force" 32-bit even if we set cpu_arch
to 64-bit, and require you to specify force_win64). To work around this
and make sure that we copy the right DLLs for the right arch into the
outer Debug/ directory, this patch temporarily disables the cross-arch
part of the build, forcing the host_toolchain to match the target_toolchain.
This likely means that 'cpu_arch="x86"' works (the default), but the 'host'
binaries like image_diff and mksnapshot will be compiled in 32-bit mode,
not 64-bit mode. 'cpu_arch="x64" force_win64=true' should also work, and
produce all-64-bit binaries. 'cpu_arch="x64"' does not work at all and
won't until we can clean up the above stuff.
R=scottmg@chromium.org, brettw@chromium.org
BUG=430661
Review URL: https://codereview.chromium.org/722723004
Cr-Original-Commit-Position: refs/heads/master@{#304310}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 0b95195e49489b7a4d87048d2ce4b747173a5b8a
2014-11-15 03:09:14 +03:00
|
|
|
|
2015-02-20 05:55:19 +03:00
|
|
|
def CopyDlls(target_dir, configuration, target_cpu):
|
Rework win_toolchains a bit and copy the vs runtime DLLs as needed.
In order to run both the visual studio tools and the binaries built
by them (and ninja), we need to ensure that the VS runtime DLLs
are available in the path.
In the GYP build, we accomplish this by copying them into the
Debug and Debug_x64 dirs as appropriate inside the gyp_chromium
script.
In the pure-GN build, then, things would be broken, so we need to
modify the GN build to do the copy as well, or we need to inject
a step somewhere that happens after GN runs but before Ninja tries
to run (since none of the toolchain binaries will work).
This patch accomplishes this by calling out to vs_toolchain.py to
copy the DLLs as neede when the toolchain is defined. This is somewhat
less than ideal (makes 'gn gen' slower) but seems better than forcing
devs to have to run an additional command.
In addition, the GYP build writes targets into Debug and Debug_x64
concurrently. This doesn't really carry over into GN correctly, and
we probably only ever want to write targets into Debug and Debug/64
(or some such).
However, the way the toolchains are currently implemented, it's not
clear if this really works and the interplay between 32-bit and 64-bit
is weird (we apparently normally "force" 32-bit even if we set cpu_arch
to 64-bit, and require you to specify force_win64). To work around this
and make sure that we copy the right DLLs for the right arch into the
outer Debug/ directory, this patch temporarily disables the cross-arch
part of the build, forcing the host_toolchain to match the target_toolchain.
This likely means that 'cpu_arch="x86"' works (the default), but the 'host'
binaries like image_diff and mksnapshot will be compiled in 32-bit mode,
not 64-bit mode. 'cpu_arch="x64" force_win64=true' should also work, and
produce all-64-bit binaries. 'cpu_arch="x64"' does not work at all and
won't until we can clean up the above stuff.
R=scottmg@chromium.org, brettw@chromium.org
BUG=430661
Review URL: https://codereview.chromium.org/722723004
Cr-Original-Commit-Position: refs/heads/master@{#304310}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 0b95195e49489b7a4d87048d2ce4b747173a5b8a
2014-11-15 03:09:14 +03:00
|
|
|
"""Copy the VS runtime DLLs into the requested directory as needed.
|
|
|
|
|
|
|
|
configuration is one of 'Debug' or 'Release'.
|
2015-02-20 05:55:19 +03:00
|
|
|
target_cpu is one of 'x86' or 'x64'.
|
Rework win_toolchains a bit and copy the vs runtime DLLs as needed.
In order to run both the visual studio tools and the binaries built
by them (and ninja), we need to ensure that the VS runtime DLLs
are available in the path.
In the GYP build, we accomplish this by copying them into the
Debug and Debug_x64 dirs as appropriate inside the gyp_chromium
script.
In the pure-GN build, then, things would be broken, so we need to
modify the GN build to do the copy as well, or we need to inject
a step somewhere that happens after GN runs but before Ninja tries
to run (since none of the toolchain binaries will work).
This patch accomplishes this by calling out to vs_toolchain.py to
copy the DLLs as neede when the toolchain is defined. This is somewhat
less than ideal (makes 'gn gen' slower) but seems better than forcing
devs to have to run an additional command.
In addition, the GYP build writes targets into Debug and Debug_x64
concurrently. This doesn't really carry over into GN correctly, and
we probably only ever want to write targets into Debug and Debug/64
(or some such).
However, the way the toolchains are currently implemented, it's not
clear if this really works and the interplay between 32-bit and 64-bit
is weird (we apparently normally "force" 32-bit even if we set cpu_arch
to 64-bit, and require you to specify force_win64). To work around this
and make sure that we copy the right DLLs for the right arch into the
outer Debug/ directory, this patch temporarily disables the cross-arch
part of the build, forcing the host_toolchain to match the target_toolchain.
This likely means that 'cpu_arch="x86"' works (the default), but the 'host'
binaries like image_diff and mksnapshot will be compiled in 32-bit mode,
not 64-bit mode. 'cpu_arch="x64" force_win64=true' should also work, and
produce all-64-bit binaries. 'cpu_arch="x64"' does not work at all and
won't until we can clean up the above stuff.
R=scottmg@chromium.org, brettw@chromium.org
BUG=430661
Review URL: https://codereview.chromium.org/722723004
Cr-Original-Commit-Position: refs/heads/master@{#304310}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 0b95195e49489b7a4d87048d2ce4b747173a5b8a
2014-11-15 03:09:14 +03:00
|
|
|
|
|
|
|
The debug configuration gets both the debug and release DLLs; the
|
|
|
|
release config only the latter.
|
|
|
|
"""
|
2015-11-21 05:21:52 +03:00
|
|
|
vs_runtime_dll_dirs = SetEnvironmentAndGetRuntimeDllDirs()
|
|
|
|
if not vs_runtime_dll_dirs:
|
Rework win_toolchains a bit and copy the vs runtime DLLs as needed.
In order to run both the visual studio tools and the binaries built
by them (and ninja), we need to ensure that the VS runtime DLLs
are available in the path.
In the GYP build, we accomplish this by copying them into the
Debug and Debug_x64 dirs as appropriate inside the gyp_chromium
script.
In the pure-GN build, then, things would be broken, so we need to
modify the GN build to do the copy as well, or we need to inject
a step somewhere that happens after GN runs but before Ninja tries
to run (since none of the toolchain binaries will work).
This patch accomplishes this by calling out to vs_toolchain.py to
copy the DLLs as neede when the toolchain is defined. This is somewhat
less than ideal (makes 'gn gen' slower) but seems better than forcing
devs to have to run an additional command.
In addition, the GYP build writes targets into Debug and Debug_x64
concurrently. This doesn't really carry over into GN correctly, and
we probably only ever want to write targets into Debug and Debug/64
(or some such).
However, the way the toolchains are currently implemented, it's not
clear if this really works and the interplay between 32-bit and 64-bit
is weird (we apparently normally "force" 32-bit even if we set cpu_arch
to 64-bit, and require you to specify force_win64). To work around this
and make sure that we copy the right DLLs for the right arch into the
outer Debug/ directory, this patch temporarily disables the cross-arch
part of the build, forcing the host_toolchain to match the target_toolchain.
This likely means that 'cpu_arch="x86"' works (the default), but the 'host'
binaries like image_diff and mksnapshot will be compiled in 32-bit mode,
not 64-bit mode. 'cpu_arch="x64" force_win64=true' should also work, and
produce all-64-bit binaries. 'cpu_arch="x64"' does not work at all and
won't until we can clean up the above stuff.
R=scottmg@chromium.org, brettw@chromium.org
BUG=430661
Review URL: https://codereview.chromium.org/722723004
Cr-Original-Commit-Position: refs/heads/master@{#304310}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 0b95195e49489b7a4d87048d2ce4b747173a5b8a
2014-11-15 03:09:14 +03:00
|
|
|
return
|
|
|
|
|
2015-11-21 05:21:52 +03:00
|
|
|
x64_runtime, x86_runtime = vs_runtime_dll_dirs
|
2015-02-20 05:55:19 +03:00
|
|
|
runtime_dir = x64_runtime if target_cpu == 'x64' else x86_runtime
|
2015-11-21 05:21:52 +03:00
|
|
|
_CopyRuntime(target_dir, runtime_dir, target_cpu, debug=False)
|
Rework win_toolchains a bit and copy the vs runtime DLLs as needed.
In order to run both the visual studio tools and the binaries built
by them (and ninja), we need to ensure that the VS runtime DLLs
are available in the path.
In the GYP build, we accomplish this by copying them into the
Debug and Debug_x64 dirs as appropriate inside the gyp_chromium
script.
In the pure-GN build, then, things would be broken, so we need to
modify the GN build to do the copy as well, or we need to inject
a step somewhere that happens after GN runs but before Ninja tries
to run (since none of the toolchain binaries will work).
This patch accomplishes this by calling out to vs_toolchain.py to
copy the DLLs as neede when the toolchain is defined. This is somewhat
less than ideal (makes 'gn gen' slower) but seems better than forcing
devs to have to run an additional command.
In addition, the GYP build writes targets into Debug and Debug_x64
concurrently. This doesn't really carry over into GN correctly, and
we probably only ever want to write targets into Debug and Debug/64
(or some such).
However, the way the toolchains are currently implemented, it's not
clear if this really works and the interplay between 32-bit and 64-bit
is weird (we apparently normally "force" 32-bit even if we set cpu_arch
to 64-bit, and require you to specify force_win64). To work around this
and make sure that we copy the right DLLs for the right arch into the
outer Debug/ directory, this patch temporarily disables the cross-arch
part of the build, forcing the host_toolchain to match the target_toolchain.
This likely means that 'cpu_arch="x86"' works (the default), but the 'host'
binaries like image_diff and mksnapshot will be compiled in 32-bit mode,
not 64-bit mode. 'cpu_arch="x64" force_win64=true' should also work, and
produce all-64-bit binaries. 'cpu_arch="x64"' does not work at all and
won't until we can clean up the above stuff.
R=scottmg@chromium.org, brettw@chromium.org
BUG=430661
Review URL: https://codereview.chromium.org/722723004
Cr-Original-Commit-Position: refs/heads/master@{#304310}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 0b95195e49489b7a4d87048d2ce4b747173a5b8a
2014-11-15 03:09:14 +03:00
|
|
|
if configuration == 'Debug':
|
2015-11-21 05:21:52 +03:00
|
|
|
_CopyRuntime(target_dir, runtime_dir, target_cpu, debug=True)
|
2017-05-12 18:29:26 +03:00
|
|
|
else:
|
|
|
|
_CopyPGORuntime(target_dir, target_cpu)
|
2014-07-22 04:18:32 +04:00
|
|
|
|
2017-04-20 01:27:40 +03:00
|
|
|
_CopyDebugger(target_dir, target_cpu)
|
|
|
|
|
|
|
|
|
|
|
|
def _CopyDebugger(target_dir, target_cpu):
|
2017-06-30 01:24:39 +03:00
|
|
|
"""Copy dbghelp.dll and dbgcore.dll into the requested directory as needed.
|
2017-04-20 01:27:40 +03:00
|
|
|
|
|
|
|
target_cpu is one of 'x86' or 'x64'.
|
|
|
|
|
|
|
|
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
|
|
|
|
ensures compatibility with recent debug information formats, such as VS
|
|
|
|
2017 /debug:fastlink PDBs.
|
2017-06-30 01:24:39 +03:00
|
|
|
|
|
|
|
dbgcore.dll is needed when using some functions from dbghelp.dll (like
|
|
|
|
MinidumpWriteDump).
|
2017-04-20 01:27:40 +03:00
|
|
|
"""
|
|
|
|
win_sdk_dir = SetEnvironmentAndGetSDKDir()
|
|
|
|
if not win_sdk_dir:
|
|
|
|
return
|
|
|
|
|
2017-08-11 19:40:45 +03:00
|
|
|
# List of debug files that should be copied, the first element of the tuple is
|
|
|
|
# the name of the file and the second indicates if it's optional.
|
|
|
|
debug_files = [('dbghelp.dll', False), ('dbgcore.dll', True)]
|
|
|
|
for debug_file, is_optional in debug_files:
|
2017-06-30 01:24:39 +03:00
|
|
|
full_path = os.path.join(win_sdk_dir, 'Debuggers', target_cpu, debug_file)
|
|
|
|
if not os.path.exists(full_path):
|
2017-08-11 19:40:45 +03:00
|
|
|
if is_optional:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
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))
|
2017-06-30 01:24:39 +03:00
|
|
|
target_path = os.path.join(target_dir, debug_file)
|
|
|
|
_CopyRuntimeImpl(target_path, full_path)
|
2017-04-20 01:27:40 +03:00
|
|
|
|
2014-03-20 02:01:39 +04:00
|
|
|
|
2014-04-09 05:56:20 +04:00
|
|
|
def _GetDesiredVsToolchainHashes():
|
|
|
|
"""Load a list of SHA1s corresponding to the toolchains that we want installed
|
|
|
|
to build with."""
|
2017-03-11 04:46:42 +03:00
|
|
|
env_version = GetVisualStudioVersion()
|
2017-03-25 02:10:01 +03:00
|
|
|
if env_version == '2017':
|
2017-12-16 01:06:00 +03:00
|
|
|
# VS 2017 Update 3.2 with 10.0.15063.468 SDK, patched setenv.cmd, and
|
|
|
|
# 10.0.16299.15 debuggers.
|
|
|
|
return ['1180cb75833ea365097e279efb2d5d7a42dee4b0']
|
2017-03-11 04:46:42 +03:00
|
|
|
raise Exception('Unsupported VS version %s' % env_version)
|
2014-04-09 05:56:20 +04:00
|
|
|
|
|
|
|
|
2016-01-16 01:29:57 +03:00
|
|
|
def ShouldUpdateToolchain():
|
|
|
|
"""Check if the toolchain should be upgraded."""
|
|
|
|
if not os.path.exists(json_data_file):
|
|
|
|
return True
|
|
|
|
with open(json_data_file, 'r') as tempf:
|
|
|
|
toolchain_data = json.load(tempf)
|
|
|
|
version = toolchain_data['version']
|
|
|
|
env_version = GetVisualStudioVersion()
|
|
|
|
# If there's a mismatch between the version set in the environment and the one
|
|
|
|
# in the json file then the toolchain should be updated.
|
|
|
|
return version != env_version
|
|
|
|
|
|
|
|
|
2015-08-12 01:25:00 +03:00
|
|
|
def Update(force=False):
|
2014-04-09 05:56:20 +04:00
|
|
|
"""Requests an update of the toolchain to the specific hashes we have at
|
|
|
|
this revision. The update outputs a .json of the various configuration
|
|
|
|
information required to pass to gyp which we use in |GetToolchainDir()|.
|
|
|
|
"""
|
2015-08-12 01:25:00 +03:00
|
|
|
if force != False and force != '--force':
|
|
|
|
print >>sys.stderr, 'Unknown parameter "%s"' % force
|
|
|
|
return 1
|
|
|
|
if force == '--force' or os.path.exists(json_data_file):
|
|
|
|
force = True
|
|
|
|
|
2014-04-09 05:56:20 +04:00
|
|
|
depot_tools_win_toolchain = \
|
|
|
|
bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1')))
|
2015-08-12 01:25:00 +03:00
|
|
|
if ((sys.platform in ('win32', 'cygwin') or force) and
|
|
|
|
depot_tools_win_toolchain):
|
2014-04-09 05:56:20 +04:00
|
|
|
import find_depot_tools
|
|
|
|
depot_tools_path = find_depot_tools.add_depot_tools_to_path()
|
2017-10-12 21:52:40 +03:00
|
|
|
|
|
|
|
# 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')
|
|
|
|
if sys.platform.startswith('linux') and not os.path.ismount(toolchain_dir):
|
|
|
|
import distutils.spawn
|
|
|
|
ciopfs = distutils.spawn.find_executable('ciopfs')
|
|
|
|
if not ciopfs:
|
|
|
|
# TODO(thakis): Offer to auto-install this? Or have a
|
|
|
|
# build/install-build-deps-win.sh script and point to that? (Or run
|
|
|
|
# that?)
|
|
|
|
print >>sys.stderr, \
|
|
|
|
"\n\tCouldn't set up case-insensitive mount for Windows SDK."
|
|
|
|
print >>sys.stderr, \
|
|
|
|
"\tPlease run `sudo apt-get install ciopfs` and try again.\n"
|
|
|
|
return 1
|
|
|
|
if not os.path.isdir(toolchain_dir):
|
|
|
|
os.mkdir(toolchain_dir)
|
|
|
|
if not os.path.isdir(toolchain_dir + '.ciopfs'):
|
|
|
|
os.mkdir(toolchain_dir + '.ciopfs')
|
2017-10-16 21:07:05 +03:00
|
|
|
# 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])
|
2017-10-12 21:52:40 +03:00
|
|
|
|
2016-03-11 22:55:25 +03:00
|
|
|
# Necessary so that get_toolchain_if_necessary.py will put the VS toolkit
|
|
|
|
# in the correct directory.
|
|
|
|
os.environ['GYP_MSVS_VERSION'] = GetVisualStudioVersion()
|
2014-04-09 05:56:20 +04:00
|
|
|
get_toolchain_args = [
|
|
|
|
sys.executable,
|
|
|
|
os.path.join(depot_tools_path,
|
|
|
|
'win_toolchain',
|
|
|
|
'get_toolchain_if_necessary.py'),
|
|
|
|
'--output-json', json_data_file,
|
|
|
|
] + _GetDesiredVsToolchainHashes()
|
2015-08-12 01:25:00 +03:00
|
|
|
if force:
|
|
|
|
get_toolchain_args.append('--force')
|
2014-04-09 05:56:20 +04:00
|
|
|
subprocess.check_call(get_toolchain_args)
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
2016-03-23 03:58:06 +03:00
|
|
|
def NormalizePath(path):
|
|
|
|
while path.endswith("\\"):
|
|
|
|
path = path[:-1]
|
|
|
|
return path
|
|
|
|
|
|
|
|
|
2017-02-16 01:45:26 +03:00
|
|
|
def SetEnvironmentAndGetSDKDir():
|
|
|
|
"""Gets location information about the current sdk (must have been
|
2014-05-29 00:32:01 +04:00
|
|
|
previously updated by 'update'). This is used for the GN build."""
|
2017-05-02 09:12:31 +03:00
|
|
|
SetEnvironmentAndGetRuntimeDllDirs()
|
2014-09-30 23:31:43 +04:00
|
|
|
|
|
|
|
# If WINDOWSSDKDIR is not set, search the default SDK path and set it.
|
|
|
|
if not 'WINDOWSSDKDIR' in os.environ:
|
2016-01-22 02:35:35 +03:00
|
|
|
default_sdk_path = 'C:\\Program Files (x86)\\Windows Kits\\10'
|
2014-09-30 23:31:43 +04:00
|
|
|
if os.path.isdir(default_sdk_path):
|
|
|
|
os.environ['WINDOWSSDKDIR'] = default_sdk_path
|
|
|
|
|
2017-02-16 01:45:26 +03:00
|
|
|
return NormalizePath(os.environ['WINDOWSSDKDIR'])
|
|
|
|
|
|
|
|
|
|
|
|
def GetToolchainDir():
|
|
|
|
"""Gets location information about the current toolchain (must have been
|
|
|
|
previously updated by 'update'). This is used for the GN build."""
|
|
|
|
runtime_dll_dirs = SetEnvironmentAndGetRuntimeDllDirs()
|
|
|
|
win_sdk_dir = SetEnvironmentAndGetSDKDir()
|
|
|
|
|
2014-05-29 00:32:01 +04:00
|
|
|
print '''vs_path = "%s"
|
|
|
|
sdk_path = "%s"
|
|
|
|
vs_version = "%s"
|
|
|
|
wdk_dir = "%s"
|
2014-11-19 22:33:28 +03:00
|
|
|
runtime_dirs = "%s"
|
2014-05-29 00:32:01 +04:00
|
|
|
''' % (
|
2016-03-23 03:58:06 +03:00
|
|
|
NormalizePath(os.environ['GYP_MSVS_OVERRIDE_PATH']),
|
2017-02-16 01:45:26 +03:00
|
|
|
win_sdk_dir,
|
2016-01-13 05:23:30 +03:00
|
|
|
GetVisualStudioVersion(),
|
2016-03-23 03:58:06 +03:00
|
|
|
NormalizePath(os.environ.get('WDK_DIR', '')),
|
2016-02-15 21:18:01 +03:00
|
|
|
os.path.pathsep.join(runtime_dll_dirs or ['None']))
|
2014-04-09 05:56:20 +04:00
|
|
|
|
|
|
|
|
2014-03-20 02:01:39 +04:00
|
|
|
def main():
|
2014-04-09 05:56:20 +04:00
|
|
|
commands = {
|
|
|
|
'update': Update,
|
|
|
|
'get_toolchain_dir': GetToolchainDir,
|
Rework win_toolchains a bit and copy the vs runtime DLLs as needed.
In order to run both the visual studio tools and the binaries built
by them (and ninja), we need to ensure that the VS runtime DLLs
are available in the path.
In the GYP build, we accomplish this by copying them into the
Debug and Debug_x64 dirs as appropriate inside the gyp_chromium
script.
In the pure-GN build, then, things would be broken, so we need to
modify the GN build to do the copy as well, or we need to inject
a step somewhere that happens after GN runs but before Ninja tries
to run (since none of the toolchain binaries will work).
This patch accomplishes this by calling out to vs_toolchain.py to
copy the DLLs as neede when the toolchain is defined. This is somewhat
less than ideal (makes 'gn gen' slower) but seems better than forcing
devs to have to run an additional command.
In addition, the GYP build writes targets into Debug and Debug_x64
concurrently. This doesn't really carry over into GN correctly, and
we probably only ever want to write targets into Debug and Debug/64
(or some such).
However, the way the toolchains are currently implemented, it's not
clear if this really works and the interplay between 32-bit and 64-bit
is weird (we apparently normally "force" 32-bit even if we set cpu_arch
to 64-bit, and require you to specify force_win64). To work around this
and make sure that we copy the right DLLs for the right arch into the
outer Debug/ directory, this patch temporarily disables the cross-arch
part of the build, forcing the host_toolchain to match the target_toolchain.
This likely means that 'cpu_arch="x86"' works (the default), but the 'host'
binaries like image_diff and mksnapshot will be compiled in 32-bit mode,
not 64-bit mode. 'cpu_arch="x64" force_win64=true' should also work, and
produce all-64-bit binaries. 'cpu_arch="x64"' does not work at all and
won't until we can clean up the above stuff.
R=scottmg@chromium.org, brettw@chromium.org
BUG=430661
Review URL: https://codereview.chromium.org/722723004
Cr-Original-Commit-Position: refs/heads/master@{#304310}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 0b95195e49489b7a4d87048d2ce4b747173a5b8a
2014-11-15 03:09:14 +03:00
|
|
|
'copy_dlls': CopyDlls,
|
2014-04-09 05:56:20 +04:00
|
|
|
}
|
|
|
|
if len(sys.argv) < 2 or sys.argv[1] not in commands:
|
|
|
|
print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands)
|
2014-03-20 21:42:25 +04:00
|
|
|
return 1
|
Rework win_toolchains a bit and copy the vs runtime DLLs as needed.
In order to run both the visual studio tools and the binaries built
by them (and ninja), we need to ensure that the VS runtime DLLs
are available in the path.
In the GYP build, we accomplish this by copying them into the
Debug and Debug_x64 dirs as appropriate inside the gyp_chromium
script.
In the pure-GN build, then, things would be broken, so we need to
modify the GN build to do the copy as well, or we need to inject
a step somewhere that happens after GN runs but before Ninja tries
to run (since none of the toolchain binaries will work).
This patch accomplishes this by calling out to vs_toolchain.py to
copy the DLLs as neede when the toolchain is defined. This is somewhat
less than ideal (makes 'gn gen' slower) but seems better than forcing
devs to have to run an additional command.
In addition, the GYP build writes targets into Debug and Debug_x64
concurrently. This doesn't really carry over into GN correctly, and
we probably only ever want to write targets into Debug and Debug/64
(or some such).
However, the way the toolchains are currently implemented, it's not
clear if this really works and the interplay between 32-bit and 64-bit
is weird (we apparently normally "force" 32-bit even if we set cpu_arch
to 64-bit, and require you to specify force_win64). To work around this
and make sure that we copy the right DLLs for the right arch into the
outer Debug/ directory, this patch temporarily disables the cross-arch
part of the build, forcing the host_toolchain to match the target_toolchain.
This likely means that 'cpu_arch="x86"' works (the default), but the 'host'
binaries like image_diff and mksnapshot will be compiled in 32-bit mode,
not 64-bit mode. 'cpu_arch="x64" force_win64=true' should also work, and
produce all-64-bit binaries. 'cpu_arch="x64"' does not work at all and
won't until we can clean up the above stuff.
R=scottmg@chromium.org, brettw@chromium.org
BUG=430661
Review URL: https://codereview.chromium.org/722723004
Cr-Original-Commit-Position: refs/heads/master@{#304310}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 0b95195e49489b7a4d87048d2ce4b747173a5b8a
2014-11-15 03:09:14 +03:00
|
|
|
return commands[sys.argv[1]](*sys.argv[2:])
|
2014-03-20 02:01:39 +04:00
|
|
|
|
2014-03-20 21:42:25 +04:00
|
|
|
|
2014-03-20 02:01:39 +04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|