summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLogan Chien <loganchien@google.com>2017-07-20 18:07:45 +0800
committerLogan Chien <loganchien@google.com>2017-08-23 09:56:33 +0800
commit8f707d70254e1e84a9c849b60b516b5286048090 (patch)
tree46ba85d1f2fa62c461c37270d6fe25f3c8ae6aef
parentf757dbcb504647d7b133860c5b2de8cd2cb41590 (diff)
downloaddevelopment-8f707d70254e1e84a9c849b60b516b5286048090.tar.gz
vndk-def: Refactor ModuleInfo class
This commit refactors ModuleInfo class to speed up the source directory lookup. Besides, the commit also moves ModuleInfo upward so that it can be used by other commands in the upcoming commits. Bug: 64503245 Test: ./tests/test_module_info.py Test: vndk and check-dep on multiple devices and get the same output. Change-Id: I4253205f63798a4cf4ef3b8cd08ec65711381337 Merged-In: I6e7a59773a35d62bde6454cc3052f76224c1fe21 (cherry picked from commit 5a6ff39a806807b197353f4713d0a612d7d3e43b)
-rwxr-xr-xvndk/tools/definition-tool/tests/test_module_info.py7
-rwxr-xr-xvndk/tools/definition-tool/vndk_definition_tool.py59
2 files changed, 44 insertions, 22 deletions
diff --git a/vndk/tools/definition-tool/tests/test_module_info.py b/vndk/tools/definition-tool/tests/test_module_info.py
index ba9f6189d..2da17b40d 100755
--- a/vndk/tools/definition-tool/tests/test_module_info.py
+++ b/vndk/tools/definition-tool/tests/test_module_info.py
@@ -15,12 +15,13 @@ SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
class ModuleInfoTest(unittest.TestCase):
def test_default(self):
- m = ModuleInfo()
+ m = ModuleInfo.load_from_path_or_default(None)
self.assertEqual([], m.get_module_path('/system/lib64/libA.so'))
def test_get_module_path(self):
- m = ModuleInfo(os.path.join(SCRIPT_DIR, 'testdata', 'test_module_info',
- 'module-info.json'))
+ json_path = os.path.join(SCRIPT_DIR, 'testdata', 'test_module_info',
+ 'module-info.json')
+ m = ModuleInfo.load_from_path_or_default(json_path)
self.assertEqual(['system/core/libA'],
m.get_module_path('/system/lib64/libA.so'))
diff --git a/vndk/tools/definition-tool/vndk_definition_tool.py b/vndk/tools/definition-tool/vndk_definition_tool.py
index 083bb7cd9..f6193c7d8 100755
--- a/vndk/tools/definition-tool/vndk_definition_tool.py
+++ b/vndk/tools/definition-tool/vndk_definition_tool.py
@@ -1760,6 +1760,43 @@ class GenericRefs(object):
#------------------------------------------------------------------------------
+# Module Info
+#------------------------------------------------------------------------------
+
+class ModuleInfo(object):
+ def __init__(self, json=None):
+ if not json:
+ self._mods = dict()
+ return
+
+ mods = collections.defaultdict(set)
+ installed_path_patt = re.compile(
+ '.*[\\\\/]target[\\\\/]product[\\\\/][^\\\\/]+([\\\\/].*)$')
+ for name, module in json.items():
+ for path in module['installed']:
+ match = installed_path_patt.match(path)
+ if match:
+ for path in module['path']:
+ mods[match.group(1)].add(path)
+ self._mods = { installed_path: sorted(src_dirs)
+ for installed_path, src_dirs in mods.items() }
+
+ def get_module_path(self, installed_path):
+ return self._mods.get(installed_path, [])
+
+ @staticmethod
+ def load(f):
+ return ModuleInfo(json.load(f))
+
+ @staticmethod
+ def load_from_path_or_default(path):
+ if not path:
+ return ModuleInfo()
+ with open(path, 'r') as f:
+ return ModuleInfo.load(f)
+
+
+#------------------------------------------------------------------------------
# Commands
#------------------------------------------------------------------------------
@@ -2275,22 +2312,6 @@ class DepsClosureCommand(ELFGraphCommand):
return 0
-class ModuleInfo(object):
- def __init__(self, module_info_path=None):
- if not module_info_path:
- self.json = dict()
- else:
- with open(module_info_path, 'r') as f:
- self.json = json.load(f)
-
- def get_module_path(self, installed_path):
- for name, module in self.json.items():
- if any(path.endswith(installed_path)
- for path in module['installed']):
- return module['path']
- return []
-
-
class CheckDepCommandBase(ELFGraphCommand):
def add_argparser_options(self, parser):
super(CheckDepCommandBase, self).add_argparser_options(parser)
@@ -2302,7 +2323,7 @@ class CheckDepCommandBase(ELFGraphCommand):
@staticmethod
def _dump_dep(lib, bad_deps, module_info):
print(lib.path)
- for module_path in sorted(module_info.get_module_path(lib.path)):
+ for module_path in module_info.get_module_path(lib.path):
print('\tMODULE_PATH:', module_path)
for dep in sorted(bad_deps):
print('\t' + dep.path)
@@ -2359,7 +2380,7 @@ class CheckDepCommand(CheckDepCommandBase):
tagged_paths = TaggedPathDict.create_from_csv_path(args.tag_file)
tagged_libs = TaggedLibDict.create_from_graph(graph, tagged_paths)
- module_info = ModuleInfo(args.module_info)
+ module_info = ModuleInfo.load_from_path_or_default(args.module_info)
num_errors = self._check_vendor_dep(graph, tagged_libs, module_info)
@@ -2417,7 +2438,7 @@ class CheckEligibleListCommand(CheckDepCommandBase):
tagged_paths = TaggedPathDict.create_from_csv_path(args.tag_file)
tagged_libs = TaggedLibDict.create_from_graph(graph, tagged_paths)
- module_info = ModuleInfo(args.module_info)
+ module_info = ModuleInfo.load_from_path_or_default(args.module_info)
num_errors = self._check_eligible_vndk_dep(graph, tagged_libs,
module_info)