OLD | NEW |
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """ | 5 """ |
6 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 6 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
7 for more details on the presubmit API built into gcl. | 7 for more details on the presubmit API built into gcl. |
8 """ | 8 """ |
9 | 9 |
| 10 import re |
| 11 |
10 def CheckChange(input_api, output_api): | 12 def CheckChange(input_api, output_api): |
11 """Checks the heapcheck suppressions files for bad data.""" | 13 """Checks the heapcheck suppressions files for bad data.""" |
| 14 sup_regex = re.compile('suppressions.*\.txt$') |
12 suppressions = {} | 15 suppressions = {} |
13 errors = [] | 16 errors = [] |
14 check_for_heapcheck = False | 17 check_for_heapcheck = False |
15 skip_next_line = False | 18 skip_next_line = False |
16 for f in filter(lambda x: x.LocalPath().endswith('.txt'), | 19 for f in filter(lambda x: sup_regex.search(x.LocalPath()), |
17 input_api.AffectedFiles()): | 20 input_api.AffectedFiles()): |
18 for line, line_num in zip(f.NewContents(), | 21 for line, line_num in zip(f.NewContents(), |
19 xrange(1, len(f.NewContents()) + 1)): | 22 xrange(1, len(f.NewContents()) + 1)): |
20 | |
21 line = line.lstrip() | 23 line = line.lstrip() |
22 if line.startswith('#') or not line: | 24 if line.startswith('#') or not line: |
23 continue | 25 continue |
24 | 26 |
25 if skip_next_line: | 27 if skip_next_line: |
26 if suppressions.has_key(line): | 28 if suppressions.has_key(line): |
27 errors.append('suppression with name "%s" at %s line %s has already ' | 29 errors.append('suppression with name "%s" at %s line %s has already ' |
28 'been defined at line %s' % (line, f.LocalPath(), | 30 'been defined at line %s' % (line, f.LocalPath(), |
29 line_num, | 31 line_num, |
30 suppressions[line][1])) | 32 suppressions[line][1])) |
(...skipping 18 matching lines...) Expand all Loading... |
49 line_num)) | 51 line_num)) |
50 if errors: | 52 if errors: |
51 return [output_api.PresubmitError('\n'.join(errors))] | 53 return [output_api.PresubmitError('\n'.join(errors))] |
52 return [] | 54 return [] |
53 | 55 |
54 def CheckChangeOnUpload(input_api, output_api): | 56 def CheckChangeOnUpload(input_api, output_api): |
55 return CheckChange(input_api, output_api) | 57 return CheckChange(input_api, output_api) |
56 | 58 |
57 def CheckChangeOnCommit(input_api, output_api): | 59 def CheckChangeOnCommit(input_api, output_api): |
58 return CheckChange(input_api, output_api) | 60 return CheckChange(input_api, output_api) |
OLD | NEW |