blob: 5bd7245cbdc7940a21c7588b55167964140f7501 [file] [log] [blame]
kjellander@webrtc.org89256622014-08-20 12:10:11 +00001#!/usr/bin/env python
2# Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3#
4# Use of this source code is governed by a BSD-style license
5# that can be found in the LICENSE file in the root of the source
6# tree. An additional intellectual property rights grant can be found
7# in the file PATENTS. All contributing project authors may
8# be found in the AUTHORS file in the root of the source tree.
9
10import argparse
11import os
12import subprocess
13import sys
14
15
16ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
17
18
19def get_target_os_list():
20 try:
21 main_gclient = os.path.join(os.path.dirname(ROOT_DIR), '.gclient')
22 config_dict = {}
23 with open(main_gclient, 'rb') as deps_content:
24 exec(deps_content, config_dict)
25 return ','.join(config_dict.get('target_os', []))
26 except Exception as e:
27 print >> sys.stderr, "error while parsing .gclient:", e
28
29
30def main():
31 CR_DIR = os.path.join(ROOT_DIR, 'chromium')
32
33 p = argparse.ArgumentParser()
34 p.add_argument('--target-revision', required=True,
35 help='The target chromium git revision [REQUIRED]')
36 p.add_argument('--chromium-dir', default=CR_DIR,
37 help=('The path to the chromium directory to sync '
38 '(default: %(default)r)'))
39 opts = p.parse_args()
40 opts.chromium_dir = os.path.abspath(opts.chromium_dir)
41
42 # Do a quick check to see if we were successful last time to make runhooks
43 # sooper fast.
44 flag_file = os.path.join(opts.chromium_dir, '.last_sync_chromium')
45 if os.path.exists(flag_file):
46 with open(flag_file, 'r') as f:
47 if f.read() == opts.target_revision:
48 print "Chromium already up to date:", opts.target_revision
49 return 0
50 os.unlink(flag_file)
51
52 env = os.environ.copy()
53 env['GYP_CHROMIUM_NO_ACTION'] = '1'
54 gclient_cmd = 'gclient.bat' if sys.platform.startswith('win') else 'gclient'
55 args = [
iannucci@chromium.org98d92d62014-08-20 23:53:59 +000056 gclient_cmd, 'sync', '--force', '--revision', 'src@'+opts.target_revision
57 ]
58
kjellander@webrtc.org3aa837c2014-08-20 14:25:43 +000059 if os.environ.get('CHROME_HEADLESS') == '1':
60 args.append('-vvv')
61
iannucci@chromium.org98d92d62014-08-20 23:53:59 +000062 if sys.platform.startswith('win'):
63 cache_path = os.path.join(os.path.splitdrive(ROOT_DIR)[0],
64 'b', 'git-cache')
65 else:
66 cache_path = '/b/git-cache'
67
68 with open(os.path.join(opts.chromium_dir, '.gclient'), 'rb') as spec:
69 spec = spec.read().splitlines()
70 spec[-1] = 'cache_dir = %r' % (cache_path,)
71 args.append('--spec')
72 args.append('\n'.join(spec))
73 args.append('--delete_unversioned_trees')
74 args.append('--reset')
75 args.append('--upstream')
76 else:
77 args.append('--no-history')
78
kjellander@webrtc.org89256622014-08-20 12:10:11 +000079 target_os_list = get_target_os_list()
80 if target_os_list:
81 args += ['--deps=' + target_os_list]
82
83 print 'Running "%s" in %s' % (' '.join(args), opts.chromium_dir)
84 ret = subprocess.call(args, cwd=opts.chromium_dir, env=env)
85 if ret == 0:
86 with open(flag_file, 'wb') as f:
87 f.write(opts.target_revision)
88
89 return ret
90
91
92if __name__ == '__main__':
93 sys.exit(main())