From 1cd902f59774cb0f57c8a4fa6d3a0a8cf084b9cd Mon Sep 17 00:00:00 2001 From: Logan Chien Date: Thu, 15 Jun 2017 17:44:40 +0800 Subject: [PATCH] vndk-def: Add --revert flag to deps-closure This commit adds --revert flag to deps-closure so that a user can list the transitive users of a library. Bug: 62644173 Test: ./vndk_definition_tool.py deps-closure --revert /system/lib/libc.so ... Change-Id: I03aab8d629c88074d6111659853b1396d87326ad --- .../definition-tool/vndk_definition_tool.py | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/vndk/tools/definition-tool/vndk_definition_tool.py b/vndk/tools/definition-tool/vndk_definition_tool.py index c1eddfa0d..302cc5c15 100755 --- a/vndk/tools/definition-tool/vndk_definition_tool.py +++ b/vndk/tools/definition-tool/vndk_definition_tool.py @@ -1591,19 +1591,29 @@ class ELFLinker(object): return vndk_cap @staticmethod - def compute_closure(root_set, is_excluded): + def _compute_closure(root_set, is_excluded, get_successors): closure = set(root_set) stack = list(root_set) while stack: lib = stack.pop() - for dep in lib.deps: - if is_excluded(dep): + for succ in get_successors(lib): + if is_excluded(succ): continue - if dep not in closure: - closure.add(dep) - stack.append(dep) + if succ not in closure: + closure.add(succ) + stack.append(succ) return closure + @classmethod + def compute_deps_closure(cls, root_set, is_excluded): + return cls._compute_closure(root_set, is_excluded, lambda x: x.deps) + + compute_closure = compute_deps_closure + + @classmethod + def compute_users_closure(cls, root_set, is_excluded): + return cls._compute_closure(root_set, is_excluded, lambda x: x.users) + @staticmethod def _create_internal(scan_elf_files, system_dirs, system_dirs_as_vendor, system_dirs_ignored, vendor_dirs, @@ -2217,6 +2227,9 @@ class DepsClosureCommand(ELFGraphCommand): parser.add_argument('--exclude-ndk', action='store_true', help='exclude ndk libraries') + parser.add_argument('--revert', action='store_true', + help='print usage dependency') + def main(self, args): generic_refs, graph = self.create_from_args(args) @@ -2234,7 +2247,11 @@ class DepsClosureCommand(ELFGraphCommand): def is_excluded_libs(lib): return lib in excluded_libs - closure = graph.compute_closure(root_libs, is_excluded_libs) + if args.revert: + closure = graph.compute_users_closure(root_libs, is_excluded_libs) + else: + closure = graph.compute_deps_closure(root_libs, is_excluded_libs) + for lib in sorted_lib_path_list(closure): print(lib) return 0