OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
stephana
2016/03/10 15:03:36
Can you add a short description of what the script
borenet
2016/03/10 21:07:08
Done in https://codereview.chromium.org/1782943002
| |
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 import argparse | |
10 import json | |
11 import os | |
12 import shlex | |
13 import shutil | |
14 import subprocess | |
15 import sys | |
16 import utils | |
17 | |
18 | |
19 REPO_CHROME = 'https://chromium.googlesource.com/chromium/src.git' | |
20 REPO_SKIA = 'https://skia.googlesource.com/skia.git' | |
21 | |
22 | |
23 def get_toolchain_dir(toolchain_dir_output): | |
24 """Find the toolchain directory.""" | |
25 prefix = 'vs_path = ' | |
26 for line in toolchain_dir_output.splitlines(): | |
27 if line.startswith(prefix): | |
28 return line[len(prefix):].strip('"') | |
29 raise Exception('Unable to find toolchain dir in output:\n%s' % ( | |
30 toolchain_dir_output)) | |
31 | |
32 | |
33 def gen_toolchain(chrome_path, msvs_version, isolate_file): | |
34 """Update the VS toolchain, isolate it, and return the isolated hash.""" | |
35 with utils.chdir(chrome_path): | |
36 subprocess.check_call([utils.GCLIENT, 'sync']) | |
37 with utils.git_branch(): | |
38 vs_toolchain_py = os.path.join('build', 'vs_toolchain.py') | |
39 env = os.environ.copy() | |
40 env['GYP_MSVS_VERSION'] = msvs_version | |
41 subprocess.check_call(['python', vs_toolchain_py, 'update'], env=env) | |
42 output = subprocess.check_output(['python', vs_toolchain_py, | |
43 'get_toolchain_dir'], env=env).rstrip() | |
44 src_dir = get_toolchain_dir(output) | |
45 | |
46 # Isolate the toolchain. Assumes we're running on Windows, since the above | |
47 # would fail otherwise. | |
48 rel_path = os.path.relpath(src_dir, os.path.dirname(isolate_file)) | |
49 isolate = os.path.join( | |
50 os.curdir, 'tools', 'luci-go', 'win64', 'isolate.exe') | |
51 isolate_cmd = [isolate, 'archive', '--quiet', | |
52 '--isolate-server', 'https://isolateserver.appspot.com', | |
53 '-i', isolate_file, | |
54 '-s', 'win_toolchain_%s.isolated' % msvs_version, | |
55 '--extra-variable', 'WIN_TOOLCHAIN_DIR=%s' % rel_path] | |
56 isolate_out = subprocess.check_output(isolate_cmd).rstrip() | |
57 return shlex.split(isolate_out)[0] | |
58 | |
59 | |
60 def update_toolchain_file(skia_path, msvs_version, isolated_hash): | |
61 """Edit the win_toolchain_hash file, upload a CL.""" | |
62 with utils.chdir(skia_path): | |
63 with utils.git_branch(): | |
64 hash_file = os.path.join('infra', 'bots', 'win_toolchain_hash.json') | |
65 with open(hash_file) as f: | |
66 hashes = json.load(f) | |
67 hashes[msvs_version] = isolated_hash | |
68 with open(hash_file, 'w') as f: | |
69 json.dump(hashes, f, indent=4, sort_keys=True) | |
70 subprocess.check_call([utils.GIT, 'add', hash_file]) | |
71 subprocess.check_call([utils.GIT, 'commit', '-m', 'Update Win toolchain']) | |
72 subprocess.check_call([utils.GIT, 'cl', 'upload', '--bypass-hooks']) | |
73 | |
74 | |
75 def main(): | |
76 parser = argparse.ArgumentParser() | |
77 parser.add_argument('--msvs_version', required=True) | |
78 parser.add_argument('--chrome_path') | |
79 parser.add_argument('--skia_path') | |
80 args = parser.parse_args() | |
81 | |
82 isolate_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), | |
83 'win_toolchain.isolate') | |
84 | |
85 with utils.print_timings(): | |
86 with utils.tmp_dir() as tmp_dir: | |
87 chrome_path = args.chrome_path | |
88 if not chrome_path: | |
89 print ('Syncing Chrome from scratch. If you already have a checkout, ' | |
90 'specify --chrome_path to save time.') | |
91 chrome_path = os.path.join(tmp_dir.name, 'src') | |
92 if not os.path.isdir(chrome_path): | |
93 utils.git_clone(REPO_CHROME, chrome_path) | |
94 | |
95 skia_path = args.skia_path | |
96 if not skia_path: | |
97 print ('Syncing Skia from scratch. If you already have a checkout, ' | |
98 'specify --chrome_path to save time.') | |
99 skia_path = os.path.join(tmp_dir.name, 'skia') | |
100 if not os.path.isdir(skia_path): | |
101 utils.git_clone(REPO_SKIA, skia_path) | |
102 | |
103 isolated_hash = gen_toolchain(chrome_path, args.msvs_version, | |
104 isolate_file) | |
105 update_toolchain_file(skia_path, args.msvs_version, isolated_hash) | |
106 | |
107 | |
108 if __name__ == '__main__': | |
109 main() | |
OLD | NEW |