OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 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 | 9 |
10 import json | 10 import json |
11 import optparse | 11 import optparse |
12 import os | 12 import os |
13 import subprocess | 13 import subprocess |
14 import sys | 14 import sys |
15 import shutil | 15 import shutil |
16 | 16 |
17 | 17 |
| 18 def HasSameContent(filename, content): |
| 19 '''Returns true if the given file is readable and has the given content.''' |
| 20 try: |
| 21 with open(filename) as file: |
| 22 return file.read() == content |
| 23 except: |
| 24 # Ignore all errors and fall back on a safe bet. |
| 25 return False |
| 26 |
| 27 |
18 def main (): | 28 def main (): |
19 parser = optparse.OptionParser() | 29 parser = optparse.OptionParser() |
20 parser.set_usage( | 30 parser.set_usage( |
21 "%prog v8_shell mock.js test_api.js js2webui.js " | 31 "%prog v8_shell mock.js test_api.js js2webui.js " |
22 "testtype inputfile inputrelfile cxxoutfile jsoutfile") | 32 "testtype inputfile inputrelfile cxxoutfile jsoutfile") |
23 parser.add_option('-v', '--verbose', action='store_true') | 33 parser.add_option('-v', '--verbose', action='store_true') |
24 parser.add_option('-n', '--impotent', action='store_true', | 34 parser.add_option('-n', '--impotent', action='store_true', |
25 help="don't execute; just print (as if verbose)") | 35 help="don't execute; just print (as if verbose)") |
26 parser.add_option('--deps_js', action="store", | 36 parser.add_option('--deps_js', action="store", |
27 help=("Path to deps.js for dependency resolution, " + | 37 help=("Path to deps.js for dependency resolution, " + |
(...skipping 20 matching lines...) Expand all Loading... |
48 cxxoutfile, test_type] | 58 cxxoutfile, test_type] |
49 cmd.extend(['-e', "arguments=" + json.dumps(arguments), mock_js, | 59 cmd.extend(['-e', "arguments=" + json.dumps(arguments), mock_js, |
50 test_api, js2webui]) | 60 test_api, js2webui]) |
51 if opts.verbose or opts.impotent: | 61 if opts.verbose or opts.impotent: |
52 print cmd | 62 print cmd |
53 if not opts.impotent: | 63 if not opts.impotent: |
54 try: | 64 try: |
55 p = subprocess.Popen( | 65 p = subprocess.Popen( |
56 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0) | 66 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0) |
57 out, err = p.communicate() | 67 out, err = p.communicate() |
58 with open(cxxoutfile, 'wb') as f: | 68 if not HasSameContent(cxxoutfile, out): |
59 f.write(out) | 69 with open(cxxoutfile, 'wb') as f: |
| 70 f.write(out) |
60 shutil.copyfile(inputfile, jsoutfile) | 71 shutil.copyfile(inputfile, jsoutfile) |
61 except Exception, ex: | 72 except Exception, ex: |
62 if os.path.exists(cxxoutfile): | 73 if os.path.exists(cxxoutfile): |
63 os.remove(cxxoutfile) | 74 os.remove(cxxoutfile) |
64 if os.path.exists(jsoutfile): | 75 if os.path.exists(jsoutfile): |
65 os.remove(jsoutfile) | 76 os.remove(jsoutfile) |
66 raise | 77 raise |
67 | 78 |
68 | 79 |
69 if __name__ == '__main__': | 80 if __name__ == '__main__': |
70 sys.exit(main()) | 81 sys.exit(main()) |
OLD | NEW |