Merge "android.test.{base|mock} are added as optional libraries."

am: e8f2977f80

Change-Id: Ia185f939b28ac14ab9cabeb40a323549d5fa8759
This commit is contained in:
Jiyong Park 2018-10-16 21:44:18 -07:00 committed by android-build-merger
commit 980b757b13

View file

@ -56,7 +56,9 @@ def parse_args():
parser.add_argument('--library', dest='library', action='store_true', parser.add_argument('--library', dest='library', action='store_true',
help='manifest is for a static library') help='manifest is for a static library')
parser.add_argument('--uses-library', dest='uses_libraries', action='append', parser.add_argument('--uses-library', dest='uses_libraries', action='append',
help='specify additional <uses-library> tag to add') help='specify additional <uses-library> tag to add. android:requred is set to true')
parser.add_argument('--optional-uses-library', dest='optional_uses_libraries', action='append',
help='specify additional <uses-library> tag to add. android:requred is set to false')
parser.add_argument('--uses-non-sdk-api', dest='uses_non_sdk_api', action='store_true', parser.add_argument('--uses-non-sdk-api', dest='uses_non_sdk_api', action='store_true',
help='manifest is for a package built against the platform') help='manifest is for a package built against the platform')
parser.add_argument('input', help='input AndroidManifest.xml file') parser.add_argument('input', help='input AndroidManifest.xml file')
@ -190,12 +192,13 @@ def raise_min_sdk_version(doc, min_sdk_version, target_sdk_version, library):
element.setAttributeNode(target_attr) element.setAttributeNode(target_attr)
def add_uses_libraries(doc, new_uses_libraries): def add_uses_libraries(doc, new_uses_libraries, required):
"""Add additional <uses-library> tags with android:required=false. """Add additional <uses-library> tags
Args: Args:
doc: The XML document. May be modified by this function. doc: The XML document. May be modified by this function.
new_uses_libraries: The names of libraries to be added by this function. new_uses_libraries: The names of libraries to be added by this function.
required: The value of android:required attribute. Can be true or false.
Raises: Raises:
RuntimeError: Invalid manifest RuntimeError: Invalid manifest
""" """
@ -227,7 +230,7 @@ def add_uses_libraries(doc, new_uses_libraries):
ul = doc.createElement('uses-library') ul = doc.createElement('uses-library')
ul.setAttributeNS(android_ns, 'android:name', name) ul.setAttributeNS(android_ns, 'android:name', name)
ul.setAttributeNS(android_ns, 'android:required', 'false') ul.setAttributeNS(android_ns, 'android:required', str(required).lower())
application.insertBefore(doc.createTextNode(indent), last) application.insertBefore(doc.createTextNode(indent), last)
application.insertBefore(ul, last) application.insertBefore(ul, last)
@ -285,7 +288,10 @@ def main():
raise_min_sdk_version(doc, args.min_sdk_version, args.target_sdk_version, args.library) raise_min_sdk_version(doc, args.min_sdk_version, args.target_sdk_version, args.library)
if args.uses_libraries: if args.uses_libraries:
add_uses_libraries(doc, args.uses_libraries) add_uses_libraries(doc, args.uses_libraries, True)
if args.optional_uses_libraries:
add_uses_libraries(doc, args.optional_uses_libraries, False)
if args.uses_non_sdk_api: if args.uses_non_sdk_api:
add_uses_non_sdk_api(doc) add_uses_non_sdk_api(doc)