Use third party libxml
[platform/framework/web/chromium-efl.git] / tizen_src / scripts / fetch_deps.py
1 #!/usr/bin/env python
2
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.
7
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.
12 """
13
14 import optparse
15 import os
16 import sys
17
18 def TryAddDepotToolsToPythonPath():
19   depot_tools = FindDepotToolsInPath()
20   if depot_tools:
21     sys.path.append(depot_tools)
22     python_path = os.environ.get('PYTHONPATH')
23     if python_path:
24       os.environ['PYTHONPATH'] = os.path.pathsep.join(
25           python_path.split(os.path.pathsep)+[depot_tools])
26     else:
27       os.environ['PYTHONPATH'] = depot_tools
28
29 def FindDepotToolsInPath():
30   paths = os.getenv('PATH').split(os.path.pathsep)
31   for path in paths:
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':
36       return path
37   return None
38
39 try:
40   import gclient_utils
41 except ImportError:
42   TryAddDepotToolsToPythonPath()
43
44 try:
45   import gclient_utils
46   import subprocess2
47 except ImportError:
48   sys.stderr.write("Can't find gclient_utils, please add your depot_tools "\
49                    "to PATH or PYTHONPATH\n")
50
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,
61                                           '.gclient-efl')
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)
65
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)
74
75
76 def main():
77   option_parser = optparse.OptionParser()
78
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()
84
85   # Following code copied from gclient_utils.py
86   try:
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)
94     return 1
95
96   deps_fetcher = DepsFetcher(options)
97   deps_fetcher.DoGclientSyncForChromium()
98
99   return 0
100
101 if __name__ == '__main__':
102   sys.exit(main())