IndexedDB: Protect against use-after-free in ChainedBlobWriter.
[chromium-blink-merge.git] / tools / gypv8sh.py
blob9724ed4b1a6ed12b2b68a91748e049f231ba0e6f
1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """This script is used by chrome_tests.gypi's js2webui action to maintain the
7 argument lists and to generate inlinable tests.
8 """
10 import json
11 import optparse
12 import os
13 import subprocess
14 import sys
15 import shutil
18 def main ():
19 parser = optparse.OptionParser()
20 parser.set_usage(
21 "%prog v8_shell mock.js test_api.js js2webui.js "
22 "testtype inputfile inputrelfile cxxoutfile jsoutfile")
23 parser.add_option('-v', '--verbose', action='store_true')
24 parser.add_option('-n', '--impotent', action='store_true',
25 help="don't execute; just print (as if verbose)")
26 parser.add_option('--deps_js', action="store",
27 help=("Path to deps.js for dependency resolution, " +
28 "optional."))
29 parser.add_option('--external', action='store',
30 help="Load V8's initial snapshot from external files (y/n)")
31 (opts, args) = parser.parse_args()
33 if len(args) != 9:
34 parser.error('all arguments are required.')
35 (v8_shell, mock_js, test_api, js2webui, test_type,
36 inputfile, inputrelfile, cxxoutfile, jsoutfile) = args
37 cmd = [v8_shell]
38 icudatafile = os.path.join(os.path.dirname(v8_shell), 'icudtl.dat')
39 if os.path.exists(icudatafile):
40 cmd.extend(['--icu-data-file=%s' % icudatafile])
41 v8nativesfile = os.path.join(os.path.dirname(v8_shell), 'natives_blob.bin')
42 if opts.external == 'y' and os.path.exists(v8nativesfile):
43 cmd.extend(['--natives_blob=%s' % v8nativesfile])
44 v8snapshotfile = os.path.join(os.path.dirname(v8_shell), 'snapshot_blob.bin')
45 if opts.external == 'y' and os.path.exists(v8snapshotfile):
46 cmd.extend(['--snapshot_blob=%s' % v8snapshotfile])
47 arguments = [js2webui, inputfile, inputrelfile, opts.deps_js,
48 cxxoutfile, test_type]
49 cmd.extend(['-e', "arguments=" + json.dumps(arguments), mock_js,
50 test_api, js2webui])
51 if opts.verbose or opts.impotent:
52 print cmd
53 if not opts.impotent:
54 try:
55 p = subprocess.Popen(
56 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0)
57 out, err = p.communicate()
58 with open(cxxoutfile, 'wb') as f:
59 f.write(out)
60 shutil.copyfile(inputfile, jsoutfile)
61 except Exception, ex:
62 if os.path.exists(cxxoutfile):
63 os.remove(cxxoutfile)
64 if os.path.exists(jsoutfile):
65 os.remove(jsoutfile)
66 raise
69 if __name__ == '__main__':
70 sys.exit(main())