Merge "manifest_check.py: trim namespace part of the module, if needed."
This commit is contained in:
@@ -90,6 +90,15 @@ def enforce_uses_libraries(manifest, required, optional, relax, is_apk, path):
|
|||||||
else:
|
else:
|
||||||
manifest_required, manifest_optional, tags = extract_uses_libs_xml(manifest)
|
manifest_required, manifest_optional, tags = extract_uses_libs_xml(manifest)
|
||||||
|
|
||||||
|
# Trim namespace component. Normally Soong does that automatically when it
|
||||||
|
# handles module names specified in Android.bp properties. However not all
|
||||||
|
# <uses-library> entries in the manifest correspond to real modules: some of
|
||||||
|
# the optional libraries may be missing at build time. Therefor this script
|
||||||
|
# accepts raw module names as spelled in Android.bp/Amdroid.mk and trims the
|
||||||
|
# optional namespace part manually.
|
||||||
|
required = trim_namespace_parts(required)
|
||||||
|
optional = trim_namespace_parts(optional)
|
||||||
|
|
||||||
if manifest_required == required and manifest_optional == optional:
|
if manifest_required == required and manifest_optional == optional:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -118,6 +127,17 @@ def enforce_uses_libraries(manifest, required, optional, relax, is_apk, path):
|
|||||||
return errmsg
|
return errmsg
|
||||||
|
|
||||||
|
|
||||||
|
MODULE_NAMESPACE = re.compile("^//[^:]+:")
|
||||||
|
|
||||||
|
def trim_namespace_parts(modules):
|
||||||
|
"""Trim the namespace part of each module, if present. Leave only the name."""
|
||||||
|
|
||||||
|
trimmed = []
|
||||||
|
for module in modules:
|
||||||
|
trimmed.append(MODULE_NAMESPACE.sub('', module))
|
||||||
|
return trimmed
|
||||||
|
|
||||||
|
|
||||||
def extract_uses_libs_apk(badging):
|
def extract_uses_libs_apk(badging):
|
||||||
"""Extract <uses-library> tags from the manifest of an APK."""
|
"""Extract <uses-library> tags from the manifest of an APK."""
|
||||||
|
|
||||||
|
@@ -183,6 +183,15 @@ class EnforceUsesLibrariesTest(unittest.TestCase):
|
|||||||
optional_uses_libraries=['bar'])
|
optional_uses_libraries=['bar'])
|
||||||
self.assertTrue(matches)
|
self.assertTrue(matches)
|
||||||
|
|
||||||
|
def test_mixed_with_namespace(self):
|
||||||
|
xml = self.xml_tmpl % ('\n'.join([uses_library_xml('foo'),
|
||||||
|
uses_library_xml('bar', required_xml(False))]))
|
||||||
|
apk = self.apk_tmpl % ('\n'.join([uses_library_apk('foo'),
|
||||||
|
uses_library_apk('bar', required_apk(False))]))
|
||||||
|
matches = self.run_test(xml, apk, uses_libraries=['//x/y/z:foo'],
|
||||||
|
optional_uses_libraries=['//x/y/z:bar'])
|
||||||
|
self.assertTrue(matches)
|
||||||
|
|
||||||
|
|
||||||
class ExtractTargetSdkVersionTest(unittest.TestCase):
|
class ExtractTargetSdkVersionTest(unittest.TestCase):
|
||||||
def run_test(self, xml, apk, version):
|
def run_test(self, xml, apk, version):
|
||||||
|
Reference in New Issue
Block a user