Upstream version 8.36.161.0
[platform/framework/web/crosswalk.git] / src / xwalk / tools / generate_gclient-xwalk.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 """
8 This script is responsible for generating .gclient-xwalk in the top-level
9 source directory from DEPS.xwalk.
10
11 User-configurable values such as |cache_dir| are fetched from .gclient instead.
12 """
13
14 import logging
15 import optparse
16 import os
17 import pprint
18
19
20 CROSSWALK_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
21 GCLIENT_ROOT = os.path.dirname(os.path.dirname(CROSSWALK_ROOT))
22
23
24 def ParseGClientConfig():
25   """
26   Parses the top-level .gclient file (NOT .gclient-xwalk) and returns the
27   values set there as a dictionary.
28   """
29   with open(os.path.join(GCLIENT_ROOT, '.gclient')) as dot_gclient:
30     config = {}
31     exec(dot_gclient, config)
32   return config
33
34
35 def GenerateGClientXWalk(options):
36   with open(os.path.join(CROSSWALK_ROOT, 'DEPS.xwalk')) as deps_file:
37     deps_contents = deps_file.read()
38
39   if 'XWALK_OS_ANDROID' in os.environ:
40     deps_contents += 'target_os = [\'android\']\n'
41
42   gclient_config = ParseGClientConfig()
43   if options.cache_dir:
44     logging.warning('--cache_dir is deprecated and will be removed in '
45                     'Crosswalk 8. You should set cache_dir in .gclient '
46                     'instead.')
47     cache_dir = options.cache_dir
48   else:
49     cache_dir = gclient_config.get('cache_dir')
50   deps_contents += 'cache_dir = %s\n' % pprint.pformat(cache_dir)
51
52   with open(os.path.join(GCLIENT_ROOT, '.gclient-xwalk'), 'w') as gclient_file:
53     gclient_file.write(deps_contents)
54
55
56 def main():
57   option_parser = optparse.OptionParser()
58   # TODO(rakuco): Remove in Crosswalk 8.
59   option_parser.add_option('--cache-dir',
60                            help='DEPRECATED Set "cache_dir" in .gclient-xwalk '
61                                 'to this directory, so that all git '
62                                 'repositories are cached there.')
63   options, _ = option_parser.parse_args()
64   GenerateGClientXWalk(options)
65
66
67 if __name__ == '__main__':
68   main()