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 |
(...skipping 28 matching lines...) Expand all Loading... |
39 def main(argv): | 39 def main(argv): |
40 option_parser = optparse.OptionParser() | 40 option_parser = optparse.OptionParser() |
41 option_parser.add_option('--output', help='HTML output filename.') | 41 option_parser.add_option('--output', help='HTML output filename.') |
42 option_parser.add_option('--coverage-dir', default=None, | 42 option_parser.add_option('--coverage-dir', default=None, |
43 help=('Root of the directory in which to search for ' | 43 help=('Root of the directory in which to search for ' |
44 'coverage data (.ec) files.')) | 44 'coverage data (.ec) files.')) |
45 option_parser.add_option('--metadata-dir', default=None, | 45 option_parser.add_option('--metadata-dir', default=None, |
46 help=('Root of the directory in which to search for ' | 46 help=('Root of the directory in which to search for ' |
47 'coverage metadata (.em) files.')) | 47 'coverage metadata (.em) files.')) |
48 option_parser.add_option('--cleanup', action='store_true', | 48 option_parser.add_option('--cleanup', action='store_true', |
49 help='If set, removes coverage/metadata files.') | 49 help=('If set, removes coverage files generated at ' |
| 50 'runtime.')) |
50 options, args = option_parser.parse_args() | 51 options, args = option_parser.parse_args() |
51 | 52 |
52 if not (options.coverage_dir and options.metadata_dir and options.output): | 53 if not (options.coverage_dir and options.metadata_dir and options.output): |
53 option_parser.error('One or more mandatory options are missing.') | 54 option_parser.error('One or more mandatory options are missing.') |
54 | 55 |
55 coverage_files = _GetFilesWithExt(options.coverage_dir, 'ec') | 56 coverage_files = _GetFilesWithExt(options.coverage_dir, 'ec') |
56 metadata_files = _GetFilesWithExt(options.metadata_dir, 'em') | 57 metadata_files = _GetFilesWithExt(options.metadata_dir, 'em') |
57 print 'Found coverage files: %s' % str(coverage_files) | 58 print 'Found coverage files: %s' % str(coverage_files) |
58 print 'Found metadata files: %s' % str(metadata_files) | 59 print 'Found metadata files: %s' % str(metadata_files) |
59 sources_files = [] | 60 |
60 final_metadata_files = [] | 61 sources = [] |
61 err = None | |
62 for f in metadata_files: | 62 for f in metadata_files: |
63 sources_file = os.path.splitext(f)[0] + '_sources.txt' | 63 sources_file = os.path.splitext(f)[0] + '_sources.txt' |
64 # TODO(gkanwar): Remove this once old coverage.em files have been cleaned | 64 with open(sources_file, 'r') as sf: |
65 # from all bots. | 65 sources.extend(json.load(sf)) |
66 # Warn if we have old metadata files lying around that don't correspond | 66 sources = [os.path.join(constants.DIR_SOURCE_ROOT, s) for s in sources] |
67 # to a *_sources.txt (these should be manually cleaned). | 67 print 'Sources: %s' % sources |
68 try: | |
69 with open(sources_file, 'r') as sf: | |
70 sources_files.extend(json.load(sf)) | |
71 except IOError as e: | |
72 traceback.print_exc() | |
73 err = e | |
74 else: | |
75 final_metadata_files.append(f) | |
76 sources_files = [os.path.join(constants.DIR_SOURCE_ROOT, s) | |
77 for s in sources_files] | |
78 | 68 |
79 input_args = [] | 69 input_args = [] |
80 for f in coverage_files + final_metadata_files: | 70 for f in coverage_files + metadata_files: |
81 input_args.append('-in') | 71 input_args.append('-in') |
82 input_args.append(f) | 72 input_args.append(f) |
83 | 73 |
84 output_args = ['-Dreport.html.out.file', options.output] | 74 output_args = ['-Dreport.html.out.file', options.output] |
85 source_args = ['-sp', ','.join(sources_files)] | 75 source_args = ['-sp', ','.join(sources)] |
86 | 76 |
87 exit_code = cmd_helper.RunCmd( | 77 exit_code = cmd_helper.RunCmd( |
88 ['java', '-cp', | 78 ['java', '-cp', |
89 os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'lib', 'emma.jar'), | 79 os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'lib', 'emma.jar'), |
90 'emma', 'report', '-r', 'html'] | 80 'emma', 'report', '-r', 'html'] |
91 + input_args + output_args + source_args) | 81 + input_args + output_args + source_args) |
92 | 82 |
93 if options.cleanup: | 83 if options.cleanup: |
94 for f in coverage_files + metadata_files: | 84 for f in coverage_files: |
95 os.remove(f) | 85 os.remove(f) |
96 | 86 |
97 if exit_code > 0: | 87 return exit_code |
98 return exit_code | |
99 elif err: | |
100 return constants.WARNING_EXIT_CODE | |
101 else: | |
102 return 0 | |
103 | 88 |
104 | 89 |
105 if __name__ == '__main__': | 90 if __name__ == '__main__': |
106 sys.exit(main(sys.argv)) | 91 sys.exit(main(sys.argv)) |
OLD | NEW |