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.
5 """A module for the sync command."""
12 class SyncCommand(cr.Command):
13 """The implementation of the sync command.
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.
20 # The configuration loaded to support this command.
21 DEFAULT = cr.Config.From(
22 GCLIENT_BINARY=os.path.join('{DEPOT_TOOLS}', 'gclient'),
25 # A placeholder for the detected gclient environment
26 DETECTED = cr.Config('DETECTED')
29 super(SyncCommand, self).__init__()
30 self.help = 'Sync the source tree'
31 self.description = 'Run gclient sync with the right environment.'
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.
39 def Run(self, context):
40 self.Sync(context, context.remains)
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
48 cr.Host.Execute(context, '{GCLIENT_BINARY}', 'sync', *args)
53 # Attempt to detect gclient and it's parent repository.
54 gclient_binaries = cr.Host.SearchPath('gclient')
56 cls.DETECTED.Set(GCLIENT_BINARY=gclient_binaries[0])
57 cls.DETECTED.Set(DEPOT_TOOLS=os.path.dirname(gclient_binaries[0]))