Support for force enabling/disabling shrinker options in run_on_app_dump.py
Change-Id: I35dca1c12b711e2183ac55cfb8b048d3c9a13126
diff --git a/tools/compiledump.py b/tools/compiledump.py
index 98c9489..a810cdc 100755
--- a/tools/compiledump.py
+++ b/tools/compiledump.py
@@ -38,6 +38,24 @@
help='Compiler to use',
default=None)
parser.add_argument(
+ '--minify',
+ help='Force enable/disable minification'
+ ' (defaults to app proguard config)',
+ choices=['default', 'force-enable', 'force-disable'],
+ default='default')
+ parser.add_argument(
+ '--optimize',
+ help='Force enable/disable optimizations'
+ ' (defaults to app proguard config)',
+ choices=['default', 'force-enable', 'force-disable'],
+ default='default')
+ parser.add_argument(
+ '--shrink',
+ help='Force enable/disable shrinking'
+ ' (defaults to app proguard config)',
+ choices=['default', 'force-enable', 'force-disable'],
+ default='default')
+ parser.add_argument(
'-v',
'--version',
help='Compiler version to use (default read from dump version file).'
@@ -281,17 +299,39 @@
return dest
-def clean_config(file):
+def clean_config(file, args):
with open(file) as f:
lines = f.readlines()
+ minify = args.minify
+ optimize = args.optimize
+ shrink = args.shrink
with open(file, 'w') as f:
+ if minify == 'force-disable':
+ print('Adding config line: -dontobfuscate')
+ f.write('-dontobfuscate\n')
+ if optimize == 'force-disable':
+ print('Adding config line: -dontoptimize')
+ f.write('-dontoptimize\n')
+ if shrink == 'force-disable':
+ print('Adding config line: -dontshrink')
+ f.write('-dontshrink\n')
for line in lines:
- if ('-injars' not in line and '-libraryjars' not in line and
- '-print' not in line):
- f.write(line)
- else:
+ if clean_config_line(line, minify, optimize, shrink):
print('Removing from config line: \n%s' % line)
+ else:
+ f.write(line)
+def clean_config_line(line, minify, optimize, shrink):
+ if ('-injars' in line or '-libraryjars' in line or
+ '-print' in line):
+ return True
+ if minify == 'force-enable' and '-dontobfuscate' in line:
+ return True
+ if optimize == 'force-enable' and '-dontoptimize' in line:
+ return True
+ if shrink == 'force-enable' and '-dontshrink' in line:
+ return True
+ return False
def prepare_wrapper(dist, temp, jdkhome):
wrapper_file = os.path.join(
@@ -376,7 +416,7 @@
else:
# If we get a dump from the wild we can't use -injars, -libraryjars or
# -print{mapping,usage}
- clean_config(dump.config_file())
+ clean_config(dump.config_file(), args)
cmd.extend(['--pg-conf', dump.config_file()])
if dump.main_dex_rules_resource():
cmd.extend(['--main-dex-rules', dump.main_dex_rules_resource()])
diff --git a/tools/run_on_app_dump.py b/tools/run_on_app_dump.py
index 6c25a4d..38bfa36 100755
--- a/tools/run_on_app_dump.py
+++ b/tools/run_on_app_dump.py
@@ -553,10 +553,13 @@
shrinker))
print('To compile locally: '
'tools/run_on_app_dump.py --shrinker {} --r8-compilation-steps {} '
- '--app {}'.format(
+ '--app {} --minify {} --optimize {} --shrink {}'.format(
shrinker,
options.r8_compilation_steps,
- app.name))
+ app.name,
+ options.minify,
+ options.optimize,
+ options.shrink))
print('HINT: use --shrinker r8-nolib --no-build if you have a local R8.jar')
recomp_jar = None
status = 'success'
@@ -652,6 +655,9 @@
def build_app_with_shrinker(app, options, temp_dir, app_dir, shrinker,
compilation_step_index, compilation_steps,
prev_recomp_jar):
+ def config_file_consumer(file):
+ compiledump.clean_config(file, options)
+ remove_print_lines(file)
args = AttrDict({
'dump': dump_for_app(app_dir, app),
'r8_jar': get_r8_jar(options, temp_dir, shrinker),
@@ -662,7 +668,7 @@
'debug_agent': options.debug_agent,
'program_jar': prev_recomp_jar,
'nolib': not is_minified_r8(shrinker),
- 'config_file_consumer': remove_print_lines,
+ 'config_file_consumer': config_file_consumer,
'properties': app.compiler_properties,
'disable_desugared_lib': False,
'print_times': options.print_times,
@@ -704,6 +710,7 @@
compilation_step_index, mapping):
def rewrite_file(file):
+ compiledump.clean_config(file, options)
remove_print_lines(file)
with open(file) as f:
lines = f.readlines()
@@ -723,7 +730,7 @@
'nolib': not is_minified_r8(shrinker),
# The config file will have an -applymapping reference to an old map.
# Update it to point to mapping file build in the compilation of the app.
- 'config_file_consumer': rewrite_file
+ 'config_file_consumer': rewrite_file,
})
test_jar = os.path.join(
@@ -894,6 +901,11 @@
result.add_argument('--keystore-password', '--keystore_password',
help='Password for app.keystore',
default='android')
+ result.add_argument('--minify',
+ help='Force enable/disable minification' +
+ ' (defaults to app proguard config)',
+ choices=['default', 'force-enable', 'force-disable'],
+ default='default')
result.add_argument('--monkey',
help='Whether to install and run app(s) with monkey',
default=False,
@@ -910,6 +922,11 @@
help='Disable logging except for errors',
default=False,
action='store_true')
+ result.add_argument('--optimize',
+ help='Force enable/disable optimizations' +
+ ' (defaults to app proguard config)',
+ choices=['default', 'force-enable', 'force-disable'],
+ default='default')
result.add_argument('--print-times',
help='Print timing information from r8',
default=False,
@@ -938,6 +955,11 @@
help='Whether to run instrumentation tests',
default=False,
action='store_true')
+ result.add_argument('--shrink',
+ help='Force enable/disable shrinking' +
+ ' (defaults to app proguard config)',
+ choices=['default', 'force-enable', 'force-disable'],
+ default='default')
result.add_argument('--sign-apks', '--sign_apks',
help='Whether the APKs should be signed',
default=False,