summaryrefslogtreecommitdiff
path: root/scripts/manifest.py
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-09-13 20:11:51 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2024-09-13 20:11:51 +0000
commitda8bc7929e05a0e96be29a35ab5a83cbbf9680be (patch)
tree78410d0aa6fc7f3e6ce803f8764be36a3ffa735a /scripts/manifest.py
parent49361b616a2bb1f66af67547beb9363ecdca3be9 (diff)
parentc2ea958b3d4474d203d2937a02b265a39f77c8e8 (diff)
Merge changes from topic "flag_application_manifest" into main am: c2ea958b3d
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/3260724 Change-Id: I9d6d4446ab53bad4a9bea493afd7a5bd9e653ec5 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'scripts/manifest.py')
-rwxr-xr-xscripts/manifest.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/scripts/manifest.py b/scripts/manifest.py
index 81f9c61a8..32603e869 100755
--- a/scripts/manifest.py
+++ b/scripts/manifest.py
@@ -23,9 +23,40 @@ from xml.dom import minidom
android_ns = 'http://schemas.android.com/apk/res/android'
+def get_or_create_applications(doc, manifest):
+ """Get all <application> tags from the manifest, or create one if none exist.
+ Multiple <application> tags may exist when manifest feature flagging is used.
+ """
+ applications = get_children_with_tag(manifest, 'application')
+ if len(applications) == 0:
+ application = doc.createElement('application')
+ indent = get_indent(manifest.firstChild, 1)
+ first = manifest.firstChild
+ manifest.insertBefore(doc.createTextNode(indent), first)
+ manifest.insertBefore(application, first)
+ applications.append(application)
+ return applications
+
+
+def get_or_create_uses_sdks(doc, manifest):
+ """Get all <uses-sdk> tags from the manifest, or create one if none exist.
+ Multiple <uses-sdk> tags may exist when manifest feature flagging is used.
+ """
+ uses_sdks = get_children_with_tag(manifest, 'uses-sdk')
+ if len(uses_sdks) == 0:
+ uses_sdk = doc.createElement('uses-sdk')
+ indent = get_indent(manifest.firstChild, 1)
+ manifest.insertBefore(uses_sdk, manifest.firstChild)
+
+ # Insert an indent before uses-sdk to line it up with the indentation of the
+ # other children of the <manifest> tag.
+ manifest.insertBefore(doc.createTextNode(indent), manifest.firstChild)
+ uses_sdks.append(uses_sdk)
+ return uses_sdks
+
def get_children_with_tag(parent, tag_name):
children = []
- for child in parent.childNodes:
+ for child in parent.childNodes:
if child.nodeType == minidom.Node.ELEMENT_NODE and \
child.tagName == tag_name:
children.append(child)