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

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

Issue 2309643002: Make android_aar_prebuilt() aware of remaining features (Closed)
Patch Set: simplify jar_labels by using tuples 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') | no next file with comments »
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['aidl'] = []
73 data['assets'] = []
53 data['resources'] = [] 74 data['resources'] = []
54 data['jars'] = [] 75 data['subjars'] = []
76 data['subjar_tuples'] = []
77 data['has_classes_jar'] = False
78 data['has_proguard_flags'] = False
79 data['has_native_libraries'] = False
55 with zipfile.ZipFile(aar_file) as z: 80 with zipfile.ZipFile(aar_file) as z:
81 data['is_manifest_empty'] = (
82 _IsManifestEmpty(z.read('AndroidManifest.xml')))
83
56 for name in z.namelist(): 84 for name in z.namelist():
57 if name.startswith('res/') and not name.endswith('/'): 85 if name.endswith('/'):
86 continue
87 if name.startswith('aidl/'):
88 data['aidl'].append(name)
89 elif name.startswith('res/'):
58 data['resources'].append(name) 90 data['resources'].append(name)
59 if name.endswith('.jar'): 91 elif name.startswith('libs/') and name.endswith('.jar'):
60 data['jars'].append(name) 92 label = posixpath.basename(name)[:-4]
93 label = re.sub(r'[^a-zA-Z0-9._]', '_', label)
94 data['subjars'].append(name)
95 data['subjar_tuples'].append([label, name])
96 elif name.startswith('assets/'):
97 data['assets'].append(name)
98 elif name.startswith('jni/'):
99 data['has_native_libraries'] = True
100 elif name == 'classes.jar':
101 data['has_classes_jar'] = True
102 elif name == 'proguard.txt':
103 data['has_proguard_flags'] = True
104
61 print gn_helpers.ToGNString(data) 105 print gn_helpers.ToGNString(data)
62 106
63 107
64 if __name__ == '__main__': 108 if __name__ == '__main__':
65 sys.exit(main()) 109 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | build/config/android/rules.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698