Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: build/android/gyp/write_ordered_libraries.py

Issue 361633002: [Android][gn] Add android resources templates (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gn-java
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 return set(_library_re.findall(elf)) 54 return set(_library_re.findall(elf))
55 55
56 56
57 def GetNonSystemDependencies(library_name): 57 def GetNonSystemDependencies(library_name):
58 all_deps = GetDependencies(FullLibraryPath(library_name)) 58 all_deps = GetDependencies(FullLibraryPath(library_name))
59 return set((lib for lib in all_deps if not IsSystemLibrary(lib))) 59 return set((lib for lib in all_deps if not IsSystemLibrary(lib)))
60 60
61 61
62 def GetSortedTransitiveDependencies(libraries): 62 def GetSortedTransitiveDependencies(libraries):
63 """Returns all transitive library dependencies in dependency order.""" 63 """Returns all transitive library dependencies in dependency order."""
64 def GraphNode(library): 64 return build_utils.GetSortedTransitiveDependencies(
65 return (library, GetNonSystemDependencies(library)) 65 libraries, GetNonSystemDependencies)
66 66
67 # First: find all library dependencies.
68 unchecked_deps = libraries
69 all_deps = set(libraries)
70 while unchecked_deps:
71 lib = unchecked_deps.pop()
72 new_deps = GetNonSystemDependencies(lib).difference(all_deps)
73 unchecked_deps.extend(new_deps)
74 all_deps = all_deps.union(new_deps)
75 67
76 # Then: simple, slow topological sort. 68 def GetSortedTransitiveDependenciesForBinaries(binaries):
77 sorted_deps = [] 69 if binaries[0].endswith('.so'):
78 unsorted_deps = dict(map(GraphNode, all_deps)) 70 libraries = [os.path.basename(lib) for lib in binaries]
79 while unsorted_deps: 71 else:
80 for library, dependencies in unsorted_deps.items(): 72 assert len(binaries) == 1
81 if not dependencies.intersection(unsorted_deps.keys()): 73 all_deps = GetDependencies(binaries[0])
82 sorted_deps.append(library) 74 libraries = [lib for lib in all_deps if not IsSystemLibrary(lib)]
83 del unsorted_deps[library]
84 75
85 return sorted_deps
86
87 def GetSortedTransitiveDependenciesForExecutable(executable):
88 """Returns all transitive library dependencies in dependency order."""
89 all_deps = GetDependencies(executable)
90 libraries = [lib for lib in all_deps if not IsSystemLibrary(lib)]
91 return GetSortedTransitiveDependencies(libraries) 76 return GetSortedTransitiveDependencies(libraries)
92 77
93 78
94 def main(): 79 def main():
95 parser = optparse.OptionParser() 80 parser = optparse.OptionParser()
96 81
97 parser.add_option('--input-libraries', 82 parser.add_option('--input-libraries',
98 help='A list of top-level input libraries.') 83 help='A list of top-level input libraries.')
99 parser.add_option('--libraries-dir', 84 parser.add_option('--libraries-dir',
100 help='The directory which contains shared libraries.') 85 help='The directory which contains shared libraries.')
101 parser.add_option('--readelf', help='Path to the readelf binary.') 86 parser.add_option('--readelf', help='Path to the readelf binary.')
102 parser.add_option('--output', help='Path to the generated .json file.') 87 parser.add_option('--output', help='Path to the generated .json file.')
103 parser.add_option('--stamp', help='Path to touch on success.') 88 parser.add_option('--stamp', help='Path to touch on success.')
104 89
105 global _options 90 global _options
106 _options, _ = parser.parse_args() 91 _options, _ = parser.parse_args()
107 92
108 libraries = build_utils.ParseGypList(_options.input_libraries) 93 libraries = GetSortedTransitiveDependenciesForBinaries(
109 if libraries[0].endswith('.so'): 94 build_utils.ParseGypList(_options.input_libraries))
110 libraries = [os.path.basename(lib) for lib in libraries]
111 libraries = GetSortedTransitiveDependencies(libraries)
112 else:
113 libraries = GetSortedTransitiveDependenciesForExecutable(libraries[0])
114 95
115 build_utils.WriteJson(libraries, _options.output, only_if_changed=True) 96 build_utils.WriteJson(libraries, _options.output, only_if_changed=True)
116 97
117 if _options.stamp: 98 if _options.stamp:
118 build_utils.Touch(_options.stamp) 99 build_utils.Touch(_options.stamp)
119 100
120 101
121 if __name__ == '__main__': 102 if __name__ == '__main__':
122 sys.exit(main()) 103 sys.exit(main())
123 104
124 105
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698