Index: build/android/gyp/aar.py |
diff --git a/build/android/gyp/aar.py b/build/android/gyp/aar.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..4a5f846b1b0c6b703caa57b8065c30907fc2a4b9 |
--- /dev/null |
+++ b/build/android/gyp/aar.py |
@@ -0,0 +1,63 @@ |
+#!/usr/bin/env python |
+# |
+# Copyright 2016 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+"""Processes an Android AAR file.""" |
+ |
+import argparse |
+import os |
+import shutil |
+import sys |
+import zipfile |
+ |
+from util import build_utils |
+ |
+sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) |
jbudorick
2016/07/19 13:14:06
nit: sys.path.append(os.path.abspath(...))
Ian Wen
2016/07/19 18:36:48
Done.
|
+import gn_helpers |
+ |
+ |
+def main(): |
+ parser = argparse.ArgumentParser(description=__doc__) |
+ parser.add_argument('--input-file', |
+ help='Path to the AAR file.', |
+ required=True, |
+ metavar='FILE') |
+ parser.add_argument('--extract', |
+ help='Extract the files to output directory.', |
+ action='store_true') |
+ parser.add_argument('--list', |
+ help='List all the resource and jar files.', |
+ action='store_true') |
+ parser.add_argument('--output-dir', |
+ help='Output directory for the extracted files. Must ' |
+ 'be set if --extract is set.', |
+ metavar='DIR') |
+ |
+ args = parser.parse_args() |
+ assert args.extract is not None or args.list is not None |
jbudorick
2016/07/19 13:14:06
nit: this should be calling parser.error if neithe
Ian Wen
2016/07/19 18:36:48
Done.
|
+ |
+ aar_file = args.input_file # e.g. library.aar |
jbudorick
2016/07/19 13:14:06
nit: move these examples up into the help text.
Ian Wen
2016/07/19 18:36:48
These comments are very basic. I will simply remov
|
+ output_dir = args.output_dir # e.g. path/to/output |
+ |
+ if args.extract: |
+ # Clear previously extracted versions of the AAR. |
+ shutil.rmtree(output_dir, True) |
+ build_utils.ExtractAll(aar_file, path=output_dir) |
+ |
+ if args.list: |
+ data = {} |
+ data['resources'] = [] |
+ data['jars'] = [] |
+ with zipfile.ZipFile(aar_file) as z: |
+ for name in z.namelist(): |
+ if name.startswith('res/') and not name.endswith('/'): |
+ data['resources'].append(name) |
+ if name.endswith('.jar'): |
+ data['jars'].append(name) |
+ print gn_helpers.ToGNString(data) |
+ |
+ |
+if __name__ == '__main__': |
+ sys.exit(main()) |