Copy VS runtime DLLs to output directory

When using the automatic toolchain for vs2013, they won't necessarily
be system-installed, so copy them next to the output binaries.

R=dpranke@chromium.org
BUG=326357

Review URL: https://codereview.chromium.org/149113004

git-svn-id: http://src.chromium.org/svn/trunk/src/build@248790 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
This commit is contained in:
scottmg@chromium.org 2014-02-04 22:11:57 +00:00
Родитель 88410a86e3
Коммит d278b247d8
1 изменённых файлов: 43 добавлений и 1 удалений

Просмотреть файл

@ -12,6 +12,7 @@ import gyp_helper
import os
import pipes
import shlex
import shutil
import subprocess
import string
import sys
@ -326,6 +327,39 @@ def RunGN(supplemental_includes):
return subprocess.call(args) == 0
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.
"""
assert sys.platform.startswith(('win32', 'cygwin'))
def copy_runtime(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 which in ('p', 'r'):
dll = dll_pattern % which
target = os.path.join(target_dir, dll)
source = os.path.join(source_dir, dll)
# If gyp generated to that output dir, and the runtime isn't already
# there, then copy it over.
if os.path.isdir(target_dir) and not os.path.isfile(target):
shutil.copyfile(source, target)
x86, x64 = runtime_dirs
out_debug = os.path.join(output_dir, 'Debug')
out_release = os.path.join(output_dir, 'Release')
out_debug_x64 = os.path.join(output_dir, 'Debug_x64')
out_release_x64 = os.path.join(output_dir, 'Release_x64')
copy_runtime(out_debug, x86, 'msvc%s120d.dll')
copy_runtime(out_release, x86, 'msvc%s120.dll')
copy_runtime(out_debug_x64, x64, 'msvc%s120d.dll')
copy_runtime(out_release_x64, x64, 'msvc%s120.dll')
if __name__ == '__main__':
args = sys.argv[1:]
@ -402,6 +436,7 @@ if __name__ == '__main__':
# If using ninja on windows, and the automatic toolchain has been installed
# by depot_tools, then use it.
vs2013_runtime_dll_dirs = None
if (sys.platform in ('win32', 'cygwin') and
os.environ.get('GYP_GENERATORS') == 'ninja'):
depot_tools_path = find_depot_tools.add_depot_tools_to_path()
@ -412,6 +447,8 @@ if __name__ == '__main__':
os.environ['GYP_MSVS_OVERRIDE_PATH'] = toolchain
with open(version_file, 'r') as f:
version_is_pro = f.read().strip() == 'pro'
vs2013_runtime_dll_dirs = (os.path.join(toolchain, 'sys32'),
os.path.join(toolchain, 'sys64'))
os.environ['GYP_MSVS_VERSION'] = '2013' if version_is_pro else '2013e'
# 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 other
@ -449,4 +486,9 @@ if __name__ == '__main__':
sys.stdout.flush()
# Off we go...
sys.exit(gyp.main(args))
gyp_rc = gyp.main(args)
if vs2013_runtime_dll_dirs:
CopyVsRuntimeDlls(GetOutputDirectory(), vs2013_runtime_dll_dirs)
sys.exit(gyp_rc)