Upstream version 5.34.97.0
[platform/framework/web/crosswalk.git] / src / xwalk / tools / fetch_deps.py
1 #!/usr/bin/env python
2
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.
6
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.
11 """
12
13 import optparse
14 import os
15 import sys
16
17 from utils import TryAddDepotToolsToPythonPath
18
19 try:
20   import gclient_utils
21 except ImportError:
22   TryAddDepotToolsToPythonPath()
23
24 try:
25   import gclient_utils
26   import subprocess2
27 except ImportError:
28   sys.stderr.write("Can't find gclient_utils, please add your depot_tools "\
29                    "to PATH or PYTHONPATH\n")
30
31 class FetchingError(Exception):
32   pass
33
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,
44                                           '.gclient-xwalk')
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)
48
49   @property
50   # pylint: disable=R0201
51   def requirements(self):
52     # No requirements at all
53     return set()
54
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.
65     return 0
66
67 def main():
68   option_parser = optparse.OptionParser()
69
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()
75
76   # Following code copied from gclient_utils.py
77   try:
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)
85     return 1
86
87   deps_fetcher = DepsFetcher(options)
88   sys.exit(deps_fetcher.DoGclientSyncForChromium())
89
90 if __name__ == '__main__':
91   main()