summaryrefslogtreecommitdiff
path: root/chromium/build/android/gyp/aar.py
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/build/android/gyp/aar.py')
-rwxr-xr-xchromium/build/android/gyp/aar.py79
1 files changed, 69 insertions, 10 deletions
diff --git a/chromium/build/android/gyp/aar.py b/chromium/build/android/gyp/aar.py
index 87f189014a1..ffd6cf8fa12 100755
--- a/chromium/build/android/gyp/aar.py
+++ b/chromium/build/android/gyp/aar.py
@@ -23,15 +23,30 @@ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__),
import gn_helpers
+# Regular expression to extract -checkdiscard / -check* lines.
+# Does not support nested comments with "}" in them (oh well).
+_CHECKDISCARD_PATTERN = re.compile(r'^\s*?-check.*?}\s*',
+ re.DOTALL | re.MULTILINE)
+
+_PROGUARD_TXT = 'proguard.txt'
+_PROGUARD_CHECKS_TXT = 'proguard-checks.txt'
+
+
def _IsManifestEmpty(manifest_str):
- """Returns whether the given manifest has merge-worthy elements.
+ """Decides whether the given manifest has merge-worthy elements.
E.g.: <activity>, <service>, etc.
+
+ Args:
+ manifest_str: Content of a manifiest XML.
+
+ Returns:
+ Whether the manifest has merge-worthy elements.
"""
doc = ElementTree.fromstring(manifest_str)
for node in doc:
if node.tag == 'application':
- if len(node):
+ if node.getchildren():
return False
elif node.tag != 'uses-sdk':
return False
@@ -40,6 +55,14 @@ def _IsManifestEmpty(manifest_str):
def _CreateInfo(aar_file):
+ """Extracts and return .info data from an .aar file.
+
+ Args:
+ aar_file: Path to an input .aar file.
+
+ Returns:
+ A dict containing .info data.
+ """
data = {}
data['aidl'] = []
data['assets'] = []
@@ -76,16 +99,40 @@ def _CreateInfo(aar_file):
data['native_libraries'] = [name]
elif name == 'classes.jar':
data['has_classes_jar'] = True
- elif name == 'proguard.txt':
+ elif name == _PROGUARD_TXT:
data['has_proguard_flags'] = True
elif name == 'R.txt':
# Some AARs, e.g. gvr_controller_java, have empty R.txt. Such AARs
# have no resources as well. We treat empty R.txt as having no R.txt.
- data['has_r_text_file'] = (z.read('R.txt').strip() != '')
+ data['has_r_text_file'] = bool(z.read('R.txt').strip())
+
+ if data['has_proguard_flags']:
+ config = z.read(_PROGUARD_TXT)
+ if _CHECKDISCARD_PATTERN.search(config):
+ data['has_proguard_check_flags'] = True
+
return data
-def _PerformExtract(aar_file, output_dir, name_allowlist):
+def _SplitProguardConfig(tmp_dir):
+ # Put -checkdiscard (and friends) into a separate proguard config.
+ # https://crbug.com/1093831
+ main_flag_path = os.path.join(tmp_dir, _PROGUARD_TXT)
+ check_flag_path = os.path.join(tmp_dir, _PROGUARD_CHECKS_TXT)
+ with open(main_flag_path) as f:
+ config_data = f.read()
+ with open(main_flag_path, 'w') as f:
+ MSG = ('# Check flag moved to proguard-checks.txt by '
+ '//build/android/gyp/aar.py\n')
+ f.write(_CHECKDISCARD_PATTERN.sub(MSG, config_data))
+ with open(check_flag_path, 'w') as f:
+ f.write('# Check flags extracted by //build/android/gyp/aar.py\n\n')
+ for m in _CHECKDISCARD_PATTERN.finditer(config_data):
+ f.write(m.group(0))
+
+
+def _PerformExtract(aar_file, output_dir, name_allowlist,
+ has_proguard_check_flags):
with build_utils.TempDir() as tmp_dir:
tmp_dir = os.path.join(tmp_dir, 'staging')
os.mkdir(tmp_dir)
@@ -94,6 +141,10 @@ def _PerformExtract(aar_file, output_dir, name_allowlist):
# Write a breadcrumb so that SuperSize can attribute files back to the .aar.
with open(os.path.join(tmp_dir, 'source.info'), 'w') as f:
f.write('source={}\n'.format(aar_file))
+
+ if has_proguard_check_flags:
+ _SplitProguardConfig(tmp_dir)
+
shutil.rmtree(output_dir, ignore_errors=True)
shutil.move(tmp_dir, output_dir)
@@ -135,7 +186,7 @@ def main():
# Generated by //build/android/gyp/aar.py
# To regenerate, use "update_android_aar_prebuilts = true" and run "gn gen".
-""" + gn_helpers.ToGNString(aar_info)
+""" + gn_helpers.ToGNString(aar_info, pretty=True)
if args.command == 'extract':
if args.assert_info_file:
@@ -150,12 +201,20 @@ def main():
if args.ignore_resources:
names = [n for n in names if not n.startswith('res')]
+ has_proguard_check_flags = aar_info.get('has_proguard_check_flags')
output_paths = [os.path.join(args.output_dir, n) for n in names]
output_paths.append(os.path.join(args.output_dir, 'source.info'))
- md5_check.CallAndRecordIfStale(
- lambda: _PerformExtract(args.aar_file, args.output_dir, set(names)),
- input_paths=[args.aar_file],
- output_paths=output_paths)
+ if has_proguard_check_flags:
+ output_paths.append(os.path.join(args.output_dir, _PROGUARD_CHECKS_TXT))
+
+ def on_stale_md5():
+ _PerformExtract(args.aar_file, args.output_dir, set(names),
+ has_proguard_check_flags)
+
+ md5_check.CallAndRecordIfStale(on_stale_md5,
+ input_strings=[aar_info],
+ input_paths=[args.aar_file],
+ output_paths=output_paths)
elif args.command == 'list':
aar_output_present = args.output != '-' and os.path.isfile(args.output)