Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / native_client / site_scons / site_tools / library_deps.py
1 # Copyright (c) 2012 The Native Client Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """Harness for defining library dependencies for scons files."""
6
7
8 # The following is a map from a library, to the corresponding
9 # list of dependent libraries that must be included after that library, in
10 # the list of libraries.
11 LIBRARY_DEPENDENCIES_DEFAULT = {
12     'arm_validator_core': [
13         'cpu_features',
14         ],
15     'validation_cache': [
16         'platform',
17         ],
18     'debug_stub': [
19         'sel',
20         ],
21     'desc_cacheability': [
22         'nrd_xfer',
23         ],
24     'imc': [
25         'platform',
26         ],
27     'nonnacl_util': [
28         'serialization',
29         ],
30     'platform': [
31         'gio',
32         ],
33     'nacl_base': [
34         'platform',
35         ],
36     'nrd_xfer': [
37         'nacl_base',
38         'imc',
39         'platform',
40         ],
41     'platform_qual_lib': [
42         'cpu_features',
43         ],
44     'reverse_service': [
45         'validation_cache',
46         ],
47     'sel': [
48         'desc_cacheability',
49         'nacl_error_code',
50         'env_cleanser',
51         'manifest_proxy',
52         'simple_service',
53         'thread_interface',
54         'nonnacl_srpc',
55         'nrd_xfer',
56         'nacl_perf_counter',
57         'nacl_base',
58         'imc',
59         'nacl_fault_inject',
60         'nacl_interval',
61         'platform',
62         'platform_qual_lib',
63         'gio',
64         'validation_cache',
65         'validators',
66         ],
67     'sel_main_chrome': [
68         'sel',
69         'debug_stub',
70         ],
71     'sel_main': [
72         'sel',
73         'debug_stub',
74         ],
75     'serialization': [
76         'platform',
77         ],
78     'testrunner_browser': [
79         'ppapi',
80         ],
81     'validation_cache': [
82         # For CHECK(...)
83         'platform',
84         ],
85     'untrusted_crash_dump': [
86         'nacl_exception',
87         ],
88     'irt_support_private': [
89         'srpc',
90         'platform',
91         ],
92     }
93
94 # Untrusted only library dependencies.
95 # Include names here that otherwise clash with trusted names.
96 UNTRUSTED_LIBRARY_DEPENDENCIES = {
97     'ppapi_cpp': [
98         'ppapi',
99         ],
100     }
101
102 # Platform specific library dependencies. Mapping from a platform,
103 # to a map from a library, to the corresponding list of dependendent
104 # libraries that must be included after that library, in the list
105 # of libraries.
106 PLATFORM_LIBRARY_DEPENDENCIES = {
107     'x86-32': {
108         'dfa_validate_caller_x86_32': [
109             'cpu_features',
110             'validation_cache',
111             'nccopy_x86_32',
112             ],
113         },
114     'x86-64': {
115         'dfa_validate_caller_x86_64': [
116             'cpu_features',
117             'validation_cache',
118             'nccopy_x86_64',
119             ],
120         },
121     'arm': {
122         'ncvalidate_arm_v2': [
123             'arm_validator_core',
124             'validation_cache',
125             ],
126         'validators': [
127             'ncvalidate_arm_v2',
128             ],
129         },
130     'mips32': {
131         'ncvalidate_mips': [
132             'mips_validator_core',
133             'cpu_features',
134             ],
135         'validators': [
136             'ncvalidate_mips',
137             ],
138         },
139     }
140
141
142 def AddLibDeps(env, platform, libraries):
143   """ Adds dependent libraries to list of libraries.
144
145   Computes the transitive closure of library dependencies for each library
146   in the given list. Dependent libraries are added after libraries
147   as defined in LIBRARY_DEPENDENCIES, unless there is a cycle. If
148   a cycle occurs, it is broken and the remaining (acyclic) graph
149   is used. Also removes duplicate library entries.
150
151   Note: Keeps libraries (in same order) as given
152   in the argument list. This includes duplicates if specified.
153   """
154   visited = set()                    # Nodes already visited
155   closure = []                       # Collected closure
156
157   # If library A depends on library B, B must appear in the link line
158   # after A.  This is why we reverse the list and reverse it back
159   # again later.
160   def VisitList(libraries):
161     for library in reversed(libraries):
162       if library not in visited:
163         VisitLibrary(library)
164
165   def GetLibraryDeps(library):
166     ret = (LIBRARY_DEPENDENCIES_DEFAULT.get(library, []) +
167         PLATFORM_LIBRARY_DEPENDENCIES.get(platform, {}).get(library, []))
168     if env['NACL_BUILD_FAMILY'] != 'TRUSTED':
169       ret.extend(UNTRUSTED_LIBRARY_DEPENDENCIES.get(library, []))
170     if library == 'validators' and env.Bit('target_x86'):
171       ret.append(env.NaClTargetArchSuffix('dfa_validate_caller'))
172     return ret
173
174   def VisitLibrary(library):
175     visited.add(library)
176     VisitList(GetLibraryDeps(library))
177     closure.append(library)
178
179   # Ideally we would just do "VisitList(libraries)" here, but some
180   # PPAPI tests (specifically, tests/ppapi_gles_book) list "ppapi_cpp"
181   # twice in the link line, and we need to maintain these duplicates.
182   for library in reversed(libraries):
183     VisitLibrary(library)
184
185   closure.reverse()
186   return closure