OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2011, 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 files. | 7 # Script to create snapshot files. |
8 | 8 |
9 import getopt | 9 import getopt |
10 import optparse | 10 import optparse |
11 import string | 11 import string |
12 import subprocess | 12 import subprocess |
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 | 19 |
20 | 20 |
21 def BuildOptions(): | 21 def BuildOptions(): |
22 result = optparse.OptionParser() | 22 result = optparse.OptionParser() |
23 result.add_option("--executable", | 23 result.add_option("--input_bin", |
24 action="store", type="string", | 24 action="store", type="string", |
25 help="path to snapshot generator executable") | 25 help="input file name of the snapshot in binary form") |
26 result.add_option("--output_bin", | |
27 action="store", type="string", | |
28 help="output file name into which snapshot in binary form is generated") | |
29 result.add_option("--input_cc", | 26 result.add_option("--input_cc", |
30 action="store", type="string", | 27 action="store", type="string", |
31 help="input file name which contains the C buffer template") | 28 help="input file name which contains the C buffer template") |
32 result.add_option("--output", | 29 result.add_option("--output", |
33 action="store", type="string", | 30 action="store", type="string", |
34 help="output file name into which snapshot in C buffer form is generated") | 31 help="output file name into which snapshot in C buffer form is generated") |
35 result.add_option("--script", | |
36 action="store", type="string", | |
37 help="Dart script for which snapshot is to be generated") | |
38 result.add_option("--url_mapping", | |
39 default=[], | |
40 action="append", | |
41 help="mapping from url to file name, used when generating snapshots") | |
42 result.add_option("-v", "--verbose", | 32 result.add_option("-v", "--verbose", |
43 help='Verbose output.', | 33 help='Verbose output.', |
44 default=False, action="store_true") | 34 default=False, action="store_true") |
45 return result | 35 return result |
46 | 36 |
47 | 37 |
48 def ProcessOptions(options): | 38 def ProcessOptions(options): |
49 if not options.executable: | 39 if not options.input_bin: |
50 sys.stderr.write('--executable not specified\n') | 40 sys.stderr.write('--input_bin not specified\n') |
51 return False | |
52 if not options.output_bin: | |
53 sys.stderr.write('--output_bin not specified\n') | |
54 return False | 41 return False |
55 if not options.input_cc: | 42 if not options.input_cc: |
56 sys.stderr.write('--input_cc not specified\n') | 43 sys.stderr.write('--input_cc not specified\n') |
57 return False | 44 return False |
58 if not options.output: | 45 if not options.output: |
59 sys.stderr.write('--output not specified\n') | 46 sys.stderr.write('--output not specified\n') |
60 return False | 47 return False |
61 return True | 48 return True |
62 | 49 |
63 | 50 |
(...skipping 25 matching lines...) Expand all Loading... |
89 (options, args) = parser.parse_args() | 76 (options, args) = parser.parse_args() |
90 if not ProcessOptions(options): | 77 if not ProcessOptions(options): |
91 parser.print_help() | 78 parser.print_help() |
92 return 1 | 79 return 1 |
93 | 80 |
94 # If there are additional arguments, report error and exit. | 81 # If there are additional arguments, report error and exit. |
95 if args: | 82 if args: |
96 parser.print_help() | 83 parser.print_help() |
97 return 1 | 84 return 1 |
98 | 85 |
99 # Setup arguments to the snapshot generator binary. | 86 if not makeFile(options.output, options.input_cc, options.input_bin): |
100 script_args = [] | |
101 | |
102 # First setup the snapshot output filename. | |
103 script_args.append(''.join([ "--snapshot=", options.output_bin ])) | |
104 | |
105 # Next setup all url mapping options specified. | |
106 for url_arg in options.url_mapping: | |
107 url_mapping_argument = ''.join(["--url_mapping=", url_arg ]) | |
108 script_args.append(url_mapping_argument) | |
109 | |
110 # Finally append the script name if one is specified. | |
111 if options.script: | |
112 script_args.append(options.script) | |
113 | |
114 # Construct command line to execute the snapshot generator binary and invoke. | |
115 command = [ options.executable ] + script_args | |
116 if options.verbose: | |
117 print ' '.join(command) | |
118 pipe = subprocess.Popen(command, | |
119 stdout=subprocess.PIPE, | |
120 stderr=subprocess.PIPE) | |
121 out, error = pipe.communicate() | |
122 if (pipe.returncode != 0): | |
123 print out, error | |
124 print "Snapshot generation failed" | |
125 print "(Command was: '", ' '.join(command), "')" | |
126 return -1 | |
127 | |
128 if not makeFile(options.output, options.input_cc, options.output_bin): | |
129 print "Unable to generate snapshot in C buffer form" | 87 print "Unable to generate snapshot in C buffer form" |
130 return -1 | 88 return -1 |
131 | 89 |
132 return 0 | 90 return 0 |
133 | 91 |
134 if __name__ == '__main__': | 92 if __name__ == '__main__': |
135 sys.exit(Main()) | 93 sys.exit(Main()) |
OLD | NEW |