blob: 91d038c4caa74e4cfa0be2318ad8bc095526701f [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'):
iannucci@chromium.org286210d2014-08-21 02:14:11 +000063 cache_path = os.path.join(os.path.splitdrive(ROOT_DIR)[0] + os.path.sep,
iannucci@chromium.org98d92d62014-08-20 23:53:59 +000064 'b', 'git-cache')
65 else:
66 cache_path = '/b/git-cache'
67
iannucci@chromium.org286210d2014-08-21 02:14:11 +000068 gclientfile = os.path.join(opts.chromium_dir, '.gclient')
69 with open(gclientfile, 'rb') as spec:
iannucci@chromium.org98d92d62014-08-20 23:53:59 +000070 spec = spec.read().splitlines()
71 spec[-1] = 'cache_dir = %r' % (cache_path,)
iannucci@chromium.org286210d2014-08-21 02:14:11 +000072 with open(gclientfile + '.bot', 'wb') as f:
73 f.write('\n'.join(spec))
74
75 args += [
76 '--gclientfile', '.gclient.bot',
77 '--delete_unversioned_trees', '--reset', '--upstream'
78 ]
iannucci@chromium.org98d92d62014-08-20 23:53:59 +000079 else:
80 args.append('--no-history')
81
kjellander@webrtc.org89256622014-08-20 12:10:11 +000082 target_os_list = get_target_os_list()
83 if target_os_list:
84 args += ['--deps=' + target_os_list]
85
86 print 'Running "%s" in %s' % (' '.join(args), opts.chromium_dir)
87 ret = subprocess.call(args, cwd=opts.chromium_dir, env=env)
88 if ret == 0:
89 with open(flag_file, 'wb') as f:
90 f.write(opts.target_revision)
91
92 return ret
93
94
95if __name__ == '__main__':
96 sys.exit(main())