Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: build/android/gyp/aar.py

Issue 2309643002: Make android_aar_prebuilt() aware of remaining features (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | build/config/android/rules.gni » ('j') | build/config/android/rules.gni » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2016 The Chromium Authors. All rights reserved. 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 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Processes an Android AAR file.""" 7 """Processes an Android AAR file."""
8 8
9 import argparse 9 import argparse
10 import os 10 import os
11 import posixpath
12 import re
11 import shutil 13 import shutil
12 import sys 14 import sys
15 from xml.etree import ElementTree
13 import zipfile 16 import zipfile
14 17
15 from util import build_utils 18 from util import build_utils
16 19
17 sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 20 sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__),
18 os.pardir, os.pardir))) 21 os.pardir, os.pardir)))
19 import gn_helpers 22 import gn_helpers
20 23
21 24
25 def _IsManifestEmpty(manifest_str):
26 """Returns whether the given manifest has merge-worthy elements.
27
28 E.g.: <activity>, <service>, etc.
29 """
30 doc = ElementTree.fromstring(manifest_str)
31 for node in doc:
32 if node.tag == 'application':
33 if len(node):
34 return False
35 elif node.tag != 'uses-sdk':
36 return False
37
38 return True
39
40
22 def main(): 41 def main():
23 parser = argparse.ArgumentParser(description=__doc__) 42 parser = argparse.ArgumentParser(description=__doc__)
24 parser.add_argument('--input-file', 43 parser.add_argument('--input-file',
25 help='Path to the AAR file.', 44 help='Path to the AAR file.',
26 required=True, 45 required=True,
27 metavar='FILE') 46 metavar='FILE')
28 parser.add_argument('--extract', 47 parser.add_argument('--extract',
29 help='Extract the files to output directory.', 48 help='Extract the files to output directory.',
30 action='store_true') 49 action='store_true')
31 parser.add_argument('--list', 50 parser.add_argument('--list',
(...skipping 11 matching lines...) Expand all
43 aar_file = args.input_file 62 aar_file = args.input_file
44 output_dir = args.output_dir 63 output_dir = args.output_dir
45 64
46 if args.extract: 65 if args.extract:
47 # Clear previously extracted versions of the AAR. 66 # Clear previously extracted versions of the AAR.
48 shutil.rmtree(output_dir, True) 67 shutil.rmtree(output_dir, True)
49 build_utils.ExtractAll(aar_file, path=output_dir) 68 build_utils.ExtractAll(aar_file, path=output_dir)
50 69
51 if args.list: 70 if args.list:
52 data = {} 71 data = {}
72 data['assets'] = []
53 data['resources'] = [] 73 data['resources'] = []
54 data['jars'] = [] 74 data['subjars'] = []
75 data['subjar_labels'] = []
76 data['has_classes_jar'] = False
77 data['has_proguard_flags'] = False
78 data['has_native_libraries'] = False
55 with zipfile.ZipFile(aar_file) as z: 79 with zipfile.ZipFile(aar_file) as z:
80 data['is_manifest_empty'] = (
81 _IsManifestEmpty(z.read('AndroidManifest.xml')))
82
56 for name in z.namelist(): 83 for name in z.namelist():
57 if name.startswith('res/') and not name.endswith('/'): 84 if name.endswith('/'):
85 continue
86 if name.startswith('res/'):
58 data['resources'].append(name) 87 data['resources'].append(name)
59 if name.endswith('.jar'): 88 elif name.startswith('libs/') and name.endswith('.jar'):
60 data['jars'].append(name) 89 label = posixpath.basename(name)[:-4]
90 label = re.sub(r'[^a-zA-Z0-9._]', '_', label)
91 data['subjars'].append(name)
Ian Wen 2016/09/06 19:09:59 One way to simplify the code a bit, is to still us
agrieve 2016/09/06 21:00:51 I originally separated this from the main classes.
Ian Wen 2016/09/06 21:38:34 Okay sg. :)
92 data['subjar_labels'].append(label)
93 elif name.startswith('assets/'):
94 data['assets'].append(name)
95 elif name.startswith('jni/'):
96 data['has_native_libraries'] = True
Ian Wen 2016/09/06 19:09:59 Instead of outputting a boolean, have you consider
agrieve 2016/09/06 21:00:51 I did consider it. The tricky bit is that the ther
Ian Wen 2016/09/06 21:38:34 Hmm if we are not going to support native librarie
agrieve 2016/09/07 02:19:30 Much of the motivation behind these flags is that
97 elif name == 'classes.jar':
98 data['has_classes_jar'] = True
99 elif name == 'proguard.txt':
100 data['has_proguard_flags'] = True
Ian Wen 2016/09/06 19:09:59 How about AIDLs and annotations? AIDLs are includ
agrieve 2016/09/06 21:00:51 Was going by the list here: http://tools.android.c
101
61 print gn_helpers.ToGNString(data) 102 print gn_helpers.ToGNString(data)
62 103
63 104
64 if __name__ == '__main__': 105 if __name__ == '__main__':
65 sys.exit(main()) 106 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | build/config/android/rules.gni » ('j') | build/config/android/rules.gni » ('J')

Powered by Google App Engine
This is Rietveld 408576698