kjellander@webrtc.org | 8925662 | 2014-08-20 12:10:11 +0000 | [diff] [blame] | 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 | |
| 10 | import argparse |
| 11 | import os |
| 12 | import subprocess |
| 13 | import sys |
| 14 | |
iannucci@chromium.org | 1613638 | 2014-08-21 15:48:23 +0000 | [diff] [blame] | 15 | # Bump this whenever the algorithm changes and you need bots/devs to re-sync, |
| 16 | # ignoring the .last_sync_chromium file |
kjellander@webrtc.org | dc926a0 | 2014-08-26 19:22:03 +0000 | [diff] [blame] | 17 | SCRIPT_VERSION = 2 |
kjellander@webrtc.org | 8925662 | 2014-08-20 12:10:11 +0000 | [diff] [blame] | 18 | |
| 19 | ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 20 | |
| 21 | |
| 22 | def get_target_os_list(): |
| 23 | try: |
| 24 | main_gclient = os.path.join(os.path.dirname(ROOT_DIR), '.gclient') |
| 25 | config_dict = {} |
| 26 | with open(main_gclient, 'rb') as deps_content: |
| 27 | exec(deps_content, config_dict) |
| 28 | return ','.join(config_dict.get('target_os', [])) |
| 29 | except Exception as e: |
| 30 | print >> sys.stderr, "error while parsing .gclient:", e |
| 31 | |
| 32 | |
| 33 | def main(): |
| 34 | CR_DIR = os.path.join(ROOT_DIR, 'chromium') |
| 35 | |
| 36 | p = argparse.ArgumentParser() |
| 37 | p.add_argument('--target-revision', required=True, |
| 38 | help='The target chromium git revision [REQUIRED]') |
| 39 | p.add_argument('--chromium-dir', default=CR_DIR, |
| 40 | help=('The path to the chromium directory to sync ' |
| 41 | '(default: %(default)r)')) |
| 42 | opts = p.parse_args() |
| 43 | opts.chromium_dir = os.path.abspath(opts.chromium_dir) |
| 44 | |
iannucci@chromium.org | 1613638 | 2014-08-21 15:48:23 +0000 | [diff] [blame] | 45 | target_os_list = get_target_os_list() |
| 46 | |
kjellander@webrtc.org | 8925662 | 2014-08-20 12:10:11 +0000 | [diff] [blame] | 47 | # Do a quick check to see if we were successful last time to make runhooks |
| 48 | # sooper fast. |
| 49 | flag_file = os.path.join(opts.chromium_dir, '.last_sync_chromium') |
iannucci@chromium.org | 1613638 | 2014-08-21 15:48:23 +0000 | [diff] [blame] | 50 | flag_file_content = '\n'.join([ |
| 51 | str(SCRIPT_VERSION), |
| 52 | opts.target_revision, |
| 53 | repr(target_os_list), |
| 54 | ]) |
kjellander@webrtc.org | 8925662 | 2014-08-20 12:10:11 +0000 | [diff] [blame] | 55 | if os.path.exists(flag_file): |
| 56 | with open(flag_file, 'r') as f: |
iannucci@chromium.org | 1613638 | 2014-08-21 15:48:23 +0000 | [diff] [blame] | 57 | if f.read() == flag_file_content: |
kjellander@webrtc.org | 8925662 | 2014-08-20 12:10:11 +0000 | [diff] [blame] | 58 | print "Chromium already up to date:", opts.target_revision |
| 59 | return 0 |
| 60 | os.unlink(flag_file) |
| 61 | |
kjellander@webrtc.org | e94f83a | 2014-09-18 13:47:23 +0000 | [diff] [blame] | 62 | # To avoid gclient sync problems when DEPS entries have been removed we must |
| 63 | # wipe the .gclient_entries file that contains cached URLs for all DEPS. |
| 64 | entries_file = os.path.join(opts.chromium_dir, '.gclient_entries') |
| 65 | if os.path.exists(entries_file): |
| 66 | os.unlink(entries_file) |
| 67 | |
kjellander@webrtc.org | 8925662 | 2014-08-20 12:10:11 +0000 | [diff] [blame] | 68 | env = os.environ.copy() |
| 69 | env['GYP_CHROMIUM_NO_ACTION'] = '1' |
| 70 | gclient_cmd = 'gclient.bat' if sys.platform.startswith('win') else 'gclient' |
| 71 | args = [ |
iannucci@chromium.org | 98d92d6 | 2014-08-20 23:53:59 +0000 | [diff] [blame] | 72 | gclient_cmd, 'sync', '--force', '--revision', 'src@'+opts.target_revision |
| 73 | ] |
| 74 | |
kjellander@webrtc.org | 3aa837c | 2014-08-20 14:25:43 +0000 | [diff] [blame] | 75 | if os.environ.get('CHROME_HEADLESS') == '1': |
| 76 | args.append('-vvv') |
| 77 | |
iannucci@chromium.org | 98d92d6 | 2014-08-20 23:53:59 +0000 | [diff] [blame] | 78 | if sys.platform.startswith('win'): |
iannucci@chromium.org | 286210d | 2014-08-21 02:14:11 +0000 | [diff] [blame] | 79 | cache_path = os.path.join(os.path.splitdrive(ROOT_DIR)[0] + os.path.sep, |
iannucci@chromium.org | 98d92d6 | 2014-08-20 23:53:59 +0000 | [diff] [blame] | 80 | 'b', 'git-cache') |
| 81 | else: |
| 82 | cache_path = '/b/git-cache' |
| 83 | |
iannucci@chromium.org | 286210d | 2014-08-21 02:14:11 +0000 | [diff] [blame] | 84 | gclientfile = os.path.join(opts.chromium_dir, '.gclient') |
| 85 | with open(gclientfile, 'rb') as spec: |
iannucci@chromium.org | 98d92d6 | 2014-08-20 23:53:59 +0000 | [diff] [blame] | 86 | spec = spec.read().splitlines() |
| 87 | spec[-1] = 'cache_dir = %r' % (cache_path,) |
iannucci@chromium.org | 286210d | 2014-08-21 02:14:11 +0000 | [diff] [blame] | 88 | with open(gclientfile + '.bot', 'wb') as f: |
| 89 | f.write('\n'.join(spec)) |
| 90 | |
| 91 | args += [ |
| 92 | '--gclientfile', '.gclient.bot', |
| 93 | '--delete_unversioned_trees', '--reset', '--upstream' |
| 94 | ] |
iannucci@chromium.org | 98d92d6 | 2014-08-20 23:53:59 +0000 | [diff] [blame] | 95 | else: |
| 96 | args.append('--no-history') |
| 97 | |
kjellander@webrtc.org | 8925662 | 2014-08-20 12:10:11 +0000 | [diff] [blame] | 98 | if target_os_list: |
| 99 | args += ['--deps=' + target_os_list] |
| 100 | |
| 101 | print 'Running "%s" in %s' % (' '.join(args), opts.chromium_dir) |
| 102 | ret = subprocess.call(args, cwd=opts.chromium_dir, env=env) |
| 103 | if ret == 0: |
| 104 | with open(flag_file, 'wb') as f: |
iannucci@chromium.org | 1613638 | 2014-08-21 15:48:23 +0000 | [diff] [blame] | 105 | f.write(flag_file_content) |
kjellander@webrtc.org | 8925662 | 2014-08-20 12:10:11 +0000 | [diff] [blame] | 106 | |
| 107 | return ret |
| 108 | |
| 109 | |
| 110 | if __name__ == '__main__': |
| 111 | sys.exit(main()) |