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 # TODO(gkanwar): Remove this once old coverage.em files have been cleaned |
60 sources_files.extend(json.load(f)) | 63 # from all bots. |
| 64 # Warn if we have old metadata files lying around that don't correspond |
| 65 # to a *_sources.txt (these should be manually cleaned). |
| 66 try: |
| 67 with open(sources_file, 'r') as sf: |
| 68 sources_files.extend(json.load(sf)) |
| 69 except IOError as e: |
| 70 traceback.print_exc() |
| 71 err = e |
| 72 else: |
| 73 final_metadata_files.append(f) |
61 sources_files = [os.path.join(constants.DIR_SOURCE_ROOT, s) | 74 sources_files = [os.path.join(constants.DIR_SOURCE_ROOT, s) |
62 for s in sources_files] | 75 for s in sources_files] |
63 | 76 |
64 input_args = [] | 77 input_args = [] |
65 for f in coverage_files + metadata_files: | 78 for f in coverage_files + final_metadata_files: |
66 input_args.append('-in') | 79 input_args.append('-in') |
67 input_args.append(f) | 80 input_args.append(f) |
68 | 81 |
69 output_args = ['-Dreport.html.out.file', options.output] | 82 output_args = ['-Dreport.html.out.file', options.output] |
70 source_args = ['-sp', ','.join(sources_files)] | 83 source_args = ['-sp', ','.join(sources_files)] |
71 | 84 |
72 return cmd_helper.RunCmd( | 85 exit_code = cmd_helper.RunCmd( |
73 ['java', '-cp', | 86 ['java', '-cp', |
74 os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'lib', 'emma.jar'), | 87 os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'lib', 'emma.jar'), |
75 'emma', 'report', '-r', 'html'] | 88 'emma', 'report', '-r', 'html'] |
76 + input_args + output_args + source_args) | 89 + input_args + output_args + source_args) |
77 | 90 |
| 91 if exit_code > 0: |
| 92 return exit_code |
| 93 elif err: |
| 94 return constants.WARNING_EXIT_CODE |
| 95 else: |
| 96 return 0 |
| 97 |
78 | 98 |
79 if __name__ == '__main__': | 99 if __name__ == '__main__': |
80 sys.exit(main(sys.argv)) | 100 sys.exit(main(sys.argv)) |
OLD | NEW |