OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Aggregates EMMA coverage files to produce html output.""" | 7 """Aggregates EMMA coverage files to produce html output.""" |
8 | 8 |
9 import fnmatch | 9 import fnmatch |
10 import json | 10 import json |
11 import optparse | 11 import optparse |
12 import os | 12 import os |
13 import sys | 13 import sys |
14 import traceback | |
14 | 15 |
15 from pylib import cmd_helper | 16 from pylib import cmd_helper |
16 from pylib import constants | 17 from pylib import constants |
17 | 18 |
18 | 19 |
19 def _GetFilesWithExt(root_dir, ext): | 20 def _GetFilesWithExt(root_dir, ext): |
20 """Gets all files with a given extension. | 21 """Gets all files with a given extension. |
21 | 22 |
22 Args: | 23 Args: |
23 root_dir: Directory in which to search for files. | 24 root_dir: Directory in which to search for files. |
(...skipping 23 matching lines...) Expand all Loading... | |
47 options, args = option_parser.parse_args() | 48 options, args = option_parser.parse_args() |
48 | 49 |
49 if not (options.coverage_dir and options.metadata_dir and options.output): | 50 if not (options.coverage_dir and options.metadata_dir and options.output): |
50 option_parser.error('All arguments are required.') | 51 option_parser.error('All arguments are required.') |
51 | 52 |
52 coverage_files = _GetFilesWithExt(options.coverage_dir, 'ec') | 53 coverage_files = _GetFilesWithExt(options.coverage_dir, 'ec') |
53 metadata_files = _GetFilesWithExt(options.metadata_dir, 'em') | 54 metadata_files = _GetFilesWithExt(options.metadata_dir, 'em') |
54 print 'Found coverage files: %s' % str(coverage_files) | 55 print 'Found coverage files: %s' % str(coverage_files) |
55 print 'Found metadata files: %s' % str(metadata_files) | 56 print 'Found metadata files: %s' % str(metadata_files) |
56 sources_files = [] | 57 sources_files = [] |
58 final_metadata_files = [] | |
59 err = None | |
57 for f in metadata_files: | 60 for f in metadata_files: |
58 sources_file = os.path.join(os.path.dirname(f), 'emma_sources.txt') | 61 sources_file = os.path.splitext(f)[0] + '_sources.txt' |
59 with open(sources_file, 'r') as f: | 62 # Warn if we have old metadata files lying around that don't correspond |
60 sources_files.extend(json.load(f)) | 63 # to a *_sources.txt (these should be manually cleaned). |
frankf
2013/08/22 17:34:26
Can you add a TODO that this should be removed onc
gkanwar1
2013/08/22 18:09:58
Done.
| |
64 try: | |
65 with open(sources_file, 'r') as sf: | |
66 sources_files.extend(json.load(sf)) | |
67 except IOError as e: | |
68 traceback.print_exc() | |
69 err = e | |
70 else: | |
71 final_metadata_files.append(f) | |
61 sources_files = [os.path.join(constants.DIR_SOURCE_ROOT, s) | 72 sources_files = [os.path.join(constants.DIR_SOURCE_ROOT, s) |
62 for s in sources_files] | 73 for s in sources_files] |
63 | 74 |
64 input_args = [] | 75 input_args = [] |
65 for f in coverage_files + metadata_files: | 76 for f in coverage_files + final_metadata_files: |
66 input_args.append('-in') | 77 input_args.append('-in') |
67 input_args.append(f) | 78 input_args.append(f) |
68 | 79 |
69 output_args = ['-Dreport.html.out.file', options.output] | 80 output_args = ['-Dreport.html.out.file', options.output] |
70 source_args = ['-sp', ','.join(sources_files)] | 81 source_args = ['-sp', ','.join(sources_files)] |
71 | 82 |
72 return cmd_helper.RunCmd( | 83 exit_code = cmd_helper.RunCmd( |
73 ['java', '-cp', | 84 ['java', '-cp', |
74 os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'lib', 'emma.jar'), | 85 os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'lib', 'emma.jar'), |
75 'emma', 'report', '-r', 'html'] | 86 'emma', 'report', '-r', 'html'] |
76 + input_args + output_args + source_args) | 87 + input_args + output_args + source_args) |
77 | 88 |
89 if exit_code > 0: | |
90 return exit_code | |
91 elif err: | |
92 return constants.WARNING_EXIT_CODE | |
93 else: | |
94 return 0 | |
95 | |
78 | 96 |
79 if __name__ == '__main__': | 97 if __name__ == '__main__': |
80 sys.exit(main(sys.argv)) | 98 sys.exit(main(sys.argv)) |
OLD | NEW |