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 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 12 | |
Christoffer Quist Adamsen | a6f4798 | 2023-09-13 13:05:17 +0200 | [diff] [blame] | 13 | def ParseOptions(argv): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 14 | parser = optparse.OptionParser(usage='%prog [options] -- [R8 options]') |
| 15 | parser.add_option('-c', |
| 16 | '--commit-hash', |
| 17 | '--commit_hash', |
| 18 | help='Commit hash of R8 to use.', |
| 19 | default=None) |
| 20 | parser.add_option( |
| 21 | '--debug-agent', |
| 22 | help= |
| 23 | 'Enable Java debug agent and suspend compilation (default disabled)', |
| 24 | default=False, |
| 25 | action='store_true') |
Christoffer Adamsen | 3c6ab2e | 2024-11-25 20:33:40 +0100 | [diff] [blame] | 26 | parser.add_option('--disable-assertions', |
| 27 | '--disable_assertions', |
| 28 | help='Disable assertions when running', |
| 29 | default=False, |
| 30 | action='store_true') |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 31 | parser.add_option('--lib-android', |
| 32 | help='Add the android.jar for the given API level', |
| 33 | default=None, |
| 34 | type=int) |
| 35 | parser.add_option('--lib-rt', |
| 36 | help='Add rt.jar from openjdk-1.8', |
| 37 | default=False, |
| 38 | action='store_true') |
| 39 | parser.add_option('--no-build', |
| 40 | '--no_build', |
| 41 | help='Do not build R8', |
| 42 | default=False, |
| 43 | action='store_true') |
| 44 | parser.add_option('--print-runtimeraw', |
| 45 | '--print_runtimeraw', |
| 46 | metavar='BENCHMARKNAME', |
| 47 | help='Print the line \'<BENCHMARKNAME>(RunTimeRaw):' + |
| 48 | ' <elapsed> ms\' at the end where <elapsed> is' + |
| 49 | ' the elapsed time in milliseconds.') |
| 50 | parser.add_option('--tag', help='Tag of R8 to use.', default=None) |
| 51 | parser.add_option('--version', help='Version of R8 to use.', default=None) |
| 52 | return parser.parse_args(argv) |
| 53 | |
Christoffer Quist Adamsen | a6f4798 | 2023-09-13 13:05:17 +0200 | [diff] [blame] | 54 | |
| 55 | def main(argv): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 56 | (options, args) = ParseOptions(sys.argv) |
| 57 | r8_args = args[1:] |
| 58 | if options.lib_android: |
Søren Gjesse | 03fa116 | 2025-03-10 12:03:05 +0100 | [diff] [blame] | 59 | r8_args.extend(['--lib', utils.get_android_jar(options.lib_android, 0)]) |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 60 | if options.lib_rt: |
| 61 | r8_args.extend(['--lib', utils.RT_JAR]) |
| 62 | time_consumer = lambda duration: print_duration(duration, options) |
| 63 | return toolhelper.run('r8', |
| 64 | r8_args, |
| 65 | build=not options.no_build, |
Rico Wind | 2a90bde | 2024-11-26 07:59:20 +0100 | [diff] [blame] | 66 | disable_assertions=options.disable_assertions, |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 67 | debug_agent=options.debug_agent, |
| 68 | jar=utils.find_r8_jar_from_options(options), |
| 69 | main='com.android.tools.r8.R8', |
| 70 | time_consumer=time_consumer) |
| 71 | |
Christoffer Quist Adamsen | a6f4798 | 2023-09-13 13:05:17 +0200 | [diff] [blame] | 72 | |
| 73 | def print_duration(duration, options): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 74 | benchmark_name = options.print_runtimeraw |
| 75 | if benchmark_name: |
| 76 | print('%s-Total(RunTimeRaw): %s ms' % (benchmark_name, duration)) |
| 77 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 78 | |
| 79 | if __name__ == '__main__': |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 80 | sys.exit(main(sys.argv[1:])) |