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.
5 """Harness for defining library dependencies for scons files."""
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': [
21 'desc_cacheability': [
41 'platform_qual_lib': [
79 'testrunner_browser': [
86 'untrusted_crash_dump': [
89 'irt_support_private': [
95 # Untrusted only library dependencies.
96 # Include names here that otherwise clash with trusted names.
97 UNTRUSTED_LIBRARY_DEPENDENCIES = {
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
107 PLATFORM_LIBRARY_DEPENDENCIES = {
109 'nc_decoder_x86_32': [
111 'nc_opcode_modeling_x86_32',
113 'ncdis_util_x86_32': [
114 'ncval_reg_sfi_verbose_x86_32',
115 'ncdis_seg_sfi_verbose_x86_32',
117 'ncdis_seg_sfi_verbose_x86_32': [
118 'ncdis_seg_sfi_x86_32',
119 'ncval_base_verbose_x86_32',
121 'ncvalidate_verbose_x86_32': [
123 'ncdis_seg_sfi_verbose_x86_32',
125 'ncvalidate_x86_32': [
126 'ncval_seg_sfi_x86_32',
129 'ncval_base_verbose_x86_32': [
132 'ncval_base_x86_32': [
137 'nc_opcode_modeling_verbose_x86_32': [
138 'nc_opcode_modeling_x86_32',
139 'ncval_base_verbose_x86_32',
141 'nc_opcode_modeling_x86_32': [
144 'ncval_reg_sfi_verbose_x86_32': [
145 'ncval_reg_sfi_x86_32',
146 'nc_opcode_modeling_verbose_x86_32',
148 'ncval_reg_sfi_x86_32': [
153 'ncval_seg_sfi_x86_32': [
155 'ncdis_seg_sfi_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',
161 'dfa_validate_caller_x86_32': [
168 'nc_decoder_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',
175 'ncdis_util_x86_64': [
176 'ncval_reg_sfi_verbose_x86_64',
177 'ncdis_seg_sfi_verbose_x86_64',
179 'ncdis_seg_sfi_verbose_x86_64': [
180 'ncdis_seg_sfi_x86_64',
181 'ncval_base_verbose_x86_64',
183 'ncvalidate_verbose_x86_64': [
185 'ncval_reg_sfi_verbose_x86_64',
187 'ncvalidate_x86_64': [
188 'ncval_reg_sfi_x86_64',
191 'ncval_base_verbose_x86_64': [
194 'ncval_base_x86_64': [
199 'nc_opcode_modeling_verbose_x86_64': [
200 'nc_opcode_modeling_x86_64',
201 'ncval_base_verbose_x86_64',
203 'nc_opcode_modeling_x86_64': [
206 'ncval_reg_sfi_verbose_x86_64': [
207 'ncval_reg_sfi_x86_64',
208 'nc_opcode_modeling_verbose_x86_64',
210 'ncval_reg_sfi_x86_64': [
216 'ncval_seg_sfi_x86_64': [
218 'ncdis_seg_sfi_x86_64',
221 'dfa_validate_caller_x86_64': [
228 'ncvalidate_arm_v2': [
229 'arm_validator_core',
238 'mips_validator_core',
248 def AddLibDeps(env, platform, libraries):
249 """ Adds dependent libraries to list of libraries.
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.
257 Note: Keeps libraries (in same order) as given
258 in the argument list. This includes duplicates if specified.
260 visited = set() # Nodes already visited
261 closure = [] # Collected closure
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
266 def VisitList(libraries):
267 for library in reversed(libraries):
268 if library not in visited:
269 VisitLibrary(library)
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'))
280 ret.append(env.NaClTargetArchSuffix('ncvalidate'))
283 def VisitLibrary(library):
285 VisitList(GetLibraryDeps(library))
286 closure.append(library)
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)