blob: 84dd1a2330e6a167c52e3acffbe1dee8ce4d4b9e [file] [log] [blame]
#!/usr/bin/env python
# Copyright (c) 2018, the R8 project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
Build r8lib.jar with both R8 and ProGuard and print a size comparison.
By default, inlining is disabled in both R8 and ProGuard to make
method-by-method comparison much easier. Pass --inlining to enable inlining.
By default, only shows methods where R8's DEX output is 5 or more instructions
larger than ProGuard+D8's output. Pass --threshold 0 to display all methods.
import argparse
import build_r8lib
import os
import subprocess
import toolhelper
import utils
parser = argparse.ArgumentParser(description=__doc__.strip(),
parser.add_argument('-t', '--tmpdir',
help='Store auxiliary files in given directory')
parser.add_argument('-i', '--inlining', action='store_true',
help='Enable inlining')
('', ''),
('', ''),
('', ''),
('joptsimple', ''),
('org.apache.commons', ''),
('org.objectweb.asm', ''),
('it.unimi.dsi.fastutil', ''),
def is_output_newer(input, output):
if not os.path.exists(output):
return False
return os.stat(input).st_mtime < os.stat(output).st_mtime
def check_call(args, **kwargs):
return subprocess.check_call(args, **kwargs)
def main(tmpdir=None, inlining=True,
run_jarsizecompare=True, threshold=None):
if tmpdir is None:
with utils.TempDir() as tmpdir:
return main(tmpdir, inlining)
inline_suffix = '-inline' if inlining else '-noinline'
pg_config = utils.R8LIB_KEEP_RULES
r8lib_jar = os.path.join(utils.LIBS, 'r8lib%s.jar' % inline_suffix)
r8lib_map = os.path.join(utils.LIBS, 'r8lib%s-map.txt' % inline_suffix)
r8lib_args = None
if not inlining:
r8lib_args = ['']
pg_config = os.path.join(tmpdir, 'keep-noinline.txt')
with open(pg_config, 'w') as new_config:
with open(utils.R8LIB_KEEP_RULES) as old_config:
new_config.write('\n') +
'\n-optimizations !method/inlining/*\n')
if not is_output_newer(utils.R8_JAR, r8lib_jar):
r8lib_memory = os.path.join(tmpdir, 'r8lib%s-memory.txt' % inline_suffix)
output_path=r8lib_jar, output_map=r8lib_map,
extra_args=r8lib_args, track_memory_file=r8lib_memory)
pg_output = os.path.join(tmpdir, 'r8lib-pg%s.jar' % inline_suffix)
pg_memory = os.path.join(tmpdir, 'r8lib-pg%s-memory.txt' % inline_suffix)
pg_map = os.path.join(tmpdir, 'r8lib-pg%s-map.txt' % inline_suffix)
pg_args = ['tools/', pg_memory,
'@' + pg_config,
'-lib', utils.RT_JAR,
'-injar', utils.R8_JAR,
'-printmapping', pg_map,
'-outjar', pg_output]
for library_name, relocated_package in R8_RELOCATIONS:
pg_args.extend(['-dontwarn', relocated_package + '.**',
'-dontnote', relocated_package + '.**'])
if threshold is None:
threshold = 5'jarsizecompare',
['--threshold', str(threshold),
'--lib', utils.RT_JAR,
'--input', 'input', utils.R8_JAR,
'--input', 'r8', r8lib_jar, r8lib_map,
'--input', 'pg', pg_output, pg_map])
if __name__ == '__main__':