Upstream version 5.34.104.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         'gio_wrapped_desc',
55         'nonnacl_srpc',
56         'nrd_xfer',
57         'nacl_perf_counter',
58         'nacl_base',
59         'imc',
60         'nacl_fault_inject',
61         'nacl_interval',
62         'platform',
63         'platform_qual_lib',
64         'gio',
65         'validation_cache',
66         'validators',
67         ],
68     'sel_main_chrome': [
69         'sel',
70         'debug_stub',
71         ],
72     'sel_main': [
73         'sel',
74         'debug_stub',
75         ],
76     'serialization': [
77         'platform',
78         ],
79     'testrunner_browser': [
80         'ppapi',
81         ],
82     'validation_cache': [
83         # For CHECK(...)
84         'platform',
85         ],
86     'untrusted_crash_dump': [
87         'nacl_exception',
88         ],
89     'irt_support_private': [
90         'srpc',
91         'platform',
92         ],
93     }
94
95 # Untrusted only library dependencies.
96 # Include names here that otherwise clash with trusted names.
97 UNTRUSTED_LIBRARY_DEPENDENCIES = {
98     'ppapi_cpp': [
99         'ppapi',
100         ],
101     }
102
103 # Platform specific library dependencies. Mapping from a platform,
104 # to a map from a library, to the corresponding list of dependendent
105 # libraries that must be included after that library, in the list
106 # of libraries.
107 PLATFORM_LIBRARY_DEPENDENCIES = {
108     'x86-32': {
109         'nc_decoder_x86_32': [
110             'ncval_base_x86_32',
111             'nc_opcode_modeling_x86_32',
112             ],
113         'ncdis_util_x86_32': [
114             'ncval_reg_sfi_verbose_x86_32',
115             'ncdis_seg_sfi_verbose_x86_32',
116             ],
117         'ncdis_seg_sfi_verbose_x86_32': [
118             'ncdis_seg_sfi_x86_32',
119             'ncval_base_verbose_x86_32',
120             ],
121         'ncvalidate_verbose_x86_32': [
122             'ncvalidate_x86_32',
123             'ncdis_seg_sfi_verbose_x86_32',
124             ],
125         'ncvalidate_x86_32': [
126             'ncval_seg_sfi_x86_32',
127             'cpu_features',
128             ],
129         'ncval_base_verbose_x86_32': [
130             'ncval_base_x86_32',
131             ],
132         'ncval_base_x86_32': [
133             'platform',
134             'cpu_features',
135             'validation_cache',
136             ],
137         'nc_opcode_modeling_verbose_x86_32': [
138             'nc_opcode_modeling_x86_32',
139             'ncval_base_verbose_x86_32',
140             ],
141         'nc_opcode_modeling_x86_32': [
142             'ncval_base_x86_32',
143             ],
144         'ncval_reg_sfi_verbose_x86_32': [
145             'ncval_reg_sfi_x86_32',
146             'nc_opcode_modeling_verbose_x86_32',
147             ],
148         'ncval_reg_sfi_x86_32': [
149             'nccopy_x86_32',
150             'ncval_base_x86_32',
151             'nc_decoder_x86_32',
152             ],
153         'ncval_seg_sfi_x86_32': [
154             'nccopy_x86_32',
155             'ncdis_seg_sfi_x86_32',
156             'ncval_base_x86_32',
157             # When turning on the DEBUGGING flag in the x86-32 validator
158             # or decoder, add the following:
159             #'nc_opcode_modeling_verbose_x86_32',
160             ],
161         'dfa_validate_caller_x86_32': [
162             'cpu_features',
163             'validation_cache',
164             'nccopy_x86_32',
165             ],
166         },
167     'x86-64': {
168         'nc_decoder_x86_64': [
169             'ncval_base_x86_64',
170             'nc_opcode_modeling_x86_64',
171             # When turning on the DEBUGGING flag in the x86-64 validator
172             # or decoder, add the following:
173             #'nc_opcode_modeling_verbose_x86_64',
174             ],
175         'ncdis_util_x86_64': [
176             'ncval_reg_sfi_verbose_x86_64',
177             'ncdis_seg_sfi_verbose_x86_64',
178             ],
179         'ncdis_seg_sfi_verbose_x86_64': [
180             'ncdis_seg_sfi_x86_64',
181             'ncval_base_verbose_x86_64',
182             ],
183         'ncvalidate_verbose_x86_64': [
184             'ncvalidate_x86_64',
185             'ncval_reg_sfi_verbose_x86_64',
186             ],
187         'ncvalidate_x86_64': [
188             'ncval_reg_sfi_x86_64',
189             'cpu_features',
190             ],
191         'ncval_base_verbose_x86_64': [
192             'ncval_base_x86_64',
193             ],
194         'ncval_base_x86_64': [
195             'platform',
196             'cpu_features',
197             'validation_cache',
198             ],
199         'nc_opcode_modeling_verbose_x86_64': [
200             'nc_opcode_modeling_x86_64',
201             'ncval_base_verbose_x86_64',
202             ],
203         'nc_opcode_modeling_x86_64': [
204             'ncval_base_x86_64',
205             ],
206         'ncval_reg_sfi_verbose_x86_64': [
207             'ncval_reg_sfi_x86_64',
208             'nc_opcode_modeling_verbose_x86_64',
209             ],
210         'ncval_reg_sfi_x86_64': [
211             'nccopy_x86_64',
212             'ncval_base_x86_64',
213             'nc_decoder_x86_64',
214             'cpu_features',
215             ],
216         'ncval_seg_sfi_x86_64': [
217             'nccopy_x86_64',
218             'ncdis_seg_sfi_x86_64',
219             'ncval_base_x86_64',
220             ],
221         'dfa_validate_caller_x86_64': [
222             'cpu_features',
223             'validation_cache',
224             'nccopy_x86_64',
225             ],
226         },
227     'arm': {
228         'ncvalidate_arm_v2': [
229             'arm_validator_core',
230             'validation_cache',
231             ],
232         'validators': [
233             'ncvalidate_arm_v2',
234             ],
235         },
236     'mips32': {
237         'ncvalidate_mips': [
238             'mips_validator_core',
239             'cpu_features',
240             ],
241         'validators': [
242             'ncvalidate_mips',
243             ],
244         },
245     }
246
247
248 def AddLibDeps(env, platform, libraries):
249   """ Adds dependent libraries to list of libraries.
250
251   Computes the transitive closure of library dependencies for each library
252   in the given list. Dependent libraries are added after libraries
253   as defined in LIBRARY_DEPENDENCIES, unless there is a cycle. If
254   a cycle occurs, it is broken and the remaining (acyclic) graph
255   is used. Also removes duplicate library entries.
256
257   Note: Keeps libraries (in same order) as given
258   in the argument list. This includes duplicates if specified.
259   """
260   visited = set()                    # Nodes already visited
261   closure = []                       # Collected closure
262
263   # If library A depends on library B, B must appear in the link line
264   # after A.  This is why we reverse the list and reverse it back
265   # again later.
266   def VisitList(libraries):
267     for library in reversed(libraries):
268       if library not in visited:
269         VisitLibrary(library)
270
271   def GetLibraryDeps(library):
272     ret = (LIBRARY_DEPENDENCIES_DEFAULT.get(library, []) +
273         PLATFORM_LIBRARY_DEPENDENCIES.get(platform, {}).get(library, []))
274     if env['NACL_BUILD_FAMILY'] != 'TRUSTED':
275       ret.extend(UNTRUSTED_LIBRARY_DEPENDENCIES.get(library, []))
276     if library == 'validators' and env.Bit('target_x86'):
277       if env.Bit('validator_ragel'):
278         ret.append(env.NaClTargetArchSuffix('dfa_validate_caller'))
279       else:
280         ret.append(env.NaClTargetArchSuffix('ncvalidate'))
281     return ret
282
283   def VisitLibrary(library):
284     visited.add(library)
285     VisitList(GetLibraryDeps(library))
286     closure.append(library)
287
288   # Ideally we would just do "VisitList(libraries)" here, but some
289   # PPAPI tests (specifically, tests/ppapi_gles_book) list "ppapi_cpp"
290   # twice in the link line, and we need to maintain these duplicates.
291   for library in reversed(libraries):
292     VisitLibrary(library)
293
294   closure.reverse()
295   return closure