| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Generates incremental code coverage reports for Java code in Chromium. | 6 """Generates incremental code coverage reports for Java code in Chromium. |
| 7 | 7 |
| 8 Usage: | 8 Usage: |
| 9 | 9 |
| 10 build/android/coverage.py -v --out <output file path> --emma-dir | 10 build/android/coverage.py -v --out <output file path> --emma-dir |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 that we should compute coverage information on lines 1 - 3 for file1. | 443 that we should compute coverage information on lines 1 - 3 for file1. |
| 444 out_file_path: A string representing the location to write the JSON report. | 444 out_file_path: A string representing the location to write the JSON report. |
| 445 coverage_dir: A string representing the file path where the EMMA | 445 coverage_dir: A string representing the file path where the EMMA |
| 446 HTML coverage files are located (i.e. folder where index.html is located). | 446 HTML coverage files are located (i.e. folder where index.html is located). |
| 447 """ | 447 """ |
| 448 with open(line_coverage_file) as f: | 448 with open(line_coverage_file) as f: |
| 449 potential_files_for_coverage = json.load(f) | 449 potential_files_for_coverage = json.load(f) |
| 450 files_for_coverage = {f: lines | 450 files_for_coverage = {f: lines |
| 451 for f, lines in potential_files_for_coverage.iteritems() | 451 for f, lines in potential_files_for_coverage.iteritems() |
| 452 if _EmmaCoverageStats.NeedsCoverage(f)} | 452 if _EmmaCoverageStats.NeedsCoverage(f)} |
| 453 if not files_for_coverage: | 453 |
| 454 coverage_results = {} |
| 455 if files_for_coverage: |
| 456 code_coverage = _EmmaCoverageStats(coverage_dir, files_for_coverage.keys()) |
| 457 coverage_results = code_coverage.GetCoverageDict( |
| 458 files_for_coverage) |
| 459 else: |
| 454 logging.info('No Java files requiring coverage were included in %s.', | 460 logging.info('No Java files requiring coverage were included in %s.', |
| 455 line_coverage_file) | 461 line_coverage_file) |
| 456 return | |
| 457 | |
| 458 code_coverage = _EmmaCoverageStats(coverage_dir, files_for_coverage.keys()) | |
| 459 coverage_results = code_coverage.GetCoverageDict( | |
| 460 files_for_coverage) | |
| 461 | 462 |
| 462 with open(out_file_path, 'w+') as out_status_file: | 463 with open(out_file_path, 'w+') as out_status_file: |
| 463 json.dump(coverage_results, out_status_file) | 464 json.dump(coverage_results, out_status_file) |
| 464 | 465 |
| 465 | 466 |
| 466 def main(): | 467 def main(): |
| 467 argparser = argparse.ArgumentParser() | 468 argparser = argparse.ArgumentParser() |
| 468 argparser.add_argument('--out', required=True, type=str, | 469 argparser.add_argument('--out', required=True, type=str, |
| 469 help='Report output file path.') | 470 help='Report output file path.') |
| 470 argparser.add_argument('--emma-dir', required=True, type=str, | 471 argparser.add_argument('--emma-dir', required=True, type=str, |
| 471 help='EMMA HTML report directory.') | 472 help='EMMA HTML report directory.') |
| 472 argparser.add_argument('--lines-for-coverage-file', required=True, type=str, | 473 argparser.add_argument('--lines-for-coverage-file', required=True, type=str, |
| 473 help='File containing a JSON object. Should contain a ' | 474 help='File containing a JSON object. Should contain a ' |
| 474 'dict mapping file names to lists of line numbers of ' | 475 'dict mapping file names to lists of line numbers of ' |
| 475 'code for which coverage information is desired.') | 476 'code for which coverage information is desired.') |
| 476 argparser.add_argument('-v', '--verbose', action='count', | 477 argparser.add_argument('-v', '--verbose', action='count', |
| 477 help='Print verbose log information.') | 478 help='Print verbose log information.') |
| 478 args = argparser.parse_args() | 479 args = argparser.parse_args() |
| 479 run_tests_helper.SetLogLevel(args.verbose) | 480 run_tests_helper.SetLogLevel(args.verbose) |
| 480 GenerateCoverageReport(args.lines_for_coverage_file, args.out, args.emma_dir) | 481 GenerateCoverageReport(args.lines_for_coverage_file, args.out, args.emma_dir) |
| 481 | 482 |
| 482 | 483 |
| 483 if __name__ == '__main__': | 484 if __name__ == '__main__': |
| 484 sys.exit(main()) | 485 sys.exit(main()) |
| OLD | NEW |