Ian Zerny | dcb172e | 2022-02-22 15:36:45 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 2 | # Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file |
| 3 | # for details. All rights reserved. Use of this source code is governed by a |
| 4 | # BSD-style license that can be found in the LICENSE file. |
| 5 | |
Christoffer Quist Adamsen | a6f4798 | 2023-09-13 13:05:17 +0200 | [diff] [blame] | 6 | import optparse |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 7 | import sys |
Christoffer Quist Adamsen | a6f4798 | 2023-09-13 13:05:17 +0200 | [diff] [blame] | 8 | |
Mathias Rav | dd6a6de | 2018-05-18 10:18:33 +0200 | [diff] [blame] | 9 | import toolhelper |
Christoffer Quist Adamsen | a6f4798 | 2023-09-13 13:05:17 +0200 | [diff] [blame] | 10 | import utils |
| 11 | |
| 12 | def ParseOptions(argv): |
| 13 | parser = optparse.OptionParser(usage='%prog [options] -- [R8 options]') |
| 14 | parser.add_option( |
| 15 | '-c', |
| 16 | '--commit-hash', |
| 17 | '--commit_hash', |
| 18 | help='Commit hash of R8 to use.', |
| 19 | default=None) |
| 20 | parser.add_argument( |
| 21 | '--debug-agent', |
| 22 | help='Enable Java debug agent and suspend compilation (default disabled)', |
| 23 | default=False, |
| 24 | action='store_true') |
| 25 | parser.add_option( |
| 26 | '--ea', |
| 27 | help='Enable Java assertions when running the compiler (default disabled)', |
| 28 | default=False, |
| 29 | action='store_true') |
| 30 | parser.add_option( |
| 31 | '--lib-android', |
| 32 | help='Add the android.jar for the given API level', |
| 33 | default=None, |
| 34 | type=int) |
| 35 | parser.add_option( |
| 36 | '--lib-rt', |
| 37 | help='Add rt.jar from openjdk-1.8', |
| 38 | default=False, |
| 39 | action='store_true') |
| 40 | parser.add_option( |
| 41 | '--no-build', '--no_build', |
| 42 | help='Do not build R8', |
| 43 | default=False, |
| 44 | action='store_true') |
| 45 | parser.add_option( |
| 46 | '--print-runtimeraw', '--print_runtimeraw', |
| 47 | metavar='BENCHMARKNAME', |
| 48 | help='Print the line \'<BENCHMARKNAME>(RunTimeRaw):' + |
| 49 | ' <elapsed> ms\' at the end where <elapsed> is' + |
| 50 | ' the elapsed time in milliseconds.') |
| 51 | parser.add_option( |
| 52 | '--tag', |
| 53 | help='Tag of R8 to use.', |
| 54 | default=None) |
| 55 | parser.add_option( |
| 56 | '--version', |
| 57 | help='Version of R8 to use.', |
| 58 | default=None) |
| 59 | return parser.parse_args(argv) |
| 60 | |
| 61 | def main(argv): |
| 62 | (options, args) = ParseOptions(sys.argv) |
| 63 | r8_args = args[1:] |
| 64 | if options.lib_android: |
| 65 | r8_args.extend(['--lib', utils.get_android_jar(options.lib_android)]) |
| 66 | if options.lib_rt: |
| 67 | r8_args.extend(['--lib', utils.RT_JAR]) |
| 68 | time_consumer = lambda duration : print_duration(duration, options) |
| 69 | return toolhelper.run( |
| 70 | 'r8', |
| 71 | r8_args, |
| 72 | build=not options.no_build, |
| 73 | debug=options.ea, |
| 74 | debug_agent=options.debug_agent, |
| 75 | jar=utils.find_r8_jar_from_options(options), |
| 76 | main='com.android.tools.r8.R8', |
| 77 | time_consumer=time_consumer) |
| 78 | |
| 79 | def print_duration(duration, options): |
| 80 | benchmark_name = options.print_runtimeraw |
| 81 | if benchmark_name: |
| 82 | print('%s-Total(RunTimeRaw): %s ms' % (benchmark_name, duration)) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 83 | |
| 84 | if __name__ == '__main__': |
Christoffer Quist Adamsen | a6f4798 | 2023-09-13 13:05:17 +0200 | [diff] [blame] | 85 | sys.exit(main(sys.argv[1:])) |