| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Writes dependency ordered list of native libraries. | 7 """Writes dependency ordered list of native libraries. |
| 8 | 8 |
| 9 The list excludes any Android system libraries, as those are not bundled with | 9 The list excludes any Android system libraries, as those are not bundled with |
| 10 the APK. | 10 the APK. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 return set(_library_re.findall(elf)) | 58 return set(_library_re.findall(elf)) |
| 59 | 59 |
| 60 | 60 |
| 61 def GetNonSystemDependencies(library_name): | 61 def GetNonSystemDependencies(library_name): |
| 62 all_deps = GetDependencies(FullLibraryPath(library_name)) | 62 all_deps = GetDependencies(FullLibraryPath(library_name)) |
| 63 return set((lib for lib in all_deps if not IsSystemLibrary(lib))) | 63 return set((lib for lib in all_deps if not IsSystemLibrary(lib))) |
| 64 | 64 |
| 65 | 65 |
| 66 def GetSortedTransitiveDependencies(libraries): | 66 def GetSortedTransitiveDependencies(libraries): |
| 67 """Returns all transitive library dependencies in dependency order.""" | 67 """Returns all transitive library dependencies in dependency order.""" |
| 68 def GraphNode(library): | 68 return build_utils.GetSortedTransitiveDependencies( |
| 69 return (library, GetNonSystemDependencies(library)) | 69 libraries, GetNonSystemDependencies) |
| 70 | 70 |
| 71 # First: find all library dependencies. | |
| 72 unchecked_deps = libraries | |
| 73 all_deps = set(libraries) | |
| 74 while unchecked_deps: | |
| 75 lib = unchecked_deps.pop() | |
| 76 new_deps = GetNonSystemDependencies(lib).difference(all_deps) | |
| 77 unchecked_deps.extend(new_deps) | |
| 78 all_deps = all_deps.union(new_deps) | |
| 79 | 71 |
| 80 # Then: simple, slow topological sort. | 72 def GetSortedTransitiveDependenciesForBinaries(binaries): |
| 81 sorted_deps = [] | 73 if binaries[0].endswith('.so'): |
| 82 unsorted_deps = dict(map(GraphNode, all_deps)) | 74 libraries = [os.path.basename(lib) for lib in binaries] |
| 83 while unsorted_deps: | 75 else: |
| 84 for library, dependencies in unsorted_deps.items(): | 76 assert len(binaries) == 1 |
| 85 if not dependencies.intersection(unsorted_deps.keys()): | 77 all_deps = GetDependencies(binaries[0]) |
| 86 sorted_deps.append(library) | 78 libraries = [lib for lib in all_deps if not IsSystemLibrary(lib)] |
| 87 del unsorted_deps[library] | |
| 88 | 79 |
| 89 return sorted_deps | |
| 90 | |
| 91 def GetSortedTransitiveDependenciesForExecutable(executable): | |
| 92 """Returns all transitive library dependencies in dependency order.""" | |
| 93 all_deps = GetDependencies(executable) | |
| 94 libraries = [lib for lib in all_deps if not IsSystemLibrary(lib)] | |
| 95 return GetSortedTransitiveDependencies(libraries) | 80 return GetSortedTransitiveDependencies(libraries) |
| 96 | 81 |
| 97 | 82 |
| 98 def main(): | 83 def main(): |
| 99 parser = optparse.OptionParser() | 84 parser = optparse.OptionParser() |
| 100 | 85 |
| 101 parser.add_option('--input-libraries', | 86 parser.add_option('--input-libraries', |
| 102 help='A list of top-level input libraries.') | 87 help='A list of top-level input libraries.') |
| 103 parser.add_option('--libraries-dir', | 88 parser.add_option('--libraries-dir', |
| 104 help='The directory which contains shared libraries.') | 89 help='The directory which contains shared libraries.') |
| 105 parser.add_option('--readelf', help='Path to the readelf binary.') | 90 parser.add_option('--readelf', help='Path to the readelf binary.') |
| 106 parser.add_option('--output', help='Path to the generated .json file.') | 91 parser.add_option('--output', help='Path to the generated .json file.') |
| 107 parser.add_option('--stamp', help='Path to touch on success.') | 92 parser.add_option('--stamp', help='Path to touch on success.') |
| 108 | 93 |
| 109 global _options | 94 global _options |
| 110 _options, _ = parser.parse_args() | 95 _options, _ = parser.parse_args() |
| 111 | 96 |
| 112 libraries = build_utils.ParseGypList(_options.input_libraries) | 97 libraries = build_utils.ParseGypList(_options.input_libraries) |
| 113 if len(libraries): | 98 if len(libraries): |
| 114 if libraries[0].endswith('.so'): | 99 libraries = GetSortedTransitiveDependenciesForBinaries(libraries) |
| 115 libraries = [os.path.basename(lib) for lib in libraries] | |
| 116 libraries = GetSortedTransitiveDependencies(libraries) | |
| 117 else: | |
| 118 libraries = GetSortedTransitiveDependenciesForExecutable(libraries[0]) | |
| 119 | 100 |
| 120 build_utils.WriteJson(libraries, _options.output, only_if_changed=True) | 101 build_utils.WriteJson(libraries, _options.output, only_if_changed=True) |
| 121 | 102 |
| 122 if _options.stamp: | 103 if _options.stamp: |
| 123 build_utils.Touch(_options.stamp) | 104 build_utils.Touch(_options.stamp) |
| 124 | 105 |
| 125 | 106 |
| 126 if __name__ == '__main__': | 107 if __name__ == '__main__': |
| 127 sys.exit(main()) | 108 sys.exit(main()) |
| 128 | 109 |
| 129 | 110 |
| OLD | NEW |