blob: d01da267a8bb2c90d69121478e0b94589dc7446f [file] [log] [blame]
David Jamesef74b1c2012-11-12 07:47:47 -08001# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Sync the Chrome source code used by Chrome OS to the specified directory."""
6
Mike Frysinger383367e2014-09-16 15:06:17 -04007from __future__ import print_function
8
Simran Basi7d7dbd82015-01-14 14:01:55 -08009import os
Ryan Cui21aa0be2013-05-02 10:34:21 -070010
Simran Basi7d7dbd82015-01-14 14:01:55 -080011from chromite.cbuildbot import constants
David Jamesef74b1c2012-11-12 07:47:47 -080012from chromite.lib import commandline
13from chromite.lib import cros_build_lib
14from chromite.lib import gclient
15from chromite.lib import osutils
16
17
18def GetParser():
19 """Creates the argparse parser."""
20 parser = commandline.ArgumentParser(description=__doc__)
21
22 version = parser.add_mutually_exclusive_group()
23 version.add_argument('--tag', help='Sync to specified Chrome release',
24 dest='version')
Stefan Zagerd49d9ff2014-08-15 21:33:37 -070025 version.add_argument('--revision', help='Sync to specified git revision',
26 dest='version')
David Jamesef74b1c2012-11-12 07:47:47 -080027
28 parser.add_argument('--internal', help='Sync internal version of Chrome',
29 action='store_true', default=False)
David Jamesef74b1c2012-11-12 07:47:47 -080030 parser.add_argument('--reset', help='Revert local changes',
31 action='store_true', default=False)
32 parser.add_argument('--gclient', help=commandline.argparse.SUPPRESS,
Simran Basi7d7dbd82015-01-14 14:01:55 -080033 default=None)
Ben Chan2e19e4e2015-01-06 20:17:15 -080034 parser.add_argument('--gclient_template', help='Template gclient input file')
Ben Chan11aad4d2015-02-20 12:47:23 -080035 parser.add_argument('--skip_cache', help='Skip using git cache',
36 dest='use_cache', action='store_false')
David Jamesef74b1c2012-11-12 07:47:47 -080037 parser.add_argument('chrome_root', help='Directory to sync chrome in')
38
39 return parser
40
41
Mike Frysinger9ad5fab2013-05-30 13:37:26 -040042def main(argv):
David Jamesef74b1c2012-11-12 07:47:47 -080043 parser = GetParser()
Mike Frysinger9ad5fab2013-05-30 13:37:26 -040044 options = parser.parse_args(argv)
David Jamesef74b1c2012-11-12 07:47:47 -080045
Simran Basi7d7dbd82015-01-14 14:01:55 -080046 if options.gclient is '':
47 parser.error('--gclient can not be an empty string!')
48 gclient_path = options.gclient or osutils.Which('gclient')
49 if not gclient_path:
50 gclient_path = os.path.join(constants.DEPOT_TOOLS_DIR, 'gclient')
51
David Jamesef74b1c2012-11-12 07:47:47 -080052 # Revert any lingering local changes.
53 if not osutils.SafeMakedirs(options.chrome_root) and options.reset:
54 try:
Simran Basi7d7dbd82015-01-14 14:01:55 -080055 gclient.Revert(gclient_path, options.chrome_root)
David Jamesef74b1c2012-11-12 07:47:47 -080056 except cros_build_lib.RunCommandError:
57 osutils.RmDir(options.chrome_root)
58 osutils.SafeMakedirs(options.chrome_root)
59
60 # Sync new Chrome.
Simran Basi7d7dbd82015-01-14 14:01:55 -080061 gclient.WriteConfigFile(gclient_path, options.chrome_root,
Ben Chan2e19e4e2015-01-06 20:17:15 -080062 options.internal, options.version,
Ben Chan11aad4d2015-02-20 12:47:23 -080063 options.gclient_template, options.use_cache)
David James2d47afa2015-03-26 11:23:56 -070064 gclient.Sync(gclient_path, options.chrome_root, reset=options.reset)
Ryan Cui21aa0be2013-05-02 10:34:21 -070065
David Jamesef74b1c2012-11-12 07:47:47 -080066 return 0