3 # Copyright (c) 2013 Intel Corporation. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 """This script will do:
8 1. Setup src's git initialization.
9 2. Place .gclient file outside of src.
10 3. Call gclient sync outside of src.
17 from utils import TryAddDepotToolsToPythonPath
22 TryAddDepotToolsToPythonPath()
28 sys.stderr.write("Can't find gclient_utils, please add your depot_tools "\
29 "to PATH or PYTHONPATH\n")
31 class FetchingError(Exception):
34 class DepsFetcher(object):
35 def __init__(self, options):
36 self._options = options
37 self._xwalk_dir = os.path.dirname(
38 os.path.dirname(os.path.abspath(__file__)))
39 # self should be at src/xwalk/tools/fetch_deps.py
40 # so src is at self/../../../
41 self._src_dir = os.path.dirname(self._xwalk_dir)
42 self._root_dir = os.path.dirname(self._src_dir)
43 self._new_gclient_file = os.path.join(self._root_dir,
45 if not os.path.isfile(self._new_gclient_file):
46 raise IOError('%s was not found. Run generate_gclient-xwalk.py.' %
47 self._new_gclient_file)
50 # pylint: disable=R0201
51 def requirements(self):
52 # No requirements at all
55 def DoGclientSyncForChromium(self):
56 gclient_cmd = ['gclient', 'sync', '--verbose', '--reset',
57 '--force', '--with_branch_heads',
58 '--delete_unversioned_trees']
59 gclient_cmd.append('--gclientfile=%s' %
60 os.path.basename(self._new_gclient_file))
61 gclient_utils.CheckCallAndFilterAndHeader(gclient_cmd,
62 always=self._options.verbose, cwd=self._root_dir)
63 # CheckCallAndFilterAndHeader will raise exception if return
64 # value is not 0. So we can easily return 0 here.
68 option_parser = optparse.OptionParser()
70 option_parser.add_option('-v', '--verbose', action='count', default=0,
71 help='Produces additional output for diagnostics. Can be '
72 'used up to three times for more logging info.')
73 # pylint: disable=W0612
74 options, args = option_parser.parse_args()
76 # Following code copied from gclient_utils.py
78 # Make stdout auto-flush so buildbot doesn't kill us during lengthy
79 # operations. Python as a strong tendency to buffer sys.stdout.
80 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout)
81 # Make stdout annotated with the thread ids.
82 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout)
83 except (gclient_utils.Error, subprocess2.CalledProcessError), e:
84 print >> sys.stderr, 'Error: %s' % str(e)
87 deps_fetcher = DepsFetcher(options)
88 sys.exit(deps_fetcher.DoGclientSyncForChromium())
90 if __name__ == '__main__':