Chromium Code Reviews| Index: tools/gypv8sh.py |
| diff --git a/tools/gypv8sh.py b/tools/gypv8sh.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..387b9e4c77e3c9bf63b21263f8d24f26afabe49a |
| --- /dev/null |
| +++ b/tools/gypv8sh.py |
| @@ -0,0 +1,74 @@ |
| +#!/usr/bin/python |
|
M-A Ruel
2011/06/17 18:15:36
#!/usr/bin/env python
Don't forget your BSD frien
Sheridan Rawlins
2011/06/18 00:03:11
Done.
|
| +# Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| +# |
| +# This script is used by chrome_tests.gypi's js2webui action to maintain the |
|
M-A Ruel
2011/06/17 18:15:36
Use a docstring instead.
Sheridan Rawlins
2011/06/18 00:03:11
Done.
|
| +# argument lists and to generate inlinable tests. |
| +# |
| +# Usage: |
| +# python tools/gypv8sh.py -p product_dir path/to/javascript2webui.js |
| +# python tools/gypv8sh.py -t # print test_harnesses |
| +# python tools/gypv8sh.py -i # print inputs |
| +# python tools/gypv8sh.py -o # print outputs |
|
M-A Ruel
2011/06/17 18:15:36
Add empty line
Sheridan Rawlins
2011/06/18 00:03:11
Done.
|
| +import json |
| +import optparse |
| +import os |
| +import subprocess |
| +import sys |
| + |
| +# Please adjust the following to edit or add new javascript webui tests. |
| +rules = [ |
| + [ |
| + 'WebUIBrowserTestPass', |
| + 'test/data/webui/sample_pass.js', |
| + 'browser/ui/webui/web_ui_browsertest-inl.h', |
| + ], |
|
M-A Ruel
2011/06/17 18:15:36
Align ] on [
Sheridan Rawlins
2011/06/18 00:03:11
Done.
|
| + ] |
| + |
| +def set_add(option, opt_str, value, parser, the_set, the_value): |
| + the_set.add(the_value) |
| + |
| +# For options -t, -i, & -o, we print the "column" of the |rules|. We keep a set |
|
M-A Ruel
2011/06/17 18:15:36
Put that in a main() function and only keep this a
Sheridan Rawlins
2011/06/18 00:03:11
Done.
|
| +# of indices to print in |print_rule_indices| and print them in sorted order if |
| +# non-empty. |
| +print_rule_indices = set() |
| +parser = optparse.OptionParser(); |
| +parser.set_usage( |
| + "%prog [-v][-n] --product_dir PRODUCT_DIR -or- " |
| + "%prog [-v][-n] (-i|-t|-o)"); |
|
M-A Ruel
2011/06/17 18:15:36
comma everywhere
Sheridan Rawlins
2011/06/18 00:03:11
As per IM session, you mean remove all semi-colons
|
| +parser.add_option('-v', '--verbose', action='store_true', dest='verbose') |
|
M-A Ruel
2011/06/17 18:15:36
Don't use dest='' if it is the same name than the
Sheridan Rawlins
2011/06/18 00:03:11
Done.
|
| +parser.add_option('-n', '--impotent', action='store_true', dest='impotent', |
| + help="don't execute; just print (as if verbose)") |
| +parser.add_option('-p', '--product_dir', action='store', type='string', |
|
M-A Ruel
2011/06/17 18:15:36
action='store', type='string' is superfluous, it's
Sheridan Rawlins
2011/06/18 00:03:11
Done.
|
| + dest='product_dir', |
|
M-A Ruel
2011/06/17 18:15:36
like this dest=''
Sheridan Rawlins
2011/06/18 00:03:11
Done.
|
| + help='for gyp to set the <(PRODUCT_DIR) for running v8_shell') |
| +parser.add_option('-t', '--test_fixture', action='callback', callback=set_add, |
| + callback_args=tuple([print_rule_indices, 0]), |
|
M-A Ruel
2011/06/17 18:15:36
callback_args=([print_rule_indices, 0],)
But this
Sheridan Rawlins
2011/06/18 00:03:11
As we only need to print one "column" at a time, u
|
| + help='print test_fixtures') |
| +parser.add_option('-i', '--in', action='callback', callback=set_add, |
| + callback_args=tuple([print_rule_indices, 1]), |
| + help='print inputs') |
| +parser.add_option('-o', '--out', action='callback', callback=set_add, |
| + callback_args=tuple([print_rule_indices, 2]), |
| + help='print outputs') |
| +(opts, args) = parser.parse_args(); |
|
M-A Ruel
2011/06/17 18:15:36
Remove extra comma
Sheridan Rawlins
2011/06/18 00:03:11
Done.
|
| + |
| +if len(print_rule_indices): |
|
M-A Ruel
2011/06/17 18:15:36
if print_rule_indices:
Sheridan Rawlins
2011/06/18 00:03:11
Done.
|
| + for rule in rules: |
| + for index in sorted(print_rule_indices): |
| + print rule[index], |
|
M-A Ruel
2011/06/17 18:15:36
Did you intent?
print '\n'.join(rule[index] for in
Sheridan Rawlins
2011/06/18 00:03:11
I don't think so, but it's moot with rewrite.
On
|
| +else: |
| + if not opts.product_dir: |
| + parser.error("--product_dir option is required"); |
| + v8_shell = os.path.join(opts.product_dir, 'v8_shell') |
| + jsfilename = args[0] |
| + for rule in rules: |
| + arguments = [jsfilename, rule[0], rule[1], os.path.basename(rule[1])] |
| + arguments = "arguments=" + json.dumps(arguments) |
|
M-A Ruel
2011/06/17 18:15:36
This variable aliasing is weird since you use 2 di
Sheridan Rawlins
2011/06/18 00:03:11
Rolled 69 into the next line - Done.
|
| + cmd = [v8_shell, '-e', arguments, jsfilename] |
| + if opts.verbose or opts.impotent: |
| + print cmd |
| + if not opts.impotent: |
| + sys.exit(subprocess.call(cmd, stdout=open(rule[2],'w+'))) |