OLD | NEW |
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 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 if args.list: | 70 if args.list: |
71 data = {} | 71 data = {} |
72 data['aidl'] = [] | 72 data['aidl'] = [] |
73 data['assets'] = [] | 73 data['assets'] = [] |
74 data['resources'] = [] | 74 data['resources'] = [] |
75 data['subjars'] = [] | 75 data['subjars'] = [] |
76 data['subjar_tuples'] = [] | 76 data['subjar_tuples'] = [] |
77 data['has_classes_jar'] = False | 77 data['has_classes_jar'] = False |
78 data['has_proguard_flags'] = False | 78 data['has_proguard_flags'] = False |
79 data['has_native_libraries'] = False | 79 data['has_native_libraries'] = False |
| 80 data['has_r_text_file'] = False |
80 with zipfile.ZipFile(aar_file) as z: | 81 with zipfile.ZipFile(aar_file) as z: |
81 data['is_manifest_empty'] = ( | 82 data['is_manifest_empty'] = ( |
82 _IsManifestEmpty(z.read('AndroidManifest.xml'))) | 83 _IsManifestEmpty(z.read('AndroidManifest.xml'))) |
83 | 84 |
84 for name in z.namelist(): | 85 for name in z.namelist(): |
85 if name.endswith('/'): | 86 if name.endswith('/'): |
86 continue | 87 continue |
87 if name.startswith('aidl/'): | 88 if name.startswith('aidl/'): |
88 data['aidl'].append(name) | 89 data['aidl'].append(name) |
89 elif name.startswith('res/'): | 90 elif name.startswith('res/'): |
90 data['resources'].append(name) | 91 data['resources'].append(name) |
91 elif name.startswith('libs/') and name.endswith('.jar'): | 92 elif name.startswith('libs/') and name.endswith('.jar'): |
92 label = posixpath.basename(name)[:-4] | 93 label = posixpath.basename(name)[:-4] |
93 label = re.sub(r'[^a-zA-Z0-9._]', '_', label) | 94 label = re.sub(r'[^a-zA-Z0-9._]', '_', label) |
94 data['subjars'].append(name) | 95 data['subjars'].append(name) |
95 data['subjar_tuples'].append([label, name]) | 96 data['subjar_tuples'].append([label, name]) |
96 elif name.startswith('assets/'): | 97 elif name.startswith('assets/'): |
97 data['assets'].append(name) | 98 data['assets'].append(name) |
98 elif name.startswith('jni/'): | 99 elif name.startswith('jni/'): |
99 data['has_native_libraries'] = True | 100 data['has_native_libraries'] = True |
100 elif name == 'classes.jar': | 101 elif name == 'classes.jar': |
101 data['has_classes_jar'] = True | 102 data['has_classes_jar'] = True |
102 elif name == 'proguard.txt': | 103 elif name == 'proguard.txt': |
103 data['has_proguard_flags'] = True | 104 data['has_proguard_flags'] = True |
| 105 elif name == 'R.txt': |
| 106 # Some AARs, e.g. gvr_controller_java, have empty R.txt. Such AARs |
| 107 # have no resources as well. We treat empty R.txt as having no R.txt. |
| 108 data['has_r_text_file'] = (z.read('R.txt').strip() != '') |
104 | 109 |
105 print gn_helpers.ToGNString(data) | 110 print gn_helpers.ToGNString(data) |
106 | 111 |
107 | 112 |
108 if __name__ == '__main__': | 113 if __name__ == '__main__': |
109 sys.exit(main()) | 114 sys.exit(main()) |
OLD | NEW |