David James | ef74b1c | 2012-11-12 07:47:47 -0800 | [diff] [blame] | 1 | # 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 | |
| 7 | from chromite.lib import commandline |
| 8 | from chromite.lib import cros_build_lib |
| 9 | from chromite.lib import gclient |
| 10 | from chromite.lib import osutils |
| 11 | |
| 12 | |
| 13 | def GetParser(): |
| 14 | """Creates the argparse parser.""" |
| 15 | parser = commandline.ArgumentParser(description=__doc__) |
| 16 | |
| 17 | version = parser.add_mutually_exclusive_group() |
| 18 | version.add_argument('--tag', help='Sync to specified Chrome release', |
| 19 | dest='version') |
| 20 | version.add_argument('--revision', help='Sync to specified SVN revision', |
| 21 | type=int, dest='version') |
| 22 | |
| 23 | parser.add_argument('--internal', help='Sync internal version of Chrome', |
| 24 | action='store_true', default=False) |
| 25 | parser.add_argument('--pdf', help='Sync PDF source code', |
| 26 | action='store_true', default=False) |
| 27 | parser.add_argument('--reset', help='Revert local changes', |
| 28 | action='store_true', default=False) |
| 29 | parser.add_argument('--gclient', help=commandline.argparse.SUPPRESS, |
| 30 | default='gclient') |
| 31 | parser.add_argument('chrome_root', help='Directory to sync chrome in') |
| 32 | |
| 33 | return parser |
| 34 | |
| 35 | |
| 36 | def main(args): |
| 37 | parser = GetParser() |
| 38 | options = parser.parse_args(args) |
| 39 | |
| 40 | # Revert any lingering local changes. |
| 41 | if not osutils.SafeMakedirs(options.chrome_root) and options.reset: |
| 42 | try: |
| 43 | gclient.Revert(options.gclient, options.chrome_root) |
| 44 | except cros_build_lib.RunCommandError: |
| 45 | osutils.RmDir(options.chrome_root) |
| 46 | osutils.SafeMakedirs(options.chrome_root) |
| 47 | |
| 48 | # Sync new Chrome. |
| 49 | gclient.WriteConfigFile(options.gclient, options.chrome_root, |
| 50 | options.internal, options.pdf, options.version) |
| 51 | gclient.Sync(options.gclient, options.chrome_root, options.reset) |
| 52 | return 0 |