Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / tools / cr / cr / commands / sync.py
1 # Copyright 2013 The Chromium 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 """A module for the sync command."""
6
7 import os.path
8
9 import cr
10
11
12 class SyncCommand(cr.Command):
13   """The implementation of the sync command.
14
15   This command is a very thin shim over the gclient sync, and should remain so.
16   The only significant thing it adds is that the environment is set up so that
17   the run-hooks will do their work in the selected output directory.
18   """
19
20   # The configuration loaded to support this command.
21   DEFAULT = cr.Config.From(
22       GCLIENT_BINARY=os.path.join('{DEPOT_TOOLS}', 'gclient'),
23   )
24
25   # A placeholder for the detected gclient environment
26   DETECTED = cr.Config('DETECTED')
27
28   def __init__(self):
29     super(SyncCommand, self).__init__()
30     self.help = 'Sync the source tree'
31     self.description = 'Run gclient sync with the right environment.'
32
33   def AddArguments(self, subparsers):
34     parser = super(SyncCommand, self).AddArguments(subparsers)
35     self.ConsumeArgs(parser, 'gclient')
36     # TODO(iancottrell): clean no-hooks support would be nice.
37     return parser
38
39   def Run(self, context):
40     self.Sync(context, context.remains)
41
42   @staticmethod
43   def Sync(context, args):
44     # TODO(iancottrell): we should probably run the python directly,
45     # rather than the shell wrapper
46     # TODO(iancottrell): try to help out when the local state is not a good
47     # one to do a sync in
48     cr.Host.Execute(context, '{GCLIENT_BINARY}', 'sync', *args)
49
50
51   @classmethod
52   def ClassInit(cls):
53     # Attempt to detect gclient and it's parent repository.
54     gclient_binaries = cr.Host.SearchPath('gclient')
55     if gclient_binaries:
56       cls.DETECTED.Set(GCLIENT_BINARY=gclient_binaries[0])
57       cls.DETECTED.Set(DEPOT_TOOLS=os.path.dirname(gclient_binaries[0]))