OLD | NEW |
---|---|
(Empty) | |
1 #!/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.
| |
2 # Copyright (c) 2011 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. | |
5 # | |
6 # 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.
| |
7 # argument lists and to generate inlinable tests. | |
8 # | |
9 # Usage: | |
10 # python tools/gypv8sh.py -p product_dir path/to/javascript2webui.js | |
11 # python tools/gypv8sh.py -t # print test_harnesses | |
12 # python tools/gypv8sh.py -i # print inputs | |
13 # 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.
| |
14 import json | |
15 import optparse | |
16 import os | |
17 import subprocess | |
18 import sys | |
19 | |
20 # Please adjust the following to edit or add new javascript webui tests. | |
21 rules = [ | |
22 [ | |
23 'WebUIBrowserTestPass', | |
24 'test/data/webui/sample_pass.js', | |
25 'browser/ui/webui/web_ui_browsertest-inl.h', | |
26 ], | |
M-A Ruel
2011/06/17 18:15:36
Align ] on [
Sheridan Rawlins
2011/06/18 00:03:11
Done.
| |
27 ] | |
28 | |
29 def set_add(option, opt_str, value, parser, the_set, the_value): | |
30 the_set.add(the_value) | |
31 | |
32 # 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.
| |
33 # of indices to print in |print_rule_indices| and print them in sorted order if | |
34 # non-empty. | |
35 print_rule_indices = set() | |
36 parser = optparse.OptionParser(); | |
37 parser.set_usage( | |
38 "%prog [-v][-n] --product_dir PRODUCT_DIR -or- " | |
39 "%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
| |
40 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.
| |
41 parser.add_option('-n', '--impotent', action='store_true', dest='impotent', | |
42 help="don't execute; just print (as if verbose)") | |
43 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.
| |
44 dest='product_dir', | |
M-A Ruel
2011/06/17 18:15:36
like this dest=''
Sheridan Rawlins
2011/06/18 00:03:11
Done.
| |
45 help='for gyp to set the <(PRODUCT_DIR) for running v8_shell') | |
46 parser.add_option('-t', '--test_fixture', action='callback', callback=set_add, | |
47 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
| |
48 help='print test_fixtures') | |
49 parser.add_option('-i', '--in', action='callback', callback=set_add, | |
50 callback_args=tuple([print_rule_indices, 1]), | |
51 help='print inputs') | |
52 parser.add_option('-o', '--out', action='callback', callback=set_add, | |
53 callback_args=tuple([print_rule_indices, 2]), | |
54 help='print outputs') | |
55 (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.
| |
56 | |
57 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.
| |
58 for rule in rules: | |
59 for index in sorted(print_rule_indices): | |
60 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
| |
61 print | |
62 else: | |
63 if not opts.product_dir: | |
64 parser.error("--product_dir option is required"); | |
65 v8_shell = os.path.join(opts.product_dir, 'v8_shell') | |
66 jsfilename = args[0] | |
67 for rule in rules: | |
68 arguments = [jsfilename, rule[0], rule[1], os.path.basename(rule[1])] | |
69 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.
| |
70 cmd = [v8_shell, '-e', arguments, jsfilename] | |
71 if opts.verbose or opts.impotent: | |
72 print cmd | |
73 if not opts.impotent: | |
74 sys.exit(subprocess.call(cmd, stdout=open(rule[2],'w+'))) | |
OLD | NEW |