| 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. |
| 11 | 11 |
| 12 This list of libraries is used for several steps of building an APK. | 12 This list of libraries is used for several steps of building an APK. |
| 13 In the component build, the --input-libraries only needs to be the top-level | 13 In the component build, the --input-libraries only needs to be the top-level |
| 14 library (i.e. libcontent_shell_content_view). This will then use readelf to | 14 library (i.e. libcontent_shell_content_view). This will then use readelf to |
| 15 inspect the shared libraries and determine the full list of (non-system) | 15 inspect the shared libraries and determine the full list of (non-system) |
| 16 libraries that should be included in the APK. | 16 libraries that should be included in the APK. |
| 17 """ | 17 """ |
| 18 | 18 |
| 19 # TODO(cjhopman): See if we can expose the list of library dependencies from | 19 # TODO(cjhopman): See if we can expose the list of library dependencies from |
| 20 # gyp, rather than calculating it ourselves. | 20 # gyp, rather than calculating it ourselves. |
| 21 # http://crbug.com/225558 | 21 # http://crbug.com/225558 |
| 22 | 22 |
| 23 import optparse | 23 import optparse |
| 24 import os | 24 import os |
| 25 import re | 25 import re |
| 26 import sys | 26 import sys |
| 27 | 27 |
| 28 from util import build_utils | 28 from util import build_utils |
| 29 | 29 |
| 30 _options = None | 30 _readelf = None |
| 31 _library_dirs = None |
| 32 |
| 31 _library_re = re.compile( | 33 _library_re = re.compile( |
| 32 '.*NEEDED.*Shared library: \[(?P<library_name>[\w/.]+)\]') | 34 '.*NEEDED.*Shared library: \[(?P<library_name>[\w/.]+)\]') |
| 33 | 35 |
| 34 | 36 |
| 37 def SetReadelfPath(path): |
| 38 global _readelf |
| 39 _readelf = path |
| 40 |
| 41 |
| 42 def SetLibraryDirs(dirs): |
| 43 global _library_dirs |
| 44 _library_dirs = dirs |
| 45 |
| 46 |
| 35 def FullLibraryPath(library_name): | 47 def FullLibraryPath(library_name): |
| 36 for directory in _options.libraries_dir.split(','): | 48 assert _library_dirs is not None |
| 49 for directory in _library_dirs: |
| 37 path = '%s/%s' % (directory, library_name) | 50 path = '%s/%s' % (directory, library_name) |
| 38 if os.path.exists(path): | 51 if os.path.exists(path): |
| 39 return path | 52 return path |
| 40 return library_name | 53 return library_name |
| 41 | 54 |
| 42 | 55 |
| 43 def IsSystemLibrary(library_name): | 56 def IsSystemLibrary(library_name): |
| 44 # If the library doesn't exist in the libraries directory, assume that it is | 57 # If the library doesn't exist in the libraries directory, assume that it is |
| 45 # an Android system library. | 58 # an Android system library. |
| 46 return not os.path.exists(FullLibraryPath(library_name)) | 59 return not os.path.exists(FullLibraryPath(library_name)) |
| 47 | 60 |
| 48 | 61 |
| 49 def CallReadElf(library_or_executable): | 62 def CallReadElf(library_or_executable): |
| 50 readelf_cmd = [_options.readelf, | 63 assert _readelf is not None |
| 64 readelf_cmd = [_readelf, |
| 51 '-d', | 65 '-d', |
| 52 library_or_executable] | 66 FullLibraryPath(library_or_executable)] |
| 53 return build_utils.CheckOutput(readelf_cmd) | 67 return build_utils.CheckOutput(readelf_cmd) |
| 54 | 68 |
| 55 | 69 |
| 56 def GetDependencies(library_or_executable): | 70 def GetDependencies(library_or_executable): |
| 57 elf = CallReadElf(library_or_executable) | 71 elf = CallReadElf(library_or_executable) |
| 58 return set(_library_re.findall(elf)) | 72 return set(_library_re.findall(elf)) |
| 59 | 73 |
| 60 | 74 |
| 61 def GetNonSystemDependencies(library_name): | 75 def GetNonSystemDependencies(library_name): |
| 62 all_deps = GetDependencies(FullLibraryPath(library_name)) | 76 all_deps = GetDependencies(FullLibraryPath(library_name)) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 84 parser = optparse.OptionParser() | 98 parser = optparse.OptionParser() |
| 85 | 99 |
| 86 parser.add_option('--input-libraries', | 100 parser.add_option('--input-libraries', |
| 87 help='A list of top-level input libraries.') | 101 help='A list of top-level input libraries.') |
| 88 parser.add_option('--libraries-dir', | 102 parser.add_option('--libraries-dir', |
| 89 help='The directory which contains shared libraries.') | 103 help='The directory which contains shared libraries.') |
| 90 parser.add_option('--readelf', help='Path to the readelf binary.') | 104 parser.add_option('--readelf', help='Path to the readelf binary.') |
| 91 parser.add_option('--output', help='Path to the generated .json file.') | 105 parser.add_option('--output', help='Path to the generated .json file.') |
| 92 parser.add_option('--stamp', help='Path to touch on success.') | 106 parser.add_option('--stamp', help='Path to touch on success.') |
| 93 | 107 |
| 94 global _options | 108 options, _ = parser.parse_args() |
| 95 _options, _ = parser.parse_args() | |
| 96 | 109 |
| 97 libraries = build_utils.ParseGypList(_options.input_libraries) | 110 SetReadelfPath(options.readelf) |
| 111 SetLibraryDirs(options.libraries_dir.split(',')) |
| 112 |
| 113 libraries = build_utils.ParseGypList(options.input_libraries) |
| 98 if len(libraries): | 114 if len(libraries): |
| 99 libraries = GetSortedTransitiveDependenciesForBinaries(libraries) | 115 libraries = GetSortedTransitiveDependenciesForBinaries(libraries) |
| 100 | 116 |
| 101 build_utils.WriteJson(libraries, _options.output, only_if_changed=True) | 117 # Convert to "base" library names: e.g. libfoo.so -> foo |
| 118 java_libraries_list = ( |
| 119 '{%s}' % ','.join(['"%s"' % s[3:-3] for s in libraries])) |
| 102 | 120 |
| 103 if _options.stamp: | 121 build_utils.WriteJson( |
| 104 build_utils.Touch(_options.stamp) | 122 {'libraries': libraries, 'java_libraries_list': java_libraries_list}, |
| 123 options.output, |
| 124 only_if_changed=True) |
| 125 |
| 126 if options.stamp: |
| 127 build_utils.Touch(options.stamp) |
| 105 | 128 |
| 106 | 129 |
| 107 if __name__ == '__main__': | 130 if __name__ == '__main__': |
| 108 sys.exit(main()) | 131 sys.exit(main()) |
| 109 | 132 |
| 110 | 133 |
| OLD | NEW |