OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 | |
3 # Copyright 2013 The Chromium Authors. All rights reserved. | |
4 # Use of this source code is governed by a BSD-style license that can be | |
5 # found in the LICENSE file. | |
6 | |
7 """Aggregates EMMA coverage files to produce html output.""" | |
8 | |
9 import fnmatch | |
10 import json | |
11 import optparse | |
12 import os | |
13 import sys | |
14 | |
15 from pylib import cmd_helper | |
16 from pylib import constants | |
17 | |
18 | |
19 def _GetFilesWithExt(root_dir, ext): | |
20 """Gets all files with a given extension. | |
21 | |
22 Args: | |
23 root_dir: Directory in which to search for files. | |
24 ext: Extension to look for (including dot) | |
25 | |
26 Returns: | |
27 A list of absolute paths to files that match. | |
28 """ | |
29 files = [] | |
30 for root, _, filenames in os.walk(root_dir): | |
31 basenames = fnmatch.filter(filenames, '*.' + ext) | |
32 files.extend([os.path.join(root, basename) | |
33 for basename in basenames]) | |
34 | |
35 return files | |
36 | |
37 | |
38 def main(argv): | |
39 option_parser = optparse.OptionParser() | |
40 option_parser.add_option('-o', '--output', help='HTML output filename.') | |
41 option_parser.add_option('-c', '--coverage-dir', default=None, | |
42 help=('Root of the directory in which to search for ' | |
43 'coverage data (.ec) files.')) | |
44 option_parser.add_option('-m', '--metadata-dir', default=None, | |
45 help=('Root of the directory in which to search for ' | |
46 'coverage metadata (.em) files.')) | |
47 options, args = option_parser.parse_args() | |
48 | |
49 if not (options.coverage_dir and options.metadata_dir and options.output): | |
50 option_parser.error('All arguments are required.') | |
51 | |
52 coverage_files = _GetFilesWithExt(options.coverage_dir, 'ec') | |
53 metadata_files = _GetFilesWithExt(options.metadata_dir, 'em') | |
54 print 'Found coverage files: %s' % str(coverage_files) | |
55 print 'Found metadata files: %s' % str(metadata_files) | |
56 sources_files = [] | |
57 for f in metadata_files: | |
58 sources_file = os.path.join(os.path.dirname(f), 'emma_sources.txt') | |
59 if os.path.exists(sources_file): | |
frankf
2013/08/20 18:30:47
when would this not exist?
gkanwar1
2013/08/20 18:37:13
It shouldn't ever not exist, since the metadata an
frankf
2013/08/20 18:47:43
Right, robustness only makes sense if there are ex
gkanwar1
2013/08/20 18:56:18
Okay, removed the check.
| |
60 with open(sources_file, 'r') as f: | |
61 sources_files.extend(json.load(f)) | |
62 sources_files = [os.path.join(constants.DIR_SOURCE_ROOT, s) | |
63 for s in sources_files] | |
64 | |
65 input_args = [] | |
66 for f in coverage_files + metadata_files: | |
67 input_args.append('-in') | |
68 input_args.append(f) | |
69 | |
70 output_args = ['-Dreport.html.out.file', options.output] | |
71 source_args = ['-sp', ','.join(sources_files)] | |
72 | |
73 return cmd_helper.RunCmd( | |
74 ['java', '-cp', | |
75 os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'lib', 'emma.jar'), | |
76 'emma', 'report', '-r', 'html'] | |
77 + input_args + output_args + source_args) | |
78 | |
79 | |
80 if __name__ == '__main__': | |
81 sys.exit(main(sys.argv)) | |
OLD | NEW |