blob: 2d9382af49d8fce21cac6c8ea30bd74e77a99aaf [file] [log] [blame]
Jaekyun Seok30706102017-02-02 00:44:58 +09001#!/usr/bin/env python
2#
3# Copyright (C) 2017 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16"""
17Utility to generate the Android manifest file of runtime resource overlay
18package for source module.
19"""
20from xml.dom.minidom import parseString
21import argparse
22import os
23import sys
24
25ANDROID_MANIFEST_TEMPLATE="""<manifest xmlns:android="http://schemas.android.com/apk/res/android"
Anton Hanssoncb8276f2019-03-18 11:43:30 +000026 package="%s.auto_generated_rro_%s__"
Jaekyun Seok30706102017-02-02 00:44:58 +090027 android:versionCode="1"
28 android:versionName="1.0">
Anton Hanssoncb8276f2019-03-18 11:43:30 +000029 <overlay android:targetPackage="%s" android:priority="%s" android:isStatic="true"/>
Jaekyun Seok30706102017-02-02 00:44:58 +090030</manifest>
31"""
32
33
34def get_args():
35 parser = argparse.ArgumentParser()
36 parser.add_argument(
37 '-u', '--use-package-name', action='store_true',
38 help='Indicate that --package-info is a package name.')
39 parser.add_argument(
40 '-p', '--package-info', required=True,
41 help='Manifest package name or manifest file path of source module.')
42 parser.add_argument(
Anton Hanssoncb8276f2019-03-18 11:43:30 +000043 '--partition', required=True,
44 help='The partition this RRO package is installed on.')
45 parser.add_argument(
46 '--priority', required=True,
47 help='The priority for the <overlay>.')
48 parser.add_argument(
Jaekyun Seok30706102017-02-02 00:44:58 +090049 '-o', '--output', required=True,
50 help='Output manifest file path.')
51 return parser.parse_args()
52
53
54def main(argv):
55 args = get_args()
56
Anton Hanssoncb8276f2019-03-18 11:43:30 +000057 partition = args.partition
58 priority = args.priority
Anton Hansson08231e12019-03-18 14:09:47 +000059 if args.use_package_name:
60 package_name = args.package_info
61 else:
Jaekyun Seok30706102017-02-02 00:44:58 +090062 with open(args.package_info) as f:
63 data = f.read()
64 f.close()
65 dom = parseString(data)
66 package_name = dom.documentElement.getAttribute('package')
67
68 with open(args.output, 'w+') as f:
Anton Hanssoncb8276f2019-03-18 11:43:30 +000069 f.write(ANDROID_MANIFEST_TEMPLATE % (package_name, partition, package_name, priority))
Jaekyun Seok30706102017-02-02 00:44:58 +090070 f.close()
71
72
73if __name__ == "__main__":
74 main(sys.argv)