| 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 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 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("--output_bin", | 27 result.add_option("--output_bin", |
| 28 action="store", type="string", | 28 action="store", type="string", |
| 29 help="output file name into which snapshot in binary form is generated") | 29 help="output file name into which snapshot in binary form is generated") |
| 30 result.add_option("--script", | 30 result.add_option("--script", |
| 31 action="store", type="string", | 31 action="store", type="string", |
| 32 help="Dart script for which snapshot is to be generated") | 32 help="Dart script for which snapshot is to be generated") |
| 33 result.add_option("--package_root", |
| 34 action="store", type="string", |
| 35 help="path used to resolve package: imports.") |
| 33 result.add_option("--url_mapping", | 36 result.add_option("--url_mapping", |
| 34 default=[], | 37 default=[], |
| 35 action="append", | 38 action="append", |
| 36 help="mapping from url to file name, used when generating snapshots") | 39 help="mapping from url to file name, used when generating snapshots") |
| 37 result.add_option("-v", "--verbose", | 40 result.add_option("-v", "--verbose", |
| 38 help='Verbose output.', | 41 help='Verbose output.', |
| 39 default=False, action="store_true") | 42 default=False, action="store_true") |
| 40 result.add_option("--target_os", | 43 result.add_option("--target_os", |
| 41 action="store", type="string", | 44 action="store", type="string", |
| 42 help="Which os to run the executable on. Current choice is android") | 45 help="Which os to run the executable on. Current choice is android") |
| (...skipping 25 matching lines...) Expand all Loading... |
| 68 return 1 | 71 return 1 |
| 69 | 72 |
| 70 # If there are additional arguments, report error and exit. | 73 # If there are additional arguments, report error and exit. |
| 71 if args: | 74 if args: |
| 72 parser.print_help() | 75 parser.print_help() |
| 73 return 1 | 76 return 1 |
| 74 | 77 |
| 75 # Setup arguments to the snapshot generator binary. | 78 # Setup arguments to the snapshot generator binary. |
| 76 script_args = ["--error_on_bad_type", "--error_on_bad_override"] | 79 script_args = ["--error_on_bad_type", "--error_on_bad_override"] |
| 77 | 80 |
| 81 # Pass along the package_root if there is one. |
| 82 if options.package_root: |
| 83 script_args.append(''.join([ "--package_root=", options.package_root])) |
| 84 |
| 78 # First setup the snapshot output filename. | 85 # First setup the snapshot output filename. |
| 79 script_args.append(''.join([ "--snapshot=", options.output_bin ])) | 86 script_args.append(''.join([ "--snapshot=", options.output_bin ])) |
| 80 | 87 |
| 81 # Next setup all url mapping options specified. | 88 # Next setup all url mapping options specified. |
| 82 for url_arg in options.url_mapping: | 89 for url_arg in options.url_mapping: |
| 83 url_mapping_argument = ''.join(["--url_mapping=", url_arg ]) | 90 url_mapping_argument = ''.join(["--url_mapping=", url_arg ]) |
| 84 script_args.append(url_mapping_argument) | 91 script_args.append(url_mapping_argument) |
| 85 | 92 |
| 86 # Finally append the script name if one is specified. | 93 # Finally append the script name if one is specified. |
| 87 if options.script: | 94 if options.script: |
| 88 script_args.append(options.script) | 95 script_args.append(options.script) |
| 89 | 96 |
| 90 # Construct command line to execute the snapshot generator binary and invoke. | 97 # Construct command line to execute the snapshot generator binary and invoke. |
| 91 command = [ options.executable ] + script_args | 98 command = [ options.executable ] + script_args |
| 92 try: | 99 try: |
| 93 utils.RunCommand(command, outStream=sys.stderr, errStream=sys.stderr, | 100 utils.RunCommand(command, outStream=sys.stderr, errStream=sys.stderr, |
| 94 verbose=options.verbose, printErrorInfo=True) | 101 verbose=options.verbose, printErrorInfo=True) |
| 95 except Exception as e: | 102 except Exception as e: |
| 96 return -1 | 103 return -1 |
| 97 | 104 |
| 98 return 0 | 105 return 0 |
| 99 | 106 |
| 100 | 107 |
| 101 if __name__ == '__main__': | 108 if __name__ == '__main__': |
| 102 sys.exit(Main()) | 109 sys.exit(Main()) |
| OLD | NEW |