Introduce 'chromium-efl-libs.spec'.
[platform/framework/web/chromium-efl.git] / tizen_src / packaging / print-chromium-deps.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2014 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 Parses a gyp JSON dependency dict generated by gyp's dump_dependency_json
9 generator and prints the Chromium targets (ie. the ones not in gyp files in
10 src/xwalk) required for building the ones passed on the command-line.
11
12 The output can then be passed, for example, to ninja.
13 """
14
15 import copy
16 import json
17 import os
18 import sys
19
20
21 def ParseDependency(dep):
22   """
23   Given a dependency like '/path/to/foo.gyp:somedep#target', returns a tuple
24   ('/path/to/foo.gyp', 'somedep').
25   """
26   path = dep[:dep.find(':')]
27   name = dep[dep.find(':')+1:dep.find('#')]
28   return (path, name)
29
30
31 def GetDependencies(deps_dict, root):
32   targets = set()
33   dependencies = copy.deepcopy(deps_dict[root])
34   while dependencies:
35     dep = dependencies.pop()
36     target_path, target_name = ParseDependency(dep)
37     if target_name in targets:
38       continue
39     if ("xwalk/" not in target_path) and ("tizen_src/ewk/" not in target_path):
40       targets.add(target_name)
41     dependencies += deps_dict[dep]
42   return targets
43
44
45 def main():
46   if len(sys.argv) < 3:
47     print('Usage: %s <deps.json> <target 1> [... <target N>]' % sys.argv[0])
48     print('<deps.json> points to deps.json generated by gyp with '
49           'GYP_GENERATORS=dump_dependency_json.')
50     print('Each target is a target name whose dependencies will be '
51           'printed.')
52     return 1
53
54   dump_json_path = sys.argv[1]
55   if not os.path.isfile(dump_json_path):
56     print('"%s" not found.' % dump_json_path)
57     print('Run gyp with GYP_GENERATORS=dump_dependency_json first.')
58     return 1
59
60   deps_dict = json.load(open(dump_json_path))
61   targets = sys.argv[2:]
62   roots = []
63
64   for target in targets:
65     valid_target = False
66     for dep in deps_dict:
67       if dep.endswith(':%s#target' % target):
68         valid_target = True
69         roots.append(dep)
70         break
71     if not valid_target:
72       print('Error: "%s" is not a valid target.' % target)
73       return 1
74
75   target_deps = set()
76   for dependency in roots:
77     target_deps |= GetDependencies(deps_dict, dependency)
78
79   print ' '.join(list(target_deps))
80   return 0
81
82
83 if __name__ == '__main__':
84   sys.exit(main())