| 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 20 matching lines...) Expand all Loading... |
| 31 for root, _, filenames in os.walk(root_dir): | 31 for root, _, filenames in os.walk(root_dir): |
| 32 basenames = fnmatch.filter(filenames, '*.' + ext) | 32 basenames = fnmatch.filter(filenames, '*.' + ext) |
| 33 files.extend([os.path.join(root, basename) | 33 files.extend([os.path.join(root, basename) |
| 34 for basename in basenames]) | 34 for basename in basenames]) |
| 35 | 35 |
| 36 return files | 36 return files |
| 37 | 37 |
| 38 | 38 |
| 39 def main(argv): | 39 def main(argv): |
| 40 option_parser = optparse.OptionParser() | 40 option_parser = optparse.OptionParser() |
| 41 option_parser.add_option('-o', '--output', help='HTML output filename.') | 41 option_parser.add_option('--output', help='HTML output filename.') |
| 42 option_parser.add_option('-c', '--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('-m', '--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', |
| 49 help='If set, removes coverage/metadata files.') |
| 48 options, args = option_parser.parse_args() | 50 options, args = option_parser.parse_args() |
| 49 | 51 |
| 50 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): |
| 51 option_parser.error('All arguments are required.') | 53 option_parser.error('One or more mandatory options are missing.') |
| 52 | 54 |
| 53 coverage_files = _GetFilesWithExt(options.coverage_dir, 'ec') | 55 coverage_files = _GetFilesWithExt(options.coverage_dir, 'ec') |
| 54 metadata_files = _GetFilesWithExt(options.metadata_dir, 'em') | 56 metadata_files = _GetFilesWithExt(options.metadata_dir, 'em') |
| 55 print 'Found coverage files: %s' % str(coverage_files) | 57 print 'Found coverage files: %s' % str(coverage_files) |
| 56 print 'Found metadata files: %s' % str(metadata_files) | 58 print 'Found metadata files: %s' % str(metadata_files) |
| 57 sources_files = [] | 59 sources_files = [] |
| 58 final_metadata_files = [] | 60 final_metadata_files = [] |
| 59 err = None | 61 err = None |
| 60 for f in metadata_files: | 62 for f in metadata_files: |
| 61 sources_file = os.path.splitext(f)[0] + '_sources.txt' | 63 sources_file = os.path.splitext(f)[0] + '_sources.txt' |
| (...skipping 19 matching lines...) Expand all Loading... |
| 81 | 83 |
| 82 output_args = ['-Dreport.html.out.file', options.output] | 84 output_args = ['-Dreport.html.out.file', options.output] |
| 83 source_args = ['-sp', ','.join(sources_files)] | 85 source_args = ['-sp', ','.join(sources_files)] |
| 84 | 86 |
| 85 exit_code = cmd_helper.RunCmd( | 87 exit_code = cmd_helper.RunCmd( |
| 86 ['java', '-cp', | 88 ['java', '-cp', |
| 87 os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'lib', 'emma.jar'), | 89 os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'lib', 'emma.jar'), |
| 88 'emma', 'report', '-r', 'html'] | 90 'emma', 'report', '-r', 'html'] |
| 89 + input_args + output_args + source_args) | 91 + input_args + output_args + source_args) |
| 90 | 92 |
| 93 if options.cleanup: |
| 94 for f in coverage_files + metadata_files: |
| 95 os.remove(f) |
| 96 |
| 91 if exit_code > 0: | 97 if exit_code > 0: |
| 92 return exit_code | 98 return exit_code |
| 93 elif err: | 99 elif err: |
| 94 return constants.WARNING_EXIT_CODE | 100 return constants.WARNING_EXIT_CODE |
| 95 else: | 101 else: |
| 96 return 0 | 102 return 0 |
| 97 | 103 |
| 98 | 104 |
| 99 if __name__ == '__main__': | 105 if __name__ == '__main__': |
| 100 sys.exit(main(sys.argv)) | 106 sys.exit(main(sys.argv)) |
| OLD | NEW |