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 | 10 import re |
11 | 11 |
12 def CheckChange(input_api, output_api): | 12 def CheckChange(input_api, output_api): |
13 """Checks the heapcheck suppressions files for bad data.""" | 13 """Checks the heapcheck suppressions files for bad data.""" |
14 sup_regex = re.compile('suppressions.*\.txt$') | 14 sup_regex = re.compile('suppressions.*\.txt$') |
15 suppressions = {} | 15 suppressions = {} |
16 errors = [] | 16 errors = [] |
17 check_for_heapcheck = False | 17 check_for_heapcheck = False |
18 skip_next_line = False | 18 skip_next_line = False |
19 for f in filter(lambda x: sup_regex.search(x.LocalPath()), | 19 for f in filter(lambda x: sup_regex.search(x.LocalPath()), |
20 input_api.AffectedFiles()): | 20 input_api.AffectedFiles()): |
21 for line, line_num in zip(f.NewContents(), | 21 for line, line_num in zip(f.NewContents(), |
22 xrange(1, len(f.NewContents()) + 1)): | 22 xrange(1, len(f.NewContents()) + 1)): |
23 line = line.lstrip() | 23 line = line.lstrip() |
24 if line.startswith('#') or not line: | 24 if line.startswith('#') or not line: |
25 continue | 25 continue |
26 | 26 |
27 if skip_next_line: | 27 if skip_next_line: |
| 28 if 'insert_a_suppression_name_here' in line: |
| 29 errors.append('"insert_a_suppression_name_here" is not a valid ' |
| 30 'suppression name') |
28 if suppressions.has_key(line): | 31 if suppressions.has_key(line): |
29 errors.append('suppression with name "%s" at %s line %s has already ' | 32 errors.append('suppression with name "%s" at %s line %s has already ' |
30 'been defined at line %s' % (line, f.LocalPath(), | 33 'been defined at line %s' % (line, f.LocalPath(), |
31 line_num, | 34 line_num, |
32 suppressions[line][1])) | 35 suppressions[line][1])) |
33 else: | 36 else: |
34 suppressions[line] = (f, line_num) | 37 suppressions[line] = (f, line_num) |
35 check_for_heapcheck = True | 38 check_for_heapcheck = True |
36 skip_next_line = False | 39 skip_next_line = False |
37 continue | 40 continue |
(...skipping 13 matching lines...) Expand all Loading... |
51 line_num)) | 54 line_num)) |
52 if errors: | 55 if errors: |
53 return [output_api.PresubmitError('\n'.join(errors))] | 56 return [output_api.PresubmitError('\n'.join(errors))] |
54 return [] | 57 return [] |
55 | 58 |
56 def CheckChangeOnUpload(input_api, output_api): | 59 def CheckChangeOnUpload(input_api, output_api): |
57 return CheckChange(input_api, output_api) | 60 return CheckChange(input_api, output_api) |
58 | 61 |
59 def CheckChangeOnCommit(input_api, output_api): | 62 def CheckChangeOnCommit(input_api, output_api): |
60 return CheckChange(input_api, output_api) | 63 return CheckChange(input_api, output_api) |
OLD | NEW |