OLD | NEW |
1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 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 def CheckChange(input_api, output_api): | 10 def CheckChange(input_api, output_api): |
11 """Checks the memcheck suppressions files for bad data.""" | 11 """Checks the memcheck suppressions files for bad data.""" |
| 12 suppressions = {} |
12 errors = [] | 13 errors = [] |
| 14 # skip_next_line has 3 possible values: |
| 15 # - False: don't skip the next line. |
| 16 # - 'skip_suppression_name': the next line is a suppression name, skip. |
| 17 # - 'skip_param': the next line is a system call parameter error, skip. |
13 skip_next_line = False | 18 skip_next_line = False |
14 func_re = input_api.re.compile('[a-z_.]+\(.+\)$') | 19 func_re = input_api.re.compile('[a-z_.]+\(.+\)$') |
15 for f, line_num, line in input_api.RightHandSideLines(lambda x: | 20 for f, line_num, line in input_api.RightHandSideLines(lambda x: |
16 x.LocalPath().endswith('.txt')): | 21 x.LocalPath().endswith('.txt')): |
17 line = line.lstrip() | 22 line = line.lstrip() |
18 if line.startswith('#') or not line: | 23 if line.startswith('#') or not line: |
19 continue | 24 continue |
20 | 25 |
21 if skip_next_line: | 26 if skip_next_line: |
| 27 if skip_next_line == 'skip_suppression_name': |
| 28 if suppressions.has_key(line): |
| 29 errors.append('suppression with name "%s" at %s line %s has already ' |
| 30 'been defined at line %s' % (line, f.LocalPath(), |
| 31 line_num, |
| 32 suppressions[line][1])) |
| 33 else: |
| 34 suppressions[line] = (f, line_num) |
22 skip_next_line = False | 35 skip_next_line = False |
23 continue | 36 continue |
24 if line == '{' or line == "Memcheck:Param": | 37 if line == '{': |
25 skip_next_line = True | 38 skip_next_line = 'skip_suppression_name' |
26 continue | 39 continue |
| 40 if line == "Memcheck:Param": |
| 41 skip_next_line = 'skip_param' |
| 42 continue |
| 43 |
27 if (line.startswith('fun:') or line.startswith('obj:') or | 44 if (line.startswith('fun:') or line.startswith('obj:') or |
28 line.startswith('Memcheck:') or line == '}' or | 45 line.startswith('Memcheck:') or line == '}' or |
29 line == '...'): | 46 line == '...'): |
30 continue | 47 continue |
31 if func_re.match(line): | 48 if func_re.match(line): |
32 continue | 49 continue |
33 errors.append('"%s" is probably wrong: %s line %s' % (line, f.LocalPath(), | 50 errors.append('"%s" is probably wrong: %s line %s' % (line, f.LocalPath(), |
34 line_num)) | 51 line_num)) |
35 if errors: | 52 if errors: |
36 return [output_api.PresubmitError('\n'.join(errors))] | 53 return [output_api.PresubmitError('\n'.join(errors))] |
37 return [] | 54 return [] |
38 | 55 |
39 def CheckChangeOnUpload(input_api, output_api): | 56 def CheckChangeOnUpload(input_api, output_api): |
40 return CheckChange(input_api, output_api) | 57 return CheckChange(input_api, output_api) |
41 | 58 |
42 def CheckChangeOnCommit(input_api, output_api): | 59 def CheckChangeOnCommit(input_api, output_api): |
43 return CheckChange(input_api, output_api) | 60 return CheckChange(input_api, output_api) |
44 | 61 |
45 def GetPreferredTrySlaves(): | 62 def GetPreferredTrySlaves(): |
46 return ['linux_valgrind', 'mac_valgrind'] | 63 return ['linux_valgrind', 'mac_valgrind'] |
OLD | NEW |