| OLD | NEW |
| (Empty) |
| 1 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 2 # for details. All rights reserved. Use of this source code is governed by a | |
| 3 # BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 """Wraps jscoverage to instrument a single file more efficently. | |
| 6 | |
| 7 JScoverage crawls directories recursively to copy and instrument everything | |
| 8 under a directory. This turns out to be too slow for our use, because our | |
| 9 generated .js files live in directories with > 100K files. Even though | |
| 10 jscoverage has a flag ('--exclude') to skip some files for | |
| 11 instrumentation/copying, it stills crawls recursively everything under the | |
| 12 directory. | |
| 13 | |
| 14 This script is a simple wrap on top of jscoverage. It creates a temporary | |
| 15 directory, copies the file we want to instrument alone, and runs jscoverage | |
| 16 within this small directory. | |
| 17 """ | |
| 18 | |
| 19 import os | |
| 20 import subprocess | |
| 21 import sys | |
| 22 | |
| 23 def main(): | |
| 24 if len(sys.argv) < 3: | |
| 25 print "usage: %s <jscoverage-path> filepath outdir" | |
| 26 return 1 | |
| 27 | |
| 28 jscoveragecmd = sys.argv[1] | |
| 29 filepath = sys.argv[2] | |
| 30 outdir = sys.argv[3] | |
| 31 | |
| 32 tmpdir = filepath + "_" | |
| 33 copypath = os.path.join(tmpdir, os.path.basename(filepath)) | |
| 34 try: | |
| 35 os.mkdir(tmpdir) | |
| 36 except Exception: | |
| 37 if not os.path.exists(tmpdir): | |
| 38 raise | |
| 39 with open(filepath, 'r') as f1: | |
| 40 with open(copypath, 'w') as f2: | |
| 41 f2.write(f1.read()) | |
| 42 status = subprocess.call([jscoveragecmd, tmpdir, outdir]) | |
| 43 os.remove(copypath) | |
| 44 os.rmdir(tmpdir) | |
| 45 return status | |
| 46 | |
| 47 if __name__ == '__main__': | |
| 48 sys.exit(main()) | |
| OLD | NEW |