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("--vm_input_bin", |
| 24 action="store", type="string", |
| 25 help="input file name of the vm isolate snapshot in binary form") |
23 result.add_option("--input_bin", | 26 result.add_option("--input_bin", |
24 action="store", type="string", | 27 action="store", type="string", |
25 help="input file name of the snapshot in binary form") | 28 help="input file name of the isolate snapshot in binary form") |
26 result.add_option("--input_cc", | 29 result.add_option("--input_cc", |
27 action="store", type="string", | 30 action="store", type="string", |
28 help="input file name which contains the C buffer template") | 31 help="input file name which contains the C buffer template") |
29 result.add_option("--output", | 32 result.add_option("--output", |
30 action="store", type="string", | 33 action="store", type="string", |
31 help="output file name into which snapshot in C buffer form is generated") | 34 help="output file name into which snapshot in C buffer form is generated") |
32 result.add_option("-v", "--verbose", | 35 result.add_option("-v", "--verbose", |
33 help='Verbose output.', | 36 help='Verbose output.', |
34 default=False, action="store_true") | 37 default=False, action="store_true") |
35 return result | 38 return result |
36 | 39 |
37 | 40 |
38 def ProcessOptions(options): | 41 def ProcessOptions(options): |
| 42 if not options.vm_input_bin: |
| 43 sys.stderr.write('--vm_input_bin not specified\n') |
| 44 return False |
39 if not options.input_bin: | 45 if not options.input_bin: |
40 sys.stderr.write('--input_bin not specified\n') | 46 sys.stderr.write('--input_bin not specified\n') |
41 return False | 47 return False |
42 if not options.input_cc: | 48 if not options.input_cc: |
43 sys.stderr.write('--input_cc not specified\n') | 49 sys.stderr.write('--input_cc not specified\n') |
44 return False | 50 return False |
45 if not options.output: | 51 if not options.output: |
46 sys.stderr.write('--output not specified\n') | 52 sys.stderr.write('--output not specified\n') |
47 return False | 53 return False |
48 return True | 54 return True |
49 | 55 |
50 | 56 |
51 def makeString(input_file): | 57 def makeString(input_file): |
52 result = ' ' | 58 result = ' ' |
53 fileHandle = open(input_file, 'rb') | 59 fileHandle = open(input_file, 'rb') |
54 lineCounter = 0 | 60 lineCounter = 0 |
55 for byte in fileHandle.read(): | 61 for byte in fileHandle.read(): |
56 result += ' %d,' % ord(byte) | 62 result += ' %d,' % ord(byte) |
57 lineCounter += 1 | 63 lineCounter += 1 |
58 if lineCounter == 10: | 64 if lineCounter == 10: |
59 result += '\n ' | 65 result += '\n ' |
60 lineCounter = 0 | 66 lineCounter = 0 |
61 if lineCounter != 0: | 67 if lineCounter != 0: |
62 result += '\n ' | 68 result += '\n ' |
63 return result | 69 return result |
64 | 70 |
65 | 71 |
66 def makeFile(output_file, input_cc_file, input_file): | 72 def makeFile(output_file, input_cc_file, |
| 73 vm_isolate_input_file, isolate_input_file): |
67 snapshot_cc_text = open(input_cc_file).read() | 74 snapshot_cc_text = open(input_cc_file).read() |
68 snapshot_cc_text = snapshot_cc_text % makeString(input_file) | 75 snapshot_cc_text = snapshot_cc_text % (makeString(vm_isolate_input_file), |
| 76 makeString(isolate_input_file)) |
69 open(output_file, 'w').write(snapshot_cc_text) | 77 open(output_file, 'w').write(snapshot_cc_text) |
70 return True | 78 return True |
71 | 79 |
72 | 80 |
73 def Main(): | 81 def Main(): |
74 # Parse options. | 82 # Parse options. |
75 parser = BuildOptions() | 83 parser = BuildOptions() |
76 (options, args) = parser.parse_args() | 84 (options, args) = parser.parse_args() |
77 if not ProcessOptions(options): | 85 if not ProcessOptions(options): |
78 parser.print_help() | 86 parser.print_help() |
79 return 1 | 87 return 1 |
80 | 88 |
81 # If there are additional arguments, report error and exit. | 89 # If there are additional arguments, report error and exit. |
82 if args: | 90 if args: |
83 parser.print_help() | 91 parser.print_help() |
84 return 1 | 92 return 1 |
85 | 93 |
86 if not makeFile(options.output, options.input_cc, options.input_bin): | 94 if not makeFile(options.output, options.input_cc, |
| 95 options.vm_input_bin, options.input_bin): |
87 print "Unable to generate snapshot in C buffer form" | 96 print "Unable to generate snapshot in C buffer form" |
88 return -1 | 97 return -1 |
89 | 98 |
90 return 0 | 99 return 0 |
91 | 100 |
92 if __name__ == '__main__': | 101 if __name__ == '__main__': |
93 sys.exit(Main()) | 102 sys.exit(Main()) |
OLD | NEW |