2012-08-14 20:04:54 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
|
|
# for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
# BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
"""Script to create snapshot bin file."""
|
|
|
|
|
|
|
|
import getopt
|
|
|
|
import optparse
|
|
|
|
import os
|
2012-08-29 20:42:28 +00:00
|
|
|
from os.path import basename, join
|
2012-08-14 20:04:54 +00:00
|
|
|
import sys
|
|
|
|
import utils
|
|
|
|
|
|
|
|
|
|
|
|
def BuildOptions():
|
|
|
|
result = optparse.OptionParser()
|
|
|
|
result.add_option("--executable",
|
|
|
|
action="store", type="string",
|
|
|
|
help="path to snapshot generator executable")
|
2017-02-15 22:28:35 +00:00
|
|
|
result.add_option("--snapshot_kind",
|
|
|
|
action="store", type="string",
|
|
|
|
help="kind of snapshot to generate",
|
|
|
|
default="core")
|
2017-06-08 23:04:26 +00:00
|
|
|
result.add_option("--load_compilation_trace",
|
|
|
|
action="store", type="string",
|
|
|
|
help="path to a compilation trace to load before generating a core-jit snapshot")
|
|
|
|
result.add_option("--vm_flag",
|
|
|
|
action="append", type="string", default=[],
|
|
|
|
help="pass additional Dart VM flag")
|
2015-03-31 18:46:19 +00:00
|
|
|
result.add_option("--vm_output_bin",
|
|
|
|
action="store", type="string",
|
|
|
|
help="output file name into which vm isolate snapshot in binary form " +
|
|
|
|
"is generated")
|
2017-05-31 20:49:09 +00:00
|
|
|
result.add_option("--vm_instructions_output_bin",
|
|
|
|
action="store", type="string",
|
|
|
|
help="output file name into which vm isolate snapshot in binary form " +
|
|
|
|
"is generated")
|
2017-02-15 22:28:35 +00:00
|
|
|
result.add_option("--isolate_output_bin",
|
2012-08-14 20:04:54 +00:00
|
|
|
action="store", type="string",
|
2015-03-31 18:46:19 +00:00
|
|
|
help="output file name into which isolate snapshot in binary form " +
|
|
|
|
"is generated")
|
2017-05-31 20:49:09 +00:00
|
|
|
result.add_option("--isolate_instructions_output_bin",
|
|
|
|
action="store", type="string",
|
|
|
|
help="output file name into which isolate snapshot in binary form " +
|
|
|
|
"is generated")
|
2012-08-14 20:04:54 +00:00
|
|
|
result.add_option("--script",
|
|
|
|
action="store", type="string",
|
|
|
|
help="Dart script for which snapshot is to be generated")
|
2015-01-14 21:59:36 +00:00
|
|
|
result.add_option("--package_root",
|
|
|
|
action="store", type="string",
|
|
|
|
help="path used to resolve package: imports.")
|
2016-06-07 00:12:20 +00:00
|
|
|
result.add_option("--packages",
|
|
|
|
action="store", type="string",
|
|
|
|
help="package config file used to reasolve package: imports.")
|
2012-08-14 20:04:54 +00:00
|
|
|
result.add_option("-v", "--verbose",
|
|
|
|
help='Verbose output.',
|
|
|
|
default=False, action="store_true")
|
2015-08-27 18:14:13 +00:00
|
|
|
result.add_option("--timestamp_file",
|
|
|
|
action="store", type="string",
|
|
|
|
help="Path to timestamp file that will be written",
|
|
|
|
default="")
|
2012-08-14 20:04:54 +00:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def ProcessOptions(options):
|
|
|
|
if not options.executable:
|
|
|
|
sys.stderr.write('--executable not specified\n')
|
|
|
|
return False
|
2017-02-15 22:28:35 +00:00
|
|
|
if not options.snapshot_kind:
|
|
|
|
sys.stderr.write('--snapshot_kind not specified\n')
|
|
|
|
return False
|
2015-03-31 18:46:19 +00:00
|
|
|
if not options.vm_output_bin:
|
|
|
|
sys.stderr.write('--vm_output_bin not specified\n')
|
|
|
|
return False
|
2017-02-15 22:28:35 +00:00
|
|
|
if not options.isolate_output_bin:
|
|
|
|
sys.stderr.write('--isolate_output_bin not specified\n')
|
2012-08-14 20:04:54 +00:00
|
|
|
return False
|
2017-05-31 20:49:09 +00:00
|
|
|
if (options.snapshot_kind == 'core-jit'
|
|
|
|
and not options.vm_instructions_output_bin):
|
|
|
|
sys.stderr.write('--vm_instructions_output_bin not specified\n')
|
|
|
|
return False
|
|
|
|
if (options.snapshot_kind == 'core-jit'
|
|
|
|
and not options.isolate_instructions_output_bin):
|
|
|
|
sys.stderr.write('--isolate_instructions_output_bin not specified\n')
|
2012-08-29 20:42:28 +00:00
|
|
|
return False
|
2012-08-14 20:04:54 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
2015-08-27 18:14:13 +00:00
|
|
|
def CreateTimestampFile(options):
|
|
|
|
if options.timestamp_file != '':
|
|
|
|
dir_name = os.path.dirname(options.timestamp_file)
|
|
|
|
if not os.path.exists(dir_name):
|
|
|
|
os.mkdir(dir_name)
|
|
|
|
open(options.timestamp_file, 'w').close()
|
|
|
|
|
|
|
|
|
2012-08-14 20:04:54 +00:00
|
|
|
def Main():
|
|
|
|
# Parse options.
|
|
|
|
parser = BuildOptions()
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
if not ProcessOptions(options):
|
|
|
|
parser.print_help()
|
|
|
|
return 1
|
|
|
|
|
|
|
|
# If there are additional arguments, report error and exit.
|
|
|
|
if args:
|
|
|
|
parser.print_help()
|
|
|
|
return 1
|
|
|
|
|
|
|
|
# Setup arguments to the snapshot generator binary.
|
2017-06-08 23:04:26 +00:00
|
|
|
script_args = ["--ignore_unrecognized_flags"]
|
|
|
|
|
|
|
|
for flag in options.vm_flag:
|
|
|
|
script_args.append(flag)
|
|
|
|
|
|
|
|
if options.load_compilation_trace:
|
|
|
|
script_args.append(''.join([ "--load_compilation_trace=", options.load_compilation_trace]))
|
2012-08-14 20:04:54 +00:00
|
|
|
|
2015-01-14 21:59:36 +00:00
|
|
|
# Pass along the package_root if there is one.
|
|
|
|
if options.package_root:
|
|
|
|
script_args.append(''.join([ "--package_root=", options.package_root]))
|
|
|
|
|
2016-06-07 00:12:20 +00:00
|
|
|
# Pass along the packages if there is one.
|
|
|
|
if options.packages:
|
|
|
|
script_args.append(''.join([ "--packages=", options.packages]))
|
|
|
|
|
2015-03-31 18:46:19 +00:00
|
|
|
# First setup the vm isolate and regular isolate snapshot output filename.
|
2017-02-15 22:28:35 +00:00
|
|
|
script_args.append(''.join([ "--snapshot_kind=", options.snapshot_kind ]))
|
2017-01-23 18:25:02 +00:00
|
|
|
script_args.append(''.join([ "--vm_snapshot_data=", options.vm_output_bin ]))
|
2017-02-15 22:28:35 +00:00
|
|
|
script_args.append(''.join([ "--isolate_snapshot_data=", options.isolate_output_bin ]))
|
2015-10-22 19:26:41 +00:00
|
|
|
|
2017-05-31 20:49:09 +00:00
|
|
|
if options.vm_instructions_output_bin != None:
|
|
|
|
script_args.append(''.join([ "--vm_snapshot_instructions=",
|
|
|
|
options.vm_instructions_output_bin ]))
|
|
|
|
if options.isolate_instructions_output_bin != None:
|
|
|
|
script_args.append(''.join([ "--isolate_snapshot_instructions=",
|
|
|
|
options.isolate_instructions_output_bin ]))
|
|
|
|
|
2012-08-14 20:04:54 +00:00
|
|
|
# Finally append the script name if one is specified.
|
|
|
|
if options.script:
|
|
|
|
script_args.append(options.script)
|
|
|
|
|
|
|
|
# Construct command line to execute the snapshot generator binary and invoke.
|
2013-05-29 09:43:10 +00:00
|
|
|
command = [ options.executable ] + script_args
|
|
|
|
try:
|
|
|
|
utils.RunCommand(command, outStream=sys.stderr, errStream=sys.stderr,
|
|
|
|
verbose=options.verbose, printErrorInfo=True)
|
|
|
|
except Exception as e:
|
|
|
|
return -1
|
2012-08-14 20:04:54 +00:00
|
|
|
|
2015-08-27 18:14:13 +00:00
|
|
|
# Success, update timestamp file.
|
|
|
|
CreateTimestampFile(options)
|
|
|
|
|
2012-08-14 20:04:54 +00:00
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(Main())
|