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 | |
Ryan Cui | 21aa0be | 2013-05-02 10:34:21 -0700 | [diff] [blame] | 7 | import functools |
| 8 | |
David James | ef74b1c | 2012-11-12 07:47:47 -0800 | [diff] [blame] | 9 | from chromite.lib import commandline |
| 10 | from chromite.lib import cros_build_lib |
| 11 | from chromite.lib import gclient |
| 12 | from chromite.lib import osutils |
| 13 | |
| 14 | |
| 15 | def GetParser(): |
| 16 | """Creates the argparse parser.""" |
| 17 | parser = commandline.ArgumentParser(description=__doc__) |
| 18 | |
| 19 | version = parser.add_mutually_exclusive_group() |
| 20 | version.add_argument('--tag', help='Sync to specified Chrome release', |
| 21 | dest='version') |
| 22 | version.add_argument('--revision', help='Sync to specified SVN revision', |
| 23 | type=int, dest='version') |
| 24 | |
| 25 | parser.add_argument('--internal', help='Sync internal version of Chrome', |
| 26 | action='store_true', default=False) |
| 27 | parser.add_argument('--pdf', help='Sync PDF source code', |
| 28 | action='store_true', default=False) |
| 29 | parser.add_argument('--reset', help='Revert local changes', |
| 30 | action='store_true', default=False) |
| 31 | parser.add_argument('--gclient', help=commandline.argparse.SUPPRESS, |
| 32 | default='gclient') |
| 33 | parser.add_argument('chrome_root', help='Directory to sync chrome in') |
| 34 | |
| 35 | return parser |
| 36 | |
| 37 | |
Mike Frysinger | 9ad5fab | 2013-05-30 13:37:26 -0400 | [diff] [blame] | 38 | def main(argv): |
David James | ef74b1c | 2012-11-12 07:47:47 -0800 | [diff] [blame] | 39 | parser = GetParser() |
Mike Frysinger | 9ad5fab | 2013-05-30 13:37:26 -0400 | [diff] [blame] | 40 | options = parser.parse_args(argv) |
David James | ef74b1c | 2012-11-12 07:47:47 -0800 | [diff] [blame] | 41 | |
| 42 | # Revert any lingering local changes. |
| 43 | if not osutils.SafeMakedirs(options.chrome_root) and options.reset: |
| 44 | try: |
| 45 | gclient.Revert(options.gclient, options.chrome_root) |
| 46 | except cros_build_lib.RunCommandError: |
| 47 | osutils.RmDir(options.chrome_root) |
| 48 | osutils.SafeMakedirs(options.chrome_root) |
| 49 | |
| 50 | # Sync new Chrome. |
| 51 | gclient.WriteConfigFile(options.gclient, options.chrome_root, |
| 52 | options.internal, options.pdf, options.version) |
Ryan Cui | 21aa0be | 2013-05-02 10:34:21 -0700 | [diff] [blame] | 53 | sync_fn = functools.partial( |
| 54 | gclient.Sync, options.gclient, options.chrome_root, reset=options.reset) |
| 55 | |
| 56 | # Sync twice when run with --reset, which implies 'gclient sync -D'. |
| 57 | # |
| 58 | # There's a bug with 'gclient sync -D' that gets hit when the location of a |
| 59 | # dependency checkout (in the DEPS file) is moved to a path that contains |
| 60 | # (in a directory fashion) its old path. E.g., when Blink is moved from |
| 61 | # Webkit/Source/ to Webkit/. When this happens, a 'gclient sync -D' will |
| 62 | # blow away Webkit/Source/ after the sync, since it is no longer in the |
| 63 | # DEPS file, leaving the Blink checkout missing a Source/ subdirectory. |
| 64 | # |
| 65 | # This bug also gets hit the other way around - E.g., if Blink moves from |
| 66 | # Webkit/ to Webkit/Source/. |
| 67 | # |
| 68 | # To work around this, we sync twice, so that any directories deleted by |
| 69 | # the first sync will be restored in the second. |
| 70 | # |
| 71 | # TODO(rcui): Remove this workaround when the bug is fixed in gclient, or |
| 72 | # replace with a more sophisticated solution that syncs twice only when any |
| 73 | # paths in the DEPS file cannot be found after initial sync. |
| 74 | if options.reset: |
| 75 | sync_fn() |
| 76 | sync_fn() |
David James | ef74b1c | 2012-11-12 07:47:47 -0800 | [diff] [blame] | 77 | return 0 |