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