Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | #!/usr/bin/env python |
michael@0 | 2 | # Copyright (c) 2012 The LibYuv Project Authors. All rights reserved. |
michael@0 | 3 | # |
michael@0 | 4 | # Use of this source code is governed by a BSD-style license |
michael@0 | 5 | # that can be found in the LICENSE file in the root of the source |
michael@0 | 6 | # tree. An additional intellectual property rights grant can be found |
michael@0 | 7 | # in the file PATENTS. All contributing project authors may |
michael@0 | 8 | # be found in the AUTHORS file in the root of the source tree. |
michael@0 | 9 | |
michael@0 | 10 | """ |
michael@0 | 11 | Copied from Chrome's src/tools/valgrind/memcheck/PRESUBMIT.py |
michael@0 | 12 | |
michael@0 | 13 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
michael@0 | 14 | for more details on the presubmit API built into gcl. |
michael@0 | 15 | """ |
michael@0 | 16 | |
michael@0 | 17 | import os |
michael@0 | 18 | import re |
michael@0 | 19 | import sys |
michael@0 | 20 | |
michael@0 | 21 | def CheckChange(input_api, output_api): |
michael@0 | 22 | """Checks the memcheck suppressions files for bad data.""" |
michael@0 | 23 | |
michael@0 | 24 | # Add the path to the Chrome valgrind dir to the import path: |
michael@0 | 25 | tools_vg_path = os.path.join(input_api.PresubmitLocalPath(), '..', '..', |
michael@0 | 26 | 'valgrind') |
michael@0 | 27 | sys.path.append(tools_vg_path) |
michael@0 | 28 | import suppressions |
michael@0 | 29 | |
michael@0 | 30 | sup_regex = re.compile('suppressions.*\.txt$') |
michael@0 | 31 | suppressions = {} |
michael@0 | 32 | errors = [] |
michael@0 | 33 | check_for_memcheck = False |
michael@0 | 34 | # skip_next_line has 3 possible values: |
michael@0 | 35 | # - False: don't skip the next line. |
michael@0 | 36 | # - 'skip_suppression_name': the next line is a suppression name, skip. |
michael@0 | 37 | # - 'skip_param': the next line is a system call parameter error, skip. |
michael@0 | 38 | skip_next_line = False |
michael@0 | 39 | for f in filter(lambda x: sup_regex.search(x.LocalPath()), |
michael@0 | 40 | input_api.AffectedFiles()): |
michael@0 | 41 | for line, line_num in zip(f.NewContents(), |
michael@0 | 42 | xrange(1, len(f.NewContents()) + 1)): |
michael@0 | 43 | line = line.lstrip() |
michael@0 | 44 | if line.startswith('#') or not line: |
michael@0 | 45 | continue |
michael@0 | 46 | |
michael@0 | 47 | if skip_next_line: |
michael@0 | 48 | if skip_next_line == 'skip_suppression_name': |
michael@0 | 49 | if 'insert_a_suppression_name_here' in line: |
michael@0 | 50 | errors.append('"insert_a_suppression_name_here" is not a valid ' |
michael@0 | 51 | 'suppression name') |
michael@0 | 52 | if suppressions.has_key(line): |
michael@0 | 53 | if f.LocalPath() == suppressions[line][1]: |
michael@0 | 54 | errors.append('suppression with name "%s" at %s line %s ' |
michael@0 | 55 | 'has already been defined at line %s' % |
michael@0 | 56 | (line, f.LocalPath(), line_num, |
michael@0 | 57 | suppressions[line][1])) |
michael@0 | 58 | else: |
michael@0 | 59 | errors.append('suppression with name "%s" at %s line %s ' |
michael@0 | 60 | 'has already been defined at %s line %s' % |
michael@0 | 61 | (line, f.LocalPath(), line_num, |
michael@0 | 62 | suppressions[line][0], suppressions[line][1])) |
michael@0 | 63 | else: |
michael@0 | 64 | suppressions[line] = (f, line_num) |
michael@0 | 65 | check_for_memcheck = True; |
michael@0 | 66 | skip_next_line = False |
michael@0 | 67 | continue |
michael@0 | 68 | if check_for_memcheck: |
michael@0 | 69 | if not line.startswith('Memcheck:'): |
michael@0 | 70 | errors.append('"%s" should be "Memcheck:..." in %s line %s' % |
michael@0 | 71 | (line, f.LocalPath(), line_num)) |
michael@0 | 72 | check_for_memcheck = False; |
michael@0 | 73 | if line == '{': |
michael@0 | 74 | skip_next_line = 'skip_suppression_name' |
michael@0 | 75 | continue |
michael@0 | 76 | if line == "Memcheck:Param": |
michael@0 | 77 | skip_next_line = 'skip_param' |
michael@0 | 78 | continue |
michael@0 | 79 | |
michael@0 | 80 | if (line.startswith('fun:') or line.startswith('obj:') or |
michael@0 | 81 | line.startswith('Memcheck:') or line == '}' or |
michael@0 | 82 | line == '...'): |
michael@0 | 83 | continue |
michael@0 | 84 | errors.append('"%s" is probably wrong: %s line %s' % (line, f.LocalPath(), |
michael@0 | 85 | line_num)) |
michael@0 | 86 | if errors: |
michael@0 | 87 | return [output_api.PresubmitError('\n'.join(errors))] |
michael@0 | 88 | return [] |
michael@0 | 89 | |
michael@0 | 90 | def CheckChangeOnUpload(input_api, output_api): |
michael@0 | 91 | return CheckChange(input_api, output_api) |
michael@0 | 92 | |
michael@0 | 93 | def CheckChangeOnCommit(input_api, output_api): |
michael@0 | 94 | return CheckChange(input_api, output_api) |
michael@0 | 95 | |
michael@0 | 96 | def GetPreferredTrySlaves(): |
michael@0 | 97 | # We don't have any memcheck slaves yet, so there's no use for this method. |
michael@0 | 98 | # When we have, the slave name(s) should be put into this list. |
michael@0 | 99 | return [] |