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 6import d8 7import gmscore_data 8import optparse 9import os 10import sys 11 12def 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', 28 choices = ['v9', 'v10']) 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 49def 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 61 if options.d8_flags: 62 args.extend(options.d8_flags.split(' ')) 63 64 args.extend(inputs) 65 66 if options.dump_args_file: 67 with open(options.dump_args_file, 'w') as args_file: 68 args_file.writelines([arg + os.linesep for arg in args]) 69 else: 70 d8.run(args, not options.no_build, not options.no_debug, options.profile, 71 options.track_memory_to_file) 72 73if __name__ == '__main__': 74 sys.exit(main()) 75