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() | |
18 HOST_CPUS = utils.GuessCpus() | |
19 DEBUG = False | |
20 VERBOSE = False | |
21 | |
22 def BuildOptions(): | 17 def BuildOptions(): |
23 result = optparse.OptionParser() | 18 result = optparse.OptionParser() |
24 result.add_option("--executable", | 19 result.add_option("--executable", |
25 action="store", type="string", | 20 action="store", type="string", |
26 help="path to snapshot generator executable") | 21 help="path to snapshot generator executable") |
27 result.add_option("--snapshot_kind", | 22 result.add_option("--snapshot_kind", |
28 action="store", type="string", | 23 action="store", type="string", |
29 help="kind of snapshot to generate", | 24 help="kind of snapshot to generate", |
30 default="core") | 25 default="core") |
31 result.add_option("--vm_output_bin", | 26 result.add_option("--vm_output_bin", |
32 action="store", type="string", | 27 action="store", type="string", |
33 help="output file name into which vm isolate snapshot in binary form " + | 28 help="output file name into which vm isolate snapshot in binary form " + |
34 "is generated") | 29 "is generated") |
| 30 result.add_option("--vm_instructions_output_bin", |
| 31 action="store", type="string", |
| 32 help="output file name into which vm isolate snapshot in binary form " + |
| 33 "is generated") |
35 result.add_option("--isolate_output_bin", | 34 result.add_option("--isolate_output_bin", |
36 action="store", type="string", | 35 action="store", type="string", |
37 help="output file name into which isolate snapshot in binary form " + | 36 help="output file name into which isolate snapshot in binary form " + |
38 "is generated") | 37 "is generated") |
| 38 result.add_option("--isolate_instructions_output_bin", |
| 39 action="store", type="string", |
| 40 help="output file name into which isolate snapshot in binary form " + |
| 41 "is generated") |
39 result.add_option("--embedder_entry_points_manifest", | 42 result.add_option("--embedder_entry_points_manifest", |
40 action="store", type="string", | 43 action="store", type="string", |
41 help="input manifest with the vm entry points in a precompiled snapshot") | 44 help="input manifest with the vm entry points in a precompiled snapshot") |
42 result.add_option("--script", | 45 result.add_option("--script", |
43 action="store", type="string", | 46 action="store", type="string", |
44 help="Dart script for which snapshot is to be generated") | 47 help="Dart script for which snapshot is to be generated") |
45 result.add_option("--package_root", | 48 result.add_option("--package_root", |
46 action="store", type="string", | 49 action="store", type="string", |
47 help="path used to resolve package: imports.") | 50 help="path used to resolve package: imports.") |
48 result.add_option("--packages", | 51 result.add_option("--packages", |
49 action="store", type="string", | 52 action="store", type="string", |
50 help="package config file used to reasolve package: imports.") | 53 help="package config file used to reasolve package: imports.") |
51 result.add_option("--url_mapping", | 54 result.add_option("--url_mapping", |
52 default=[], | 55 default=[], |
53 action="append", | 56 action="append", |
54 help=("mapping from url to file name, used when generating snapshots " + | 57 help=("mapping from url to file name, used when generating snapshots " + |
55 "E.g.: --url_mapping=fileUri,/path/to/file.dart")) | 58 "E.g.: --url_mapping=fileUri,/path/to/file.dart")) |
56 result.add_option("-v", "--verbose", | 59 result.add_option("-v", "--verbose", |
57 help='Verbose output.', | 60 help='Verbose output.', |
58 default=False, action="store_true") | 61 default=False, action="store_true") |
59 result.add_option("--target_os", | |
60 action="store", type="string", | |
61 help="Which os to run the executable on. Current choice is android") | |
62 result.add_option("--abi", | |
63 action="store", type="string", | |
64 help="Desired ABI for android target OS. armeabi-v7a or x86") | |
65 result.add_option("--timestamp_file", | 62 result.add_option("--timestamp_file", |
66 action="store", type="string", | 63 action="store", type="string", |
67 help="Path to timestamp file that will be written", | 64 help="Path to timestamp file that will be written", |
68 default="") | 65 default="") |
69 return result | 66 return result |
70 | 67 |
71 | 68 |
72 def ProcessOptions(options): | 69 def ProcessOptions(options): |
73 if not options.executable: | 70 if not options.executable: |
74 sys.stderr.write('--executable not specified\n') | 71 sys.stderr.write('--executable not specified\n') |
75 return False | 72 return False |
76 if not options.snapshot_kind: | 73 if not options.snapshot_kind: |
77 sys.stderr.write('--snapshot_kind not specified\n') | 74 sys.stderr.write('--snapshot_kind not specified\n') |
78 return False | 75 return False |
79 if not options.vm_output_bin: | 76 if not options.vm_output_bin: |
80 sys.stderr.write('--vm_output_bin not specified\n') | 77 sys.stderr.write('--vm_output_bin not specified\n') |
81 return False | 78 return False |
82 if not options.isolate_output_bin: | 79 if not options.isolate_output_bin: |
83 sys.stderr.write('--isolate_output_bin not specified\n') | 80 sys.stderr.write('--isolate_output_bin not specified\n') |
84 return False | 81 return False |
85 if options.abi and not options.target_os == 'android': | 82 if (options.snapshot_kind == 'core-jit' |
86 sys.stderr.write('--abi requires --target_os android\n') | 83 and not options.vm_instructions_output_bin): |
| 84 sys.stderr.write('--vm_instructions_output_bin not specified\n') |
| 85 return False |
| 86 if (options.snapshot_kind == 'core-jit' |
| 87 and not options.isolate_instructions_output_bin): |
| 88 sys.stderr.write('--isolate_instructions_output_bin not specified\n') |
87 return False | 89 return False |
88 return True | 90 return True |
89 | 91 |
90 | 92 |
91 def CreateTimestampFile(options): | 93 def CreateTimestampFile(options): |
92 if options.timestamp_file != '': | 94 if options.timestamp_file != '': |
93 dir_name = os.path.dirname(options.timestamp_file) | 95 dir_name = os.path.dirname(options.timestamp_file) |
94 if not os.path.exists(dir_name): | 96 if not os.path.exists(dir_name): |
95 os.mkdir(dir_name) | 97 os.mkdir(dir_name) |
96 open(options.timestamp_file, 'w').close() | 98 open(options.timestamp_file, 'w').close() |
97 | 99 |
98 | 100 |
99 def Main(): | 101 def Main(): |
100 # Parse options. | 102 # Parse options. |
101 parser = BuildOptions() | 103 parser = BuildOptions() |
102 (options, args) = parser.parse_args() | 104 (options, args) = parser.parse_args() |
103 if not ProcessOptions(options): | 105 if not ProcessOptions(options): |
104 parser.print_help() | 106 parser.print_help() |
105 return 1 | 107 return 1 |
106 | 108 |
107 # If there are additional arguments, report error and exit. | 109 # If there are additional arguments, report error and exit. |
108 if args: | 110 if args: |
109 parser.print_help() | 111 parser.print_help() |
110 return 1 | 112 return 1 |
111 | 113 |
112 # Setup arguments to the snapshot generator binary. | 114 # Setup arguments to the snapshot generator binary. |
113 script_args = ["--ignore_unrecognized_flags", | 115 script_args = ["--ignore_unrecognized_flags" ] |
114 "--error_on_bad_type", | |
115 "--error_on_bad_override"] | |
116 | 116 |
117 # Pass along the package_root if there is one. | 117 # Pass along the package_root if there is one. |
118 if options.package_root: | 118 if options.package_root: |
119 script_args.append(''.join([ "--package_root=", options.package_root])) | 119 script_args.append(''.join([ "--package_root=", options.package_root])) |
120 | 120 |
121 # Pass along the packages if there is one. | 121 # Pass along the packages if there is one. |
122 if options.packages: | 122 if options.packages: |
123 script_args.append(''.join([ "--packages=", options.packages])) | 123 script_args.append(''.join([ "--packages=", options.packages])) |
124 | 124 |
125 # First setup the vm isolate and regular isolate snapshot output filename. | 125 # First setup the vm isolate and regular isolate snapshot output filename. |
126 script_args.append(''.join([ "--snapshot_kind=", options.snapshot_kind ])) | 126 script_args.append(''.join([ "--snapshot_kind=", options.snapshot_kind ])) |
127 script_args.append(''.join([ "--vm_snapshot_data=", options.vm_output_bin ])) | 127 script_args.append(''.join([ "--vm_snapshot_data=", options.vm_output_bin ])) |
128 script_args.append(''.join([ "--isolate_snapshot_data=", options.isolate_outpu
t_bin ])) | 128 script_args.append(''.join([ "--isolate_snapshot_data=", options.isolate_outpu
t_bin ])) |
129 | 129 |
| 130 if options.vm_instructions_output_bin != None: |
| 131 script_args.append(''.join([ "--vm_snapshot_instructions=", |
| 132 options.vm_instructions_output_bin ])) |
| 133 if options.isolate_instructions_output_bin != None: |
| 134 script_args.append(''.join([ "--isolate_snapshot_instructions=", |
| 135 options.isolate_instructions_output_bin ])) |
| 136 |
130 # Specify the embedder entry points snapshot | 137 # Specify the embedder entry points snapshot |
131 if options.embedder_entry_points_manifest: | 138 if options.embedder_entry_points_manifest: |
132 script_args.append(''.join([ "--embedder_entry_points_manifest=", | 139 script_args.append(''.join([ "--embedder_entry_points_manifest=", |
133 options.embedder_entry_points_manifest ])) | 140 options.embedder_entry_points_manifest ])) |
134 | 141 |
135 # Next setup all url mapping options specified. | 142 # Next setup all url mapping options specified. |
136 for url_arg in options.url_mapping: | 143 for url_arg in options.url_mapping: |
137 url_mapping_argument = ''.join(["--url_mapping=", url_arg ]) | 144 url_mapping_argument = ''.join(["--url_mapping=", url_arg ]) |
138 script_args.append(url_mapping_argument) | 145 script_args.append(url_mapping_argument) |
139 | 146 |
(...skipping 10 matching lines...) Expand all Loading... |
150 return -1 | 157 return -1 |
151 | 158 |
152 # Success, update timestamp file. | 159 # Success, update timestamp file. |
153 CreateTimestampFile(options) | 160 CreateTimestampFile(options) |
154 | 161 |
155 return 0 | 162 return 0 |
156 | 163 |
157 | 164 |
158 if __name__ == '__main__': | 165 if __name__ == '__main__': |
159 sys.exit(Main()) | 166 sys.exit(Main()) |
OLD | NEW |