3 # Copyright 2015 Samsung Electronics. All rights reserved.
4 # Copyright (c) 2013 Intel Corporation. All rights reserved.
5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file.
8 """This script will do:
9 1. Setup src's git initialization.
10 2. Place .gclient file outside of src.
11 3. Call gclient sync outside of src.
18 def TryAddDepotToolsToPythonPath():
19 depot_tools = FindDepotToolsInPath()
21 sys.path.append(depot_tools)
22 python_path = os.environ.get('PYTHONPATH')
24 os.environ['PYTHONPATH'] = os.path.pathsep.join(
25 python_path.split(os.path.pathsep)+[depot_tools])
27 os.environ['PYTHONPATH'] = depot_tools
29 def FindDepotToolsInPath():
30 paths = os.getenv('PATH').split(os.path.pathsep)
32 if os.path.basename(path) == '':
33 # path is end with os.path.pathsep
34 path = os.path.dirname(path)
35 if os.path.basename(path) == 'depot_tools':
42 TryAddDepotToolsToPythonPath()
48 sys.stderr.write("Can't find gclient_utils, please add your depot_tools "\
49 "to PATH or PYTHONPATH\n")
51 class DepsFetcher(object):
52 def __init__(self, options):
53 self._options = options
54 self._tools_dir = os.path.dirname(os.path.abspath(__file__))
55 self._tizensrc_dir = os.path.dirname(self._tools_dir)
56 # self should be at src/tizen_src/scripts/fetch_deps.py
57 # so src is at self/../../../
58 self._src_dir = os.path.dirname(self._tizensrc_dir)
59 self._root_dir = os.path.dirname(self._src_dir)
60 self._new_gclient_file = os.path.join(self._root_dir,
62 if not os.path.isfile(self._new_gclient_file):
63 raise IOError('%s was not found. Run generate_gclient-efl.py.' %
64 self._new_gclient_file)
66 def DoGclientSyncForChromium(self):
67 gclient_cmd = ['gclient', 'sync', '--verbose', '--reset',
68 '--force', '--with_branch_heads',
69 '--delete_unversioned_trees']
70 gclient_cmd.append('--gclientfile=%s' %
71 os.path.basename(self._new_gclient_file))
72 gclient_utils.CheckCallAndFilterAndHeader(gclient_cmd,
73 always=self._options.verbose, cwd=self._root_dir)
77 option_parser = optparse.OptionParser()
79 option_parser.add_option('-v', '--verbose', action='count', default=0,
80 help='Produces additional output for diagnostics. Can be '
81 'used up to three times for more logging info.')
82 # pylint: disable=W0612
83 options, args = option_parser.parse_args()
85 # Following code copied from gclient_utils.py
87 # Make stdout auto-flush so buildbot doesn't kill us during lengthy
88 # operations. Python as a strong tendency to buffer sys.stdout.
89 sys.stdout = gclient_utils.MakeFileAutoFlush(sys.stdout)
90 # Make stdout annotated with the thread ids.
91 sys.stdout = gclient_utils.MakeFileAnnotated(sys.stdout)
92 except (gclient_utils.Error, subprocess2.CalledProcessError), e:
93 print >> sys.stderr, 'Error: %s' % str(e)
96 deps_fetcher = DepsFetcher(options)
97 deps_fetcher.DoGclientSyncForChromium()
101 if __name__ == '__main__':