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': [
78 'testrunner_browser': [
85 'untrusted_crash_dump': [
88 'irt_support_private': [
94 # Untrusted only library dependencies.
95 # Include names here that otherwise clash with trusted names.
96 UNTRUSTED_LIBRARY_DEPENDENCIES = {
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
106 PLATFORM_LIBRARY_DEPENDENCIES = {
108 'dfa_validate_caller_x86_32': [
115 'dfa_validate_caller_x86_64': [
122 'ncvalidate_arm_v2': [
123 'arm_validator_core',
132 'mips_validator_core',
142 def AddLibDeps(env, platform, libraries):
143 """ Adds dependent libraries to list of libraries.
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.
151 Note: Keeps libraries (in same order) as given
152 in the argument list. This includes duplicates if specified.
154 visited = set() # Nodes already visited
155 closure = [] # Collected closure
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
160 def VisitList(libraries):
161 for library in reversed(libraries):
162 if library not in visited:
163 VisitLibrary(library)
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'))
174 def VisitLibrary(library):
176 VisitList(GetLibraryDeps(library))
177 closure.append(library)
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)