Home | History | Annotate | Download | only in tools
      1 #!/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 """
     17 Utility to generate the Android manifest file of runtime resource overlay
     18 package for source module.
     19 """
     20 from xml.dom.minidom import parseString
     21 import argparse
     22 import os
     23 import sys
     24 
     25 ANDROID_MANIFEST_TEMPLATE="""<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     26     package="%s.auto_generated_rro__"
     27     android:versionCode="1"
     28     android:versionName="1.0">
     29     <overlay android:targetPackage="%s" android:priority="0" android:isStatic="true"/>
     30 </manifest>
     31 """
     32 
     33 
     34 def 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(
     43         '-o', '--output', required=True,
     44         help='Output manifest file path.')
     45     return parser.parse_args()
     46 
     47 
     48 def main(argv):
     49   args = get_args()
     50 
     51   package_name = args.package_info
     52   if not args.use_package_name:
     53     with open(args.package_info) as f:
     54       data = f.read()
     55       f.close()
     56       dom = parseString(data)
     57       package_name = dom.documentElement.getAttribute('package')
     58 
     59   with open(args.output, 'w+') as f:
     60     f.write(ANDROID_MANIFEST_TEMPLATE % (package_name, package_name))
     61     f.close()
     62 
     63 
     64 if __name__ == "__main__":
     65   main(sys.argv)
     66