OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # |
| 3 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. |
| 6 |
| 7 """Processes an Android AAR file.""" |
| 8 |
| 9 import argparse |
| 10 import os |
| 11 import shutil |
| 12 import sys |
| 13 import zipfile |
| 14 |
| 15 from util import build_utils |
| 16 |
| 17 sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), |
| 18 os.pardir, os.pardir))) |
| 19 import gn_helpers |
| 20 |
| 21 |
| 22 def main(): |
| 23 parser = argparse.ArgumentParser(description=__doc__) |
| 24 parser.add_argument('--input-file', |
| 25 help='Path to the AAR file.', |
| 26 required=True, |
| 27 metavar='FILE') |
| 28 parser.add_argument('--extract', |
| 29 help='Extract the files to output directory.', |
| 30 action='store_true') |
| 31 parser.add_argument('--list', |
| 32 help='List all the resource and jar files.', |
| 33 action='store_true') |
| 34 parser.add_argument('--output-dir', |
| 35 help='Output directory for the extracted files. Must ' |
| 36 'be set if --extract is set.', |
| 37 metavar='DIR') |
| 38 |
| 39 args = parser.parse_args() |
| 40 if not args.extract and not args.list: |
| 41 parser.error('Either --extract or --list has to be specified.') |
| 42 |
| 43 aar_file = args.input_file |
| 44 output_dir = args.output_dir |
| 45 |
| 46 if args.extract: |
| 47 # Clear previously extracted versions of the AAR. |
| 48 shutil.rmtree(output_dir, True) |
| 49 build_utils.ExtractAll(aar_file, path=output_dir) |
| 50 |
| 51 if args.list: |
| 52 data = {} |
| 53 data['resources'] = [] |
| 54 data['jars'] = [] |
| 55 with zipfile.ZipFile(aar_file) as z: |
| 56 for name in z.namelist(): |
| 57 if name.startswith('res/') and not name.endswith('/'): |
| 58 data['resources'].append(name) |
| 59 if name.endswith('.jar'): |
| 60 data['jars'].append(name) |
| 61 print gn_helpers.ToGNString(data) |
| 62 |
| 63 |
| 64 if __name__ == '__main__': |
| 65 sys.exit(main()) |
OLD | NEW |