OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """This script is used by chrome_tests.gypi's js2webui action to maintain the | 6 """This script is used by chrome_tests.gypi's js2webui action to maintain the |
7 argument lists and to generate inlinable tests. | 7 argument lists and to generate inlinable tests. |
8 | 8 |
9 Usage: | 9 Usage: |
10 python tools/gypv8sh.py v8_shell mock.js test_api.js js2webui.js \ | 10 python tools/gypv8sh.py v8_shell mock.js test_api.js js2webui.js \ |
11 inputfile inputrelfile cxxoutfile jsoutfile | 11 inputfile inputrelfile cxxoutfile jsoutfile |
12 """ | 12 """ |
13 | 13 |
14 try: | 14 import json |
15 import json | |
16 except ImportError: | |
17 import simplejson as json | |
18 import optparse | 15 import optparse |
19 import os | 16 import os |
20 import subprocess | 17 import subprocess |
21 import sys | 18 import sys |
22 import shutil | 19 import shutil |
23 | 20 |
| 21 |
24 def main (): | 22 def main (): |
25 parser = optparse.OptionParser() | 23 parser = optparse.OptionParser() |
26 parser.set_usage( | 24 parser.set_usage( |
27 "%prog v8_shell mock.js test_api.js js2webui.js " | 25 "%prog v8_shell mock.js test_api.js js2webui.js " |
28 "testtype inputfile inputrelfile cxxoutfile jsoutfile") | 26 "testtype inputfile inputrelfile cxxoutfile jsoutfile") |
29 parser.add_option('-v', '--verbose', action='store_true') | 27 parser.add_option('-v', '--verbose', action='store_true') |
30 parser.add_option('-n', '--impotent', action='store_true', | 28 parser.add_option('-n', '--impotent', action='store_true', |
31 help="don't execute; just print (as if verbose)") | 29 help="don't execute; just print (as if verbose)") |
32 (opts, args) = parser.parse_args() | 30 (opts, args) = parser.parse_args() |
33 | 31 |
34 if len(args) != 9: | 32 if len(args) != 9: |
35 parser.error('all arguments are required.') | 33 parser.error('all arguments are required.') |
36 (v8_shell, mock_js, test_api, js2webui, test_type, | 34 (v8_shell, mock_js, test_api, js2webui, test_type, |
37 inputfile, inputrelfile, cxxoutfile, jsoutfile) = args | 35 inputfile, inputrelfile, cxxoutfile, jsoutfile) = args |
38 arguments = [js2webui, inputfile, inputrelfile, cxxoutfile, test_type] | 36 arguments = [js2webui, inputfile, inputrelfile, cxxoutfile, test_type] |
39 cmd = [v8_shell, '-e', "arguments=" + json.dumps(arguments), mock_js, | 37 cmd = [v8_shell, '-e', "arguments=" + json.dumps(arguments), mock_js, |
40 test_api, js2webui] | 38 test_api, js2webui] |
41 if opts.verbose or opts.impotent: | 39 if opts.verbose or opts.impotent: |
42 print cmd | 40 print cmd |
43 if not opts.impotent: | 41 if not opts.impotent: |
44 try: | 42 try: |
45 subprocess.check_call(cmd, stdout=open(cxxoutfile, 'w')) | 43 with open(cxxoutfile, 'w') as f: |
| 44 subprocess.check_call(cmd, stdin=subprocess.PIPE, stdout=f) |
46 shutil.copyfile(inputfile, jsoutfile) | 45 shutil.copyfile(inputfile, jsoutfile) |
47 except Exception, ex: | 46 except Exception, ex: |
48 print ex | 47 if os.path.exists(cxxoutfile): |
49 os.remove(cxxoutfile) | 48 os.remove(cxxoutfile) |
50 os.remove(jsoutfile) | 49 if os.path.exists(jsoutfile): |
51 sys.exit(1) | 50 os.remove(jsoutfile) |
| 51 raise |
| 52 |
52 | 53 |
53 if __name__ == '__main__': | 54 if __name__ == '__main__': |
54 sys.exit(main()) | 55 sys.exit(main()) |
OLD | NEW |