sync_chromium.py revision bbca4dde0cd3755f97f0d00f0330b0469a88c4da
1#!/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 = [
56      gclient_cmd, 'sync', '--no-history', '--force', '--verbose', '--revision',
57      'src@'+opts.target_revision]
58  target_os_list = get_target_os_list()
59  if target_os_list:
60    args += ['--deps=' + target_os_list]
61
62  print 'Running "%s" in %s' % (' '.join(args), opts.chromium_dir)
63  ret = subprocess.call(args, cwd=opts.chromium_dir, env=env)
64  if ret == 0:
65    with open(flag_file, 'wb') as f:
66      f.write(opts.target_revision)
67
68  return ret
69
70
71if __name__ == '__main__':
72  sys.exit(main())
73