OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # |
| 3 # Copyright 2016 Google Inc. |
| 4 # |
| 5 # Use of this source code is governed by a BSD-style license that can be |
| 6 # found in the LICENSE file. |
| 7 |
| 8 |
| 9 """Download an updated VS toolchain""" |
| 10 |
| 11 |
| 12 import argparse |
| 13 import common |
| 14 import json |
| 15 import os |
| 16 import shlex |
| 17 import shutil |
| 18 import subprocess |
| 19 import sys |
| 20 import utils |
| 21 |
| 22 import win_toolchain_utils |
| 23 |
| 24 |
| 25 # By default the toolchain includes a bunch of unnecessary stuff with long path |
| 26 # names. Trim out directories with these names. |
| 27 IGNORE_LIST = [ |
| 28 'WindowsMobile', |
| 29 'App Certification Kit', |
| 30 'Debuggers', |
| 31 'Extension SDKs', |
| 32 'winrt', |
| 33 'DesignTime', |
| 34 'AccChecker', |
| 35 ] |
| 36 |
| 37 REPO_CHROME = 'https://chromium.googlesource.com/chromium/src.git' |
| 38 |
| 39 |
| 40 def filter_toolchain_files(dirname, files): |
| 41 """Callback for shutil.copytree. Return lists of files to skip.""" |
| 42 split = dirname.split(os.path.sep) |
| 43 for ign in IGNORE_LIST: |
| 44 if ign in split: |
| 45 print 'Ignoring dir %s' % dirname |
| 46 return files |
| 47 return [] |
| 48 |
| 49 |
| 50 def get_toolchain_dir(toolchain_dir_output): |
| 51 """Find the toolchain directory.""" |
| 52 prefix = 'vs_path = ' |
| 53 for line in toolchain_dir_output.splitlines(): |
| 54 if line.startswith(prefix): |
| 55 return line[len(prefix):].strip('"') |
| 56 raise Exception('Unable to find toolchain dir in output:\n%s' % ( |
| 57 toolchain_dir_output)) |
| 58 |
| 59 |
| 60 def gen_toolchain(chrome_path, msvs_version, target_dir): |
| 61 """Update the VS toolchain and copy it to the target_dir.""" |
| 62 with utils.chdir(os.path.join(chrome_path, 'src')): |
| 63 subprocess.check_call([utils.GCLIENT, 'sync']) |
| 64 depot_tools = subprocess.check_output([ |
| 65 'python', os.path.join('build', 'find_depot_tools.py')]).rstrip() |
| 66 with utils.git_branch(): |
| 67 vs_toolchain_py = os.path.join('build', 'vs_toolchain.py') |
| 68 env = os.environ.copy() |
| 69 env['GYP_MSVS_VERSION'] = msvs_version |
| 70 subprocess.check_call(['python', vs_toolchain_py, 'update'], env=env) |
| 71 output = subprocess.check_output(['python', vs_toolchain_py, |
| 72 'get_toolchain_dir'], env=env).rstrip() |
| 73 src_dir = get_toolchain_dir(output) |
| 74 # Mock out absolute paths in win_toolchain.json. |
| 75 win_toolchain_utils.abstract(os.path.join('build', 'win_toolchain.json'), |
| 76 os.path.dirname(depot_tools)) |
| 77 |
| 78 # Copy the toolchain files to the target_dir. |
| 79 build = os.path.join(os.getcwd(), 'build') |
| 80 dst_build = os.path.join(target_dir, 'src', 'build') |
| 81 os.makedirs(dst_build) |
| 82 for f in ('find_depot_tools.py', 'vs_toolchain.py', 'win_toolchain.json'): |
| 83 shutil.copyfile(os.path.join(build, f), os.path.join(dst_build, f)) |
| 84 |
| 85 shutil.copytree(os.path.join(os.getcwd(), 'tools', 'gyp', 'pylib'), |
| 86 os.path.join(target_dir, 'src', 'tools', 'gyp', 'pylib')) |
| 87 |
| 88 dst_depot_tools = os.path.join(target_dir, 'depot_tools') |
| 89 os.makedirs(dst_depot_tools) |
| 90 for f in ('gclient.py', 'breakpad.py'): |
| 91 shutil.copyfile(os.path.join(depot_tools, f), |
| 92 os.path.join(dst_depot_tools, f)) |
| 93 toolchain_dst = os.path.join( |
| 94 target_dir, 'depot_tools', os.path.relpath(src_dir, depot_tools)) |
| 95 shutil.copytree(src_dir, toolchain_dst, ignore=filter_toolchain_files) |
| 96 |
| 97 |
| 98 def create_asset(target_dir, msvs_version, chrome_path=None): |
| 99 """Create the asset.""" |
| 100 if not os.path.isdir(target_dir): |
| 101 os.makedirs(target_dir) |
| 102 with utils.tmp_dir() as tmp_dir: |
| 103 if not chrome_path: |
| 104 print ('Syncing Chrome from scratch. If you already have a checkout, ' |
| 105 'specify --chrome_path to save time.') |
| 106 chrome_path = os.path.join(tmp_dir.name, 'src') |
| 107 if not os.path.isdir(chrome_path): |
| 108 subprocess.check_call([utils.GCLIENT, 'config', REPO_CHROME, '--managed']) |
| 109 subprocess.check_call([utils.GCLIENT, 'sync']) |
| 110 |
| 111 gen_toolchain(chrome_path, msvs_version, target_dir) |
| 112 |
| 113 def main(): |
| 114 if sys.platform != 'win32': |
| 115 print >> sys.stderr, 'This script only runs on Windows.' |
| 116 sys.exit(1) |
| 117 |
| 118 parser = argparse.ArgumentParser() |
| 119 parser.add_argument('--msvs_version', required=True) |
| 120 parser.add_argument('--chrome_path') |
| 121 parser.add_argument('--target_dir', '-t', required=True) |
| 122 args = parser.parse_args() |
| 123 target_dir = os.path.abspath(args.target_dir) |
| 124 create_asset(target_dir, args.msvs_version, args.chrome_path) |
| 125 |
| 126 |
| 127 if __name__ == '__main__': |
| 128 main() |
OLD | NEW |