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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 help='If set, removes coverage/metadata files.') | 49 help='If set, removes coverage/metadata files.') |
50 options, args = option_parser.parse_args() | 50 options, args = option_parser.parse_args() |
51 | 51 |
52 if not (options.coverage_dir and options.metadata_dir and options.output): | 52 if not (options.coverage_dir and options.metadata_dir and options.output): |
53 option_parser.error('One or more mandatory options are missing.') | 53 option_parser.error('One or more mandatory options are missing.') |
54 | 54 |
55 coverage_files = _GetFilesWithExt(options.coverage_dir, 'ec') | 55 coverage_files = _GetFilesWithExt(options.coverage_dir, 'ec') |
56 metadata_files = _GetFilesWithExt(options.metadata_dir, 'em') | 56 metadata_files = _GetFilesWithExt(options.metadata_dir, 'em') |
57 print 'Found coverage files: %s' % str(coverage_files) | 57 print 'Found coverage files: %s' % str(coverage_files) |
58 print 'Found metadata files: %s' % str(metadata_files) | 58 print 'Found metadata files: %s' % str(metadata_files) |
59 sources_files = [] | 59 |
60 final_metadata_files = [] | 60 sources = [] |
61 err = None | |
62 for f in metadata_files: | 61 for f in metadata_files: |
63 sources_file = os.path.splitext(f)[0] + '_sources.txt' | 62 sources_file = os.path.splitext(f)[0] + '_sources.txt' |
64 # TODO(gkanwar): Remove this once old coverage.em files have been cleaned | 63 with open(sources_file, 'r') as sf: |
65 # from all bots. | 64 sources.extend(json.load(sf)) |
66 # Warn if we have old metadata files lying around that don't correspond | 65 sources = [os.path.join(constants.DIR_SOURCE_ROOT, s) for s in sources] |
67 # to a *_sources.txt (these should be manually cleaned). | 66 print 'Sources: %s' % sources |
cjhopman
2013/08/30 17:59:40
Note: this print is new. Just confirming that's in
frankf
2013/08/30 18:12:36
Yea, they've been helpful in debugging.
| |
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 | 67 |
79 input_args = [] | 68 input_args = [] |
80 for f in coverage_files + final_metadata_files: | 69 for f in coverage_files + metadata_files: |
81 input_args.append('-in') | 70 input_args.append('-in') |
82 input_args.append(f) | 71 input_args.append(f) |
83 | 72 |
84 output_args = ['-Dreport.html.out.file', options.output] | 73 output_args = ['-Dreport.html.out.file', options.output] |
85 source_args = ['-sp', ','.join(sources_files)] | 74 source_args = ['-sp', ','.join(sources)] |
86 | 75 |
87 exit_code = cmd_helper.RunCmd( | 76 exit_code = cmd_helper.RunCmd( |
88 ['java', '-cp', | 77 ['java', '-cp', |
89 os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'lib', 'emma.jar'), | 78 os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'lib', 'emma.jar'), |
90 'emma', 'report', '-r', 'html'] | 79 'emma', 'report', '-r', 'html'] |
91 + input_args + output_args + source_args) | 80 + input_args + output_args + source_args) |
92 | 81 |
93 if options.cleanup: | 82 if options.cleanup: |
94 for f in coverage_files + metadata_files: | 83 for f in coverage_files: |
95 os.remove(f) | 84 os.remove(f) |
96 | 85 |
97 if exit_code > 0: | 86 return exit_code |
98 return exit_code | |
99 elif err: | |
100 return constants.WARNING_EXIT_CODE | |
101 else: | |
102 return 0 | |
103 | 87 |
104 | 88 |
105 if __name__ == '__main__': | 89 if __name__ == '__main__': |
106 sys.exit(main(sys.argv)) | 90 sys.exit(main(sys.argv)) |
OLD | NEW |