blob: 43ff629983895443707f48210e4583ea13142f0d [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
Ryan Cui21aa0be2013-05-02 10:34:21 -07007import functools
8
David Jamesef74b1c2012-11-12 07:47:47 -08009from chromite.lib import commandline
10from chromite.lib import cros_build_lib
11from chromite.lib import gclient
12from chromite.lib import osutils
13
14
15def 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)
Mike Frysinger04455ee2014-05-20 23:29:15 -040027 # TODO(build): Delete this once all the calls disappear.
David Jamesef74b1c2012-11-12 07:47:47 -080028 parser.add_argument('--pdf', help='Sync PDF source code',
29 action='store_true', default=False)
30 parser.add_argument('--reset', help='Revert local changes',
31 action='store_true', default=False)
32 parser.add_argument('--gclient', help=commandline.argparse.SUPPRESS,
33 default='gclient')
34 parser.add_argument('chrome_root', help='Directory to sync chrome in')
35
36 return parser
37
38
Mike Frysinger9ad5fab2013-05-30 13:37:26 -040039def main(argv):
David Jamesef74b1c2012-11-12 07:47:47 -080040 parser = GetParser()
Mike Frysinger9ad5fab2013-05-30 13:37:26 -040041 options = parser.parse_args(argv)
David Jamesef74b1c2012-11-12 07:47:47 -080042
43 # Revert any lingering local changes.
44 if not osutils.SafeMakedirs(options.chrome_root) and options.reset:
45 try:
46 gclient.Revert(options.gclient, options.chrome_root)
47 except cros_build_lib.RunCommandError:
48 osutils.RmDir(options.chrome_root)
49 osutils.SafeMakedirs(options.chrome_root)
50
51 # Sync new Chrome.
52 gclient.WriteConfigFile(options.gclient, options.chrome_root,
Mike Frysinger04455ee2014-05-20 23:29:15 -040053 options.internal, options.version)
Ryan Cui21aa0be2013-05-02 10:34:21 -070054 sync_fn = functools.partial(
55 gclient.Sync, options.gclient, options.chrome_root, reset=options.reset)
56
57 # Sync twice when run with --reset, which implies 'gclient sync -D'.
58 #
59 # There's a bug with 'gclient sync -D' that gets hit when the location of a
60 # dependency checkout (in the DEPS file) is moved to a path that contains
61 # (in a directory fashion) its old path. E.g., when Blink is moved from
62 # Webkit/Source/ to Webkit/. When this happens, a 'gclient sync -D' will
63 # blow away Webkit/Source/ after the sync, since it is no longer in the
64 # DEPS file, leaving the Blink checkout missing a Source/ subdirectory.
65 #
66 # This bug also gets hit the other way around - E.g., if Blink moves from
67 # Webkit/ to Webkit/Source/.
68 #
69 # To work around this, we sync twice, so that any directories deleted by
70 # the first sync will be restored in the second.
71 #
72 # TODO(rcui): Remove this workaround when the bug is fixed in gclient, or
73 # replace with a more sophisticated solution that syncs twice only when any
74 # paths in the DEPS file cannot be found after initial sync.
75 if options.reset:
76 sync_fn()
77 sync_fn()
David Jamesef74b1c2012-11-12 07:47:47 -080078 return 0