blob: 868e2aad42f371b2fc04ba4ee73995bd12b7e322 [file] [log] [blame]
[email protected]982899492011-07-01 20:46:171#!/usr/bin/env python
[email protected]4f6b1db02012-05-18 18:15:192# Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]982899492011-07-01 20:46:173# 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
7argument lists and to generate inlinable tests.
[email protected]982899492011-07-01 20:46:178"""
9
Raul Tambref3d9412e2019-09-24 05:31:4410from __future__ import print_function
11
[email protected]4f6b1db02012-05-18 18:15:1912import json
[email protected]982899492011-07-01 20:46:1713import optparse
14import os
15import subprocess
16import sys
[email protected]4ba1dbc2011-10-22 01:46:0317import shutil
[email protected]982899492011-07-01 20:46:1718
[email protected]4f6b1db02012-05-18 18:15:1919
plundblad9e0db322015-05-11 18:12:3920def HasSameContent(filename, content):
21 '''Returns true if the given file is readable and has the given content.'''
22 try:
23 with open(filename) as file:
24 return file.read() == content
25 except:
26 # Ignore all errors and fall back on a safe bet.
27 return False
28
29
[email protected]982899492011-07-01 20:46:1730def main ():
31 parser = optparse.OptionParser()
[email protected]bf8feaa2011-07-12 00:17:3632 parser.set_usage(
[email protected]b5664182014-06-05 22:16:5933 "%prog v8_shell mock.js test_api.js js2webui.js "
A Olsen0cbed542019-04-23 10:12:1434 "testtype inputfile srcrootdir cxxoutfile jsoutfile")
[email protected]982899492011-07-01 20:46:1735 parser.add_option('-v', '--verbose', action='store_true')
36 parser.add_option('-n', '--impotent', action='store_true',
37 help="don't execute; just print (as if verbose)")
[email protected]b5664182014-06-05 22:16:5938 parser.add_option('--deps_js', action="store",
39 help=("Path to deps.js for dependency resolution, " +
40 "optional."))
baixo3a3c88a2014-10-28 11:52:2141 parser.add_option('--external', action='store',
42 help="Load V8's initial snapshot from external files (y/n)")
[email protected]982899492011-07-01 20:46:1743 (opts, args) = parser.parse_args()
44
[email protected]b5664182014-06-05 22:16:5945 if len(args) != 9:
[email protected]982899492011-07-01 20:46:1746 parser.error('all arguments are required.')
[email protected]b5664182014-06-05 22:16:5947 (v8_shell, mock_js, test_api, js2webui, test_type,
A Olsen0cbed542019-04-23 10:12:1448 inputfile, srcrootdir, cxxoutfile, jsoutfile) = args
[email protected]b6ae0be2014-05-22 11:39:5149 cmd = [v8_shell]
A Olsen0cbed542019-04-23 10:12:1450 arguments = [js2webui, inputfile, srcrootdir, opts.deps_js,
[email protected]b5664182014-06-05 22:16:5951 cxxoutfile, test_type]
[email protected]b6ae0be2014-05-22 11:39:5152 cmd.extend(['-e', "arguments=" + json.dumps(arguments), mock_js,
[email protected]b5664182014-06-05 22:16:5953 test_api, js2webui])
[email protected]982899492011-07-01 20:46:1754 if opts.verbose or opts.impotent:
Raul Tambref3d9412e2019-09-24 05:31:4455 print(cmd)
[email protected]982899492011-07-01 20:46:1756 if not opts.impotent:
57 try:
[email protected]abb2ada2014-07-02 16:33:0858 p = subprocess.Popen(
59 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0)
[email protected]46dd51e92014-07-01 18:01:3060 out, err = p.communicate()
plundblad2cadf1f2015-08-27 19:58:4061 if p.returncode != 0:
62 sys.stderr.write(out + err);
63 return 1
plundblad9e0db322015-05-11 18:12:3964 if not HasSameContent(cxxoutfile, out):
65 with open(cxxoutfile, 'wb') as f:
66 f.write(out)
[email protected]4ba1dbc2011-10-22 01:46:0367 shutil.copyfile(inputfile, jsoutfile)
[email protected]982899492011-07-01 20:46:1768 except Exception, ex:
[email protected]4f6b1db02012-05-18 18:15:1969 if os.path.exists(cxxoutfile):
70 os.remove(cxxoutfile)
71 if os.path.exists(jsoutfile):
72 os.remove(jsoutfile)
73 raise
74
[email protected]982899492011-07-01 20:46:1775
76if __name__ == '__main__':
plundblad9e0db322015-05-11 18:12:3977 sys.exit(main())