Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 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 | |
| 6 | import d8 |
| 7 | import gmscore_data |
| 8 | import optparse |
| 9 | import os |
| 10 | import sys |
| 11 | |
| 12 | def ParseOptions(): |
| 13 | result = optparse.OptionParser() |
| 14 | result.add_option('--out', |
| 15 | help = '', |
| 16 | default = os.getcwd()) |
| 17 | result.add_option('--no-build', |
| 18 | help = '', |
| 19 | default = False, |
| 20 | action = 'store_true') |
| 21 | result.add_option('--no-debug', |
| 22 | help = 'Run without debug asserts.', |
| 23 | default = False, |
| 24 | action = 'store_true') |
| 25 | result.add_option('--version', |
| 26 | help = '', |
| 27 | default = 'v9', |
Tamas Kenez | 228870b | 2017-08-23 13:53:22 +0200 | [diff] [blame] | 28 | choices = ['v9', 'v10', 'latest']) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 29 | result.add_option('--type', |
| 30 | help = '', |
| 31 | default = 'proguarded', |
| 32 | choices = ['proguarded', 'deploy']) |
| 33 | result.add_option('--d8-flags', |
| 34 | help = 'Additional option(s) for D8. ' + |
| 35 | 'If passing several options use a quoted string.') |
| 36 | result.add_option('--track-memory-to-file', |
| 37 | help = 'Track how much memory the jvm is using while ' + |
| 38 | ' compiling. Output to the specified file.') |
| 39 | result.add_option('--profile', |
| 40 | help = 'Profile D8 run.', |
| 41 | default = False, |
| 42 | action = 'store_true') |
| 43 | result.add_option('--dump-args-file', |
| 44 | help = 'Dump a file with the arguments for the specified ' + |
| 45 | 'configuration. For use as a @<file> argument to perform ' + |
| 46 | 'the run.') |
| 47 | return result.parse_args() |
| 48 | |
| 49 | def main(): |
| 50 | (options, args) = ParseOptions() |
| 51 | outdir = options.out |
| 52 | version = gmscore_data.VERSIONS[options.version] |
| 53 | values = version[options.type] |
| 54 | inputs = values['inputs'] |
| 55 | |
| 56 | args.extend(['--output', outdir]) |
| 57 | |
| 58 | if not os.path.exists(outdir): |
| 59 | os.makedirs(outdir) |
| 60 | |
Lars Bak | 9bee2d8 | 2017-08-23 11:00:04 +0200 | [diff] [blame] | 61 | if 'main-dex-list' in values: |
| 62 | args.extend(['--main-dex-list', values['main-dex-list']]) |
| 63 | |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 64 | if options.d8_flags: |
| 65 | args.extend(options.d8_flags.split(' ')) |
| 66 | |
| 67 | args.extend(inputs) |
| 68 | |
| 69 | if options.dump_args_file: |
| 70 | with open(options.dump_args_file, 'w') as args_file: |
| 71 | args_file.writelines([arg + os.linesep for arg in args]) |
| 72 | else: |
| 73 | d8.run(args, not options.no_build, not options.no_debug, options.profile, |
| 74 | options.track_memory_to_file) |
| 75 | |
| 76 | if __name__ == '__main__': |
| 77 | sys.exit(main()) |