Evaluate the Chromium checkout for pattern matches.
(output_file=None)
| 667 | |
| 668 | |
| 669 | def check_pattern_matches(output_file=None): |
| 670 | """ Evaluate the Chromium checkout for pattern matches. """ |
| 671 | config = read_update_file() |
| 672 | if config is None: |
| 673 | msg("Skipping Chromium pattern matching.") |
| 674 | return |
| 675 | |
| 676 | if 'patterns' in config: |
| 677 | if output_file is None: |
| 678 | fp = sys.stdout |
| 679 | else: |
| 680 | msg('Writing %s' % output_file) |
| 681 | fp = open(output_file, 'w') |
| 682 | |
| 683 | has_output = False |
| 684 | for entry in config['patterns']: |
| 685 | msg("Evaluating pattern: %s" % entry['pattern']) |
| 686 | |
| 687 | # Read patterns from a file to avoid formatting problems. |
| 688 | pattern_handle, pattern_file = tempfile.mkstemp() |
| 689 | os.write(pattern_handle, entry['pattern']) |
| 690 | os.close(pattern_handle) |
| 691 | |
| 692 | cmd = '%s grep -n -f %s' % (git_exe, pattern_file) |
| 693 | result = exec_cmd(cmd, chromium_src_dir) |
| 694 | os.remove(pattern_file) |
| 695 | |
| 696 | if result['out'] != '': |
| 697 | write_msg = True |
| 698 | re_exclude = re.compile( |
| 699 | entry['exclude_matches']) if 'exclude_matches' in entry else None |
| 700 | |
| 701 | for line in result['out'].split('\n'): |
| 702 | line = line.strip() |
| 703 | if len(line) == 0: |
| 704 | continue |
| 705 | skip = not re_exclude is None and re_exclude.match(line) != None |
| 706 | if not skip: |
| 707 | if write_msg: |
| 708 | if has_output: |
| 709 | fp.write('\n') |
| 710 | fp.write('!!!! WARNING: FOUND PATTERN: %s\n' % entry['pattern']) |
| 711 | if 'message' in entry: |
| 712 | fp.write(entry['message'] + '\n') |
| 713 | fp.write('\n') |
| 714 | write_msg = False |
| 715 | fp.write(line + '\n') |
| 716 | has_output = True |
| 717 | |
| 718 | if not output_file is None: |
| 719 | if has_output: |
| 720 | msg('ERROR Matches found. See %s for output.' % out_file) |
| 721 | else: |
| 722 | fp.write('Good news! No matches.\n') |
| 723 | fp.close() |
| 724 | |
| 725 | if has_output: |
| 726 | # Don't continue when we know the build will be wrong. |
no test coverage detected