Commit bea04b15 authored by Eric Roman's avatar Eric Roman Committed by Commit Bot

Rewrite some proguard rules when building for cronet.

Bug: 1004516
Change-Id: I5c489ce94d9bea9d7b16fd8954008a28f7ddb8a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1808116Reviewed-by: default avatarRyan Hamilton <rch@chromium.org>
Commit-Queue: Eric Roman <eroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697402}
parent a449371f
......@@ -498,6 +498,9 @@ action("cronet_combine_proguard_flags") {
script = "//components/cronet/tools/generate_proguard_file.py"
sources = [
"//base/android/proguard/chromium_code.flags",
# Massage the proguard rules to work with AppReduce.
"//components/cronet/android/cronet_appreduce_workaround.patch",
"//components/cronet/android/cronet_impl_native_proguard.cfg",
]
outputs = [
......
This patchfile is a stop-gap solution to accomodate differences in syntax for
AppReduce, which is used internally in place of ProGuard. See crbug.com/1004516.
This patches base/android/proguard/chromium_code.flags.
It can be re-generated using these steps:
cd src
export ORIG_FLAGS="base/android/proguard/chromium_code.flags"
cp $ORIG_FLAGS modified.flags
$EDITOR modified.flags
diff -u "$ORIG_FLAGS" modified.flags > "components/cronet/android/cronet_appreduce_workaround.patch"
To test whether the patch applies cleanly use:
autoninja -C out/Release cronet_combine_proguard_flags
--- base/android/proguard/chromium_code.flags 2019-09-16 16:39:21.108477065 -0700
+++ modified.flags 2019-09-17 12:12:17.487606737 -0700
@@ -50,9 +50,12 @@
-assumenosideeffects class ** {
# Remove @RemovableInRelease methods so long as return values are unused.
@org.chromium.base.annotations.RemovableInRelease <methods>;
+}
+
+-assumevalues class ** {
# Remove object @RemovableInRelease methods even when return value is used.
- # Note: * in return type does not match primitives.
- @org.chromium.base.annotations.RemovableInRelease * *(...) return null;
+ # Note: ** in return type does not match primitives.
+ @org.chromium.base.annotations.RemovableInRelease ** *(...) return null;
# Remove boolean @RemovableInRelease methods even when return value is used.
@org.chromium.base.annotations.RemovableInRelease boolean *(...) return false;
}
......@@ -4,20 +4,42 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Tool that combines a sequence of input proguard files and outputs a single
# proguard file.
#
# The final output file is formed by concatenating all of the
# input proguard files, and then sequentally applying any .patch files that
# were given in the input.
#
# This tool requires the ability to shell execute the 'patch' tool, and is
# expected to only be run on Linux.
import optparse
import sys
import subprocess
def ReadFile(path):
with open(path, 'rb') as f:
return f.read()
def IsPatchFile(path):
return path.endswith('.patch')
# Combines files in |input_files| as one proguard file and write that to
# |output_file|
def GenerateProguardFile(output_file, input_files):
def ApplyPatch(output_file, patch_file):
try:
with open(output_file, "wb") as target:
for input_file in input_files:
f = open(input_file, "rb")
for line in f:
target.write(line)
except IOError:
raise Exception("Proguard file generation failed")
subprocess.check_call(['patch', '--quiet', output_file, patch_file])
except:
message = '''
Failed applying patch %s to %s
For help on fixing read the documentation in the patch file.
'''
sys.stderr.write(message % (patch_file, output_file))
raise
def main():
......@@ -26,7 +48,18 @@ def main():
help='Output file for the generated proguard file')
options, input_files = parser.parse_args()
GenerateProguardFile(options.output_file, input_files)
proguard_files = [path for path in input_files if not IsPatchFile(path)]
patch_files = [path for path in input_files if IsPatchFile(path)]
# Concatenate all the proguard files.
with open(options.output_file, 'wb') as target:
for input_file in proguard_files:
target.write(ReadFile(input_file))
# Apply any patch files.
for patch_file in patch_files:
ApplyPatch(options.output_file, patch_file)
if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment