chromium-src-build/vs_toolchain.py

363 строки
13 KiB
Python
Исходник Обычный вид История

#!/usr/bin/env python
# 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.
import json
import os
import pipes
import shutil
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'))
json_data_file = os.path.join(script_dir, 'win_toolchain.json')
import gyp
# Use MSVS2013 as the default toolchain.
CURRENT_DEFAULT_TOOLCHAIN_VERSION = '2013'
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.
"""
vs_runtime_dll_dirs = None
depot_tools_win_toolchain = \
bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1')))
# 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).
if ((sys.platform in ('win32', 'cygwin') or os.path.exists(json_data_file))
and depot_tools_win_toolchain):
if ShouldUpdateToolchain():
Update()
with open(json_data_file, 'r') as tempf:
toolchain_data = json.load(tempf)
toolchain = toolchain_data['path']
version = toolchain_data['version']
win_sdk = toolchain_data.get('win_sdk')
if not win_sdk:
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 CopyVsRuntimeDlls call
# below). http://crbug.com/345992
vs_runtime_dll_dirs = toolchain_data['runtime_dirs']
os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain
os.environ['GYP_MSVS_VERSION'] = version
# 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'))
gyp_defines_dict['windows_sdk_path'] = win_sdk
os.environ['GYP_DEFINES'] = ' '.join('%s=%s' % (k, pipes.quote(str(v)))
for k, v in gyp_defines_dict.iteritems())
os.environ['WINDOWSSDKDIR'] = win_sdk
os.environ['WDK_DIR'] = wdk
# Include the VS runtime in the PATH in case it's not machine-installed.
runtime_path = ';'.join(vs_runtime_dll_dirs)
os.environ['PATH'] = runtime_path + ';' + os.environ['PATH']
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()
if not 'GYP_MSVS_VERSION' in os.environ:
os.environ['GYP_MSVS_VERSION'] = GetVisualStudioVersion()
return vs_runtime_dll_dirs
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.')
def GetVisualStudioVersion():
"""Return GYP_MSVS_VERSION of Visual Studio.
"""
return os.environ.get('GYP_MSVS_VERSION', CURRENT_DEFAULT_TOOLCHAIN_VERSION)
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.
version_as_year = GetVisualStudioVersion()
year_to_version = {
'2013': '12.0',
'2015': '14.0',
}
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]
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))
def _VersionNumber():
"""Gets the standard version number ('120', '140', etc.) based on
GYP_MSVS_VERSION."""
vs_version = GetVisualStudioVersion()
if vs_version == '2013':
return '120'
elif vs_version == '2015':
return '140'
else:
raise ValueError('Unexpected GYP_MSVS_VERSION')
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
def _CopyRuntimeImpl(target, source):
"""Copy |source| to |target| if it doesn't already exist or if it
needs to be updated.
"""
if (os.path.isdir(os.path.dirname(target)) and
(not os.path.isfile(target) or
os.stat(target).st_mtime != os.stat(source).st_mtime)):
print 'Copying %s to %s...' % (source, target)
if os.path.exists(target):
os.unlink(target)
shutil.copy2(source, target)
def _CopyRuntime2013(target_dir, source_dir, dll_pattern):
"""Copy both the msvcr and msvcp runtime DLLs, only if the target doesn't
exist, but the target directory does exist."""
for file_part in ('p', 'r'):
dll = dll_pattern % file_part
target = os.path.join(target_dir, dll)
source = os.path.join(source_dir, dll)
_CopyRuntimeImpl(target, source)
def _CopyRuntime2015(target_dir, source_dir, dll_pattern):
"""Copy both the msvcp and vccorlib runtime DLLs, only if the target doesn't
exist, but the target directory does exist."""
for file_part in ('msvcp', 'vccorlib', 'vcruntime'):
dll = dll_pattern % file_part
target = os.path.join(target_dir, dll)
source = os.path.join(source_dir, dll)
_CopyRuntimeImpl(target, source)
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
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 2013 and VS 2015."""
suffix = "d.dll" if debug else ".dll"
if GetVisualStudioVersion() == '2015':
_CopyRuntime2015(target_dir, source_dir, '%s140' + suffix)
New VS 2015 package and copy ucrtbased.dll This switches the VS 2015 package to one that includes the UCRT installers, and it copies ucrtbased.dll to debug directories so that debug binaries will run. The new VS 2015 package was created using the changes in crrev.com/1588673004. This package was created on a clean VM in hopes of making it reproducible. The steps to create it are: Install Windows 7 Professional, 64-bit Install VS 2015 Professional Update 1. Select custom install and these minimum options: - Visual C++ (which selects three sub-categories including MFC) - Universal Windows App Development Tools - Tools (1.2) and Windows 10 SDK (10.0.10586) Then download the Windows 10 SDK. The version must match the one installed with VS 2015 Update 1 or else there will be warnings about the need to uninstall the previous version. Select "Debugging Tools for Windows" in addition to the defaults (Windows App Certification Kit, Windows Software Development Kit). Note, however, that this just downloads the installers. A message will suggest that running setup.exe will install the requested components but actually you have to go into the Downloads\Windows Kits\10\StandaloneSDK\Installers directory to run the x86 and x64 debugger installers. Then download three copies of update 2999226, the Windows 10 Universal C Runtime, for 64-bit Windows 7, Windows 8, and Windows 8.1. Leave these in the downloads folder. This URl contains the download links: https://support.microsoft.com/en-us/kb/2999226 Then install depot_tools and run: > python depot_tools\win_toolchain\package_from_installed.py 2015 Then upload the package with this syntax (replace hash.zip): > python depot_tools\third_party\gsutil\gsutil cp hash.zip gs://chrome-wintoolchain/hash.zip BUG=440500 Review URL: https://codereview.chromium.org/1587073006 Cr-Original-Commit-Position: refs/heads/master@{#369841} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 51f790c13ee0d450d15eca26c3fb558818b7173d
2016-01-16 00:18:06 +03:00
if debug:
_CopyRuntimeImpl(os.path.join(target_dir, 'ucrtbased.dll'),
os.path.join(source_dir, 'ucrtbased.dll'))
else:
_CopyRuntime2013(target_dir, source_dir, 'msvc%s120' + suffix)
# Copy the PGO runtime library to the release directories.
if not debug and os.environ.get('GYP_MSVS_OVERRIDE_PATH'):
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')
pgo_runtime_dll = 'pgort' + _VersionNumber() + '.dll'
if target_cpu == "x86":
source_x86 = os.path.join(pgo_x86_runtime_dir, pgo_runtime_dll)
if os.path.exists(source_x86):
_CopyRuntimeImpl(os.path.join(target_dir, pgo_runtime_dll), source_x86)
elif target_cpu == "x64":
source_x64 = os.path.join(pgo_x64_runtime_dir, pgo_runtime_dll)
if os.path.exists(source_x64):
_CopyRuntimeImpl(os.path.join(target_dir, pgo_runtime_dll),
source_x64)
else:
raise NotImplementedError("Unexpected target_cpu value:" + target_cpu)
def CopyVsRuntimeDlls(output_dir, runtime_dirs):
"""Copies the VS runtime DLLs from the given |runtime_dirs| to the output
directory so that even if not system-installed, built binaries are likely to
be able to run.
This needs to be run after gyp has been run so that the expected target
output directories are already created.
This is used for the GYP build and gclient runhooks.
"""
x86, x64 = runtime_dirs
out_debug = os.path.join(output_dir, 'Debug')
out_debug_nacl64 = os.path.join(output_dir, 'Debug', 'x64')
out_release = os.path.join(output_dir, 'Release')
out_release_nacl64 = os.path.join(output_dir, 'Release', 'x64')
out_debug_x64 = os.path.join(output_dir, 'Debug_x64')
out_release_x64 = os.path.join(output_dir, 'Release_x64')
if os.path.exists(out_debug) and not os.path.exists(out_debug_nacl64):
os.makedirs(out_debug_nacl64)
if os.path.exists(out_release) and not os.path.exists(out_release_nacl64):
os.makedirs(out_release_nacl64)
_CopyRuntime(out_debug, x86, "x86", debug=True)
_CopyRuntime(out_release, x86, "x86", debug=False)
_CopyRuntime(out_debug_x64, x64, "x64", debug=True)
_CopyRuntime(out_release_x64, x64, "x64", debug=False)
_CopyRuntime(out_debug_nacl64, x64, "x64", debug=True)
_CopyRuntime(out_release_nacl64, x64, "x64", 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
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'.
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.
This is used for the GN build.
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
"""
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
x64_runtime, x86_runtime = vs_runtime_dll_dirs
runtime_dir = x64_runtime if target_cpu == 'x64' else x86_runtime
_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':
_CopyRuntime(target_dir, runtime_dir, target_cpu, debug=True)
def _GetDesiredVsToolchainHashes():
"""Load a list of SHA1s corresponding to the toolchains that we want installed
to build with."""
if GetVisualStudioVersion() == '2015':
New VS 2015 package and copy ucrtbased.dll This switches the VS 2015 package to one that includes the UCRT installers, and it copies ucrtbased.dll to debug directories so that debug binaries will run. The new VS 2015 package was created using the changes in crrev.com/1588673004. This package was created on a clean VM in hopes of making it reproducible. The steps to create it are: Install Windows 7 Professional, 64-bit Install VS 2015 Professional Update 1. Select custom install and these minimum options: - Visual C++ (which selects three sub-categories including MFC) - Universal Windows App Development Tools - Tools (1.2) and Windows 10 SDK (10.0.10586) Then download the Windows 10 SDK. The version must match the one installed with VS 2015 Update 1 or else there will be warnings about the need to uninstall the previous version. Select "Debugging Tools for Windows" in addition to the defaults (Windows App Certification Kit, Windows Software Development Kit). Note, however, that this just downloads the installers. A message will suggest that running setup.exe will install the requested components but actually you have to go into the Downloads\Windows Kits\10\StandaloneSDK\Installers directory to run the x86 and x64 debugger installers. Then download three copies of update 2999226, the Windows 10 Universal C Runtime, for 64-bit Windows 7, Windows 8, and Windows 8.1. Leave these in the downloads folder. This URl contains the download links: https://support.microsoft.com/en-us/kb/2999226 Then install depot_tools and run: > python depot_tools\win_toolchain\package_from_installed.py 2015 Then upload the package with this syntax (replace hash.zip): > python depot_tools\third_party\gsutil\gsutil cp hash.zip gs://chrome-wintoolchain/hash.zip BUG=440500 Review URL: https://codereview.chromium.org/1587073006 Cr-Original-Commit-Position: refs/heads/master@{#369841} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 51f790c13ee0d450d15eca26c3fb558818b7173d
2016-01-16 00:18:06 +03:00
# Update 1 with Debuggers, UCRT installers and ucrtbased.dll
return ['5a85cf1ce842f7cc96b9d17039a445a9dc9cf0dd']
else:
# Default to VS2013.
Reland of win: Update to Win 10 SDK (patchset #1 id:1 of https://codereview.chromium.org/1410153007/ ) Reason for revert: Relanding, we think all bots are updated now. Original issue's description: > Revert of win: Update to Win 10 SDK (patchset #8 id:140001 of https://codereview.chromium.org/1378153003/ ) > > Reason for revert: > This is a suspect in breaking Win bots (e.g. here http://build.chromium.org/p/chromium.webkit/builders/WebKit%20Win%20Builder/builds/93039) > > Original issue's description: > > win: Update to Win 10 SDK > > > > Tested on clean Win7 VM against both VS2013 and clang=1 at 247874-1. > > > > R=brucedawson@chromium.org > > BUG=491424 > > > > Committed: https://crrev.com/3f6f89251dc210b24a36398237d374a87d4a3b33 > > Cr-Commit-Position: refs/heads/master@{#352667} > > > > Committed: https://crrev.com/1feffb4b7b1c2bfaf112a8993ae7ab0c16a52da9 > > Cr-Commit-Position: refs/heads/master@{#356373} > > TBR=brucedawson@chromium.org,sky@chromium.org,scottmg@chromium.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=491424 > > Committed: https://crrev.com/e4a933bfce1dce211b29c392a681513a9d69a85c > Cr-Commit-Position: refs/heads/master@{#356484} TBR=brucedawson@chromium.org,sky@chromium.org,caseq@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=491424 Review URL: https://codereview.chromium.org/1502563003 Cr-Original-Commit-Position: refs/heads/master@{#363257} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 510a9e822cf893ec133f1f48643fbf913c24d8c1
2015-12-04 21:46:18 +03:00
return ['9ff97c632ae1fee0c98bcd53e71770eb3a0d8deb']
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
def Update(force=False):
"""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()|.
"""
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
depot_tools_win_toolchain = \
bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', '1')))
if ((sys.platform in ('win32', 'cygwin') or force) and
depot_tools_win_toolchain):
import find_depot_tools
depot_tools_path = find_depot_tools.add_depot_tools_to_path()
get_toolchain_args = [
sys.executable,
os.path.join(depot_tools_path,
'win_toolchain',
'get_toolchain_if_necessary.py'),
'--output-json', json_data_file,
] + _GetDesiredVsToolchainHashes()
if force:
get_toolchain_args.append('--force')
subprocess.check_call(get_toolchain_args)
return 0
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()
# 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\\8.1'
if os.path.isdir(default_sdk_path):
os.environ['WINDOWSSDKDIR'] = default_sdk_path
print '''vs_path = "%s"
sdk_path = "%s"
vs_version = "%s"
wdk_dir = "%s"
runtime_dirs = "%s"
''' % (
os.environ['GYP_MSVS_OVERRIDE_PATH'],
os.environ['WINDOWSSDKDIR'],
GetVisualStudioVersion(),
os.environ.get('WDK_DIR', ''),
';'.join(runtime_dll_dirs or ['None']))
def main():
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,
}
if len(sys.argv) < 2 or sys.argv[1] not in commands:
print >>sys.stderr, 'Expected one of: %s' % ', '.join(commands)
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:])
if __name__ == '__main__':
sys.exit(main())