| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 4 # for details. All rights reserved. Use of this source code is governed by a | 4 # for details. All rights reserved. Use of this source code is governed by a |
| 5 # BSD-style license that can be found in the LICENSE file. | 5 # BSD-style license that can be found in the LICENSE file. |
| 6 | 6 |
| 7 """Script to create snapshot bin file.""" | 7 """Script to create snapshot bin file.""" |
| 8 | 8 |
| 9 import getopt | 9 import getopt |
| 10 import optparse | 10 import optparse |
| 11 import os | 11 import os |
| 12 from os.path import basename, join | 12 from os.path import basename, join |
| 13 import sys | 13 import sys |
| 14 import utils | 14 import utils |
| 15 | 15 |
| 16 | 16 |
| 17 HOST_OS = utils.GuessOS() | 17 HOST_OS = utils.GuessOS() |
| 18 HOST_CPUS = utils.GuessCpus() | 18 HOST_CPUS = utils.GuessCpus() |
| 19 DEBUG = False | 19 DEBUG = False |
| 20 VERBOSE = False | 20 VERBOSE = False |
| 21 | 21 |
| 22 def BuildOptions(): | 22 def BuildOptions(): |
| 23 result = optparse.OptionParser() | 23 result = optparse.OptionParser() |
| 24 result.add_option("--executable", | 24 result.add_option("--executable", |
| 25 action="store", type="string", | 25 action="store", type="string", |
| 26 help="path to snapshot generator executable") | 26 help="path to snapshot generator executable") |
| 27 result.add_option("--vm_output_bin", |
| 28 action="store", type="string", |
| 29 help="output file name into which vm isolate snapshot in binary form " + |
| 30 "is generated") |
| 27 result.add_option("--output_bin", | 31 result.add_option("--output_bin", |
| 28 action="store", type="string", | 32 action="store", type="string", |
| 29 help="output file name into which snapshot in binary form is generated") | 33 help="output file name into which isolate snapshot in binary form " + |
| 34 "is generated") |
| 30 result.add_option("--script", | 35 result.add_option("--script", |
| 31 action="store", type="string", | 36 action="store", type="string", |
| 32 help="Dart script for which snapshot is to be generated") | 37 help="Dart script for which snapshot is to be generated") |
| 33 result.add_option("--package_root", | 38 result.add_option("--package_root", |
| 34 action="store", type="string", | 39 action="store", type="string", |
| 35 help="path used to resolve package: imports.") | 40 help="path used to resolve package: imports.") |
| 36 result.add_option("--url_mapping", | 41 result.add_option("--url_mapping", |
| 37 default=[], | 42 default=[], |
| 38 action="append", | 43 action="append", |
| 39 help=("mapping from url to file name, used when generating snapshots " + | 44 help=("mapping from url to file name, used when generating snapshots " + |
| 40 "E.g.: --url_mapping=fileUri,/path/to/file.dart")) | 45 "E.g.: --url_mapping=fileUri,/path/to/file.dart")) |
| 41 result.add_option("-v", "--verbose", | 46 result.add_option("-v", "--verbose", |
| 42 help='Verbose output.', | 47 help='Verbose output.', |
| 43 default=False, action="store_true") | 48 default=False, action="store_true") |
| 44 result.add_option("--target_os", | 49 result.add_option("--target_os", |
| 45 action="store", type="string", | 50 action="store", type="string", |
| 46 help="Which os to run the executable on. Current choice is android") | 51 help="Which os to run the executable on. Current choice is android") |
| 47 result.add_option("--abi", | 52 result.add_option("--abi", |
| 48 action="store", type="string", | 53 action="store", type="string", |
| 49 help="Desired ABI for android target OS. armeabi-v7a or x86") | 54 help="Desired ABI for android target OS. armeabi-v7a or x86") |
| 50 return result | 55 return result |
| 51 | 56 |
| 52 | 57 |
| 53 def ProcessOptions(options): | 58 def ProcessOptions(options): |
| 54 if not options.executable: | 59 if not options.executable: |
| 55 sys.stderr.write('--executable not specified\n') | 60 sys.stderr.write('--executable not specified\n') |
| 56 return False | 61 return False |
| 62 if not options.vm_output_bin: |
| 63 sys.stderr.write('--vm_output_bin not specified\n') |
| 64 return False |
| 57 if not options.output_bin: | 65 if not options.output_bin: |
| 58 sys.stderr.write('--output_bin not specified\n') | 66 sys.stderr.write('--output_bin not specified\n') |
| 59 return False | 67 return False |
| 60 if options.abi and not options.target_os == 'android': | 68 if options.abi and not options.target_os == 'android': |
| 61 sys.stderr.write('--abi requires --target_os android\n') | 69 sys.stderr.write('--abi requires --target_os android\n') |
| 62 return False | 70 return False |
| 63 return True | 71 return True |
| 64 | 72 |
| 65 | 73 |
| 66 def Main(): | 74 def Main(): |
| 67 # Parse options. | 75 # Parse options. |
| 68 parser = BuildOptions() | 76 parser = BuildOptions() |
| 69 (options, args) = parser.parse_args() | 77 (options, args) = parser.parse_args() |
| 70 if not ProcessOptions(options): | 78 if not ProcessOptions(options): |
| 71 parser.print_help() | 79 parser.print_help() |
| 72 return 1 | 80 return 1 |
| 73 | 81 |
| 74 # If there are additional arguments, report error and exit. | 82 # If there are additional arguments, report error and exit. |
| 75 if args: | 83 if args: |
| 76 parser.print_help() | 84 parser.print_help() |
| 77 return 1 | 85 return 1 |
| 78 | 86 |
| 79 # Setup arguments to the snapshot generator binary. | 87 # Setup arguments to the snapshot generator binary. |
| 80 script_args = ["--error_on_bad_type", "--error_on_bad_override"] | 88 script_args = ["--error_on_bad_type", "--error_on_bad_override"] |
| 81 | 89 |
| 82 # Pass along the package_root if there is one. | 90 # Pass along the package_root if there is one. |
| 83 if options.package_root: | 91 if options.package_root: |
| 84 script_args.append(''.join([ "--package_root=", options.package_root])) | 92 script_args.append(''.join([ "--package_root=", options.package_root])) |
| 85 | 93 |
| 86 # First setup the snapshot output filename. | 94 # First setup the vm isolate and regular isolate snapshot output filename. |
| 87 script_args.append(''.join([ "--snapshot=", options.output_bin ])) | 95 script_args.append(''.join([ "--vm_isolate_snapshot=", |
| 96 options.vm_output_bin ])) |
| 97 script_args.append(''.join([ "--isolate_snapshot=", options.output_bin ])) |
| 88 | 98 |
| 89 # Next setup all url mapping options specified. | 99 # Next setup all url mapping options specified. |
| 90 for url_arg in options.url_mapping: | 100 for url_arg in options.url_mapping: |
| 91 url_mapping_argument = ''.join(["--url_mapping=", url_arg ]) | 101 url_mapping_argument = ''.join(["--url_mapping=", url_arg ]) |
| 92 script_args.append(url_mapping_argument) | 102 script_args.append(url_mapping_argument) |
| 93 | 103 |
| 94 # Finally append the script name if one is specified. | 104 # Finally append the script name if one is specified. |
| 95 if options.script: | 105 if options.script: |
| 96 script_args.append(options.script) | 106 script_args.append(options.script) |
| 97 | 107 |
| 98 # Construct command line to execute the snapshot generator binary and invoke. | 108 # Construct command line to execute the snapshot generator binary and invoke. |
| 99 command = [ options.executable ] + script_args | 109 command = [ options.executable ] + script_args |
| 100 try: | 110 try: |
| 101 utils.RunCommand(command, outStream=sys.stderr, errStream=sys.stderr, | 111 utils.RunCommand(command, outStream=sys.stderr, errStream=sys.stderr, |
| 102 verbose=options.verbose, printErrorInfo=True) | 112 verbose=options.verbose, printErrorInfo=True) |
| 103 except Exception as e: | 113 except Exception as e: |
| 104 return -1 | 114 return -1 |
| 105 | 115 |
| 106 return 0 | 116 return 0 |
| 107 | 117 |
| 108 | 118 |
| 109 if __name__ == '__main__': | 119 if __name__ == '__main__': |
| 110 sys.exit(Main()) | 120 sys.exit(Main()) |
| OLD | NEW |