Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: tools/create_snapshot_file.py

Issue 8439061: Support command line parameters to specify a url to file name mapping. This is used during snapsh... (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « bin/run_vm_tests.cc ('k') | vm/dart.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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("--executable",
24 action="store", type="string", 24 action="store", type="string",
25 help="path to executable") 25 help="path to snapshot generator executable")
26 result.add_option("--output_bin", 26 result.add_option("--output_bin",
27 action="store", type="string", 27 action="store", type="string",
28 help="binary snapshot output file name") 28 help="output file name into which snapshot in binary form is generated")
29 result.add_option("--input_cc", 29 result.add_option("--input_cc",
30 action="store", type="string", 30 action="store", type="string",
31 help="input template file name") 31 help="input file name which contains the C buffer template")
32 result.add_option("--output", 32 result.add_option("--output",
33 action="store", type="string", 33 action="store", type="string",
34 help="generated snapshot output file name") 34 help="output file name into which snapshot in C buffer form is generated")
35 result.add_option("--scripts", 35 result.add_option("--script",
36 action="store", type="string", 36 action="store", type="string",
37 help="list of scripts to include in snapshot") 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")
38 result.add_option("-v", "--verbose", 42 result.add_option("-v", "--verbose",
39 help='Verbose output.', 43 help='Verbose output.',
40 default=False, action="store_true") 44 default=False, action="store_true")
41 return result 45 return result
42 46
43 47
44 def ProcessOptions(options): 48 def ProcessOptions(options):
45 if not options.executable: 49 if not options.executable:
46 sys.stderr.write('--executable not specified\n') 50 sys.stderr.write('--executable not specified\n')
47 return False 51 return False
(...skipping 25 matching lines...) Expand all
73 77
74 78
75 def makeFile(output_file, input_cc_file, input_file): 79 def makeFile(output_file, input_cc_file, input_file):
76 snapshot_cc_text = open(input_cc_file).read() 80 snapshot_cc_text = open(input_cc_file).read()
77 snapshot_cc_text = snapshot_cc_text % makeString(input_file) 81 snapshot_cc_text = snapshot_cc_text % makeString(input_file)
78 open(output_file, 'w').write(snapshot_cc_text) 82 open(output_file, 'w').write(snapshot_cc_text)
79 return True 83 return True
80 84
81 85
82 def Main(): 86 def Main():
83 # Parse the options. 87 # Parse options.
84 parser = BuildOptions() 88 parser = BuildOptions()
85 (options, args) = parser.parse_args() 89 (options, args) = parser.parse_args()
86 if not ProcessOptions(options): 90 if not ProcessOptions(options):
87 parser.print_help() 91 parser.print_help()
88 return 1 92 return 1
89 93
90 # Construct the path to the dart binary. 94 # If there are additional arguments, report error and exit.
91 snapshot_argument = ''.join([ "--snapshot=", options.output_bin ]) 95 if args:
92 if not options.scripts: 96 parser.print_help()
93 command = [ options.executable, snapshot_argument ] 97 return 1
94 else: 98
95 scripts = string.split(options.scripts) 99 # Setup arguments to the snapshot generator binary.
96 command = [ options.executable, snapshot_argument ] + scripts 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
97 if options.verbose: 116 if options.verbose:
98 print ' '.join(command) 117 print ' '.join(command)
99 pipe = subprocess.Popen(command, 118 pipe = subprocess.Popen(command,
100 stdout=subprocess.PIPE, 119 stdout=subprocess.PIPE,
101 stderr=subprocess.PIPE) 120 stderr=subprocess.PIPE)
102 out, error = pipe.communicate() 121 out, error = pipe.communicate()
103 if (pipe.returncode != 0): 122 if (pipe.returncode != 0):
104 print out, error 123 print out, error
105 print "Snapshot generation failed" 124 print "Snapshot generation failed"
106 return -1 125 return -1
107 126
108 if not makeFile(options.output, options.input_cc, options.output_bin): 127 if not makeFile(options.output, options.input_cc, options.output_bin):
128 print "Unable to generate snapshot in C buffer form"
109 return -1 129 return -1
110 130
111 return 0 131 return 0
112 132
113 if __name__ == '__main__': 133 if __name__ == '__main__':
114 sys.exit(Main()) 134 sys.exit(Main())
OLDNEW
« no previous file with comments | « bin/run_vm_tests.cc ('k') | vm/dart.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698