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
3 # found in the LICENSE file.
6 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
7 for more details on the presubmit API built into gcl.
12 def CheckChange(input_api
, output_api
):
13 """Checks the heapcheck suppressions files for bad data."""
14 sup_regex
= re
.compile('suppressions.*\.txt$')
17 check_for_heapcheck
= False
18 skip_next_line
= False
19 for f
in filter(lambda x
: sup_regex
.search(x
.LocalPath()),
20 input_api
.AffectedFiles()):
21 for line
, line_num
in zip(f
.NewContents(),
22 xrange(1, len(f
.NewContents()) + 1)):
24 if line
.startswith('#') or not line
:
28 if 'insert_a_suppression_name_here' in line
:
29 errors
.append('"insert_a_suppression_name_here" is not a valid '
31 if suppressions
.has_key(line
):
32 errors
.append('suppression with name "%s" at %s line %s has already '
33 'been defined at line %s' % (line
, f
.LocalPath(),
35 suppressions
[line
][1]))
37 suppressions
[line
] = (f
, line_num
)
38 check_for_heapcheck
= True
39 skip_next_line
= False
41 if check_for_heapcheck
:
42 if not line
== 'Heapcheck:Leak':
43 errors
.append('"%s" should be "Heapcheck:Leak" in %s line %s' %
44 (line
, f
.LocalPath(), line_num
))
45 check_for_heapcheck
= False;
49 if (line
.startswith('fun:') or line
.startswith('obj:') or
50 line
== 'Heapcheck:Leak' or line
== '}' or
53 errors
.append('"%s" is probably wrong: %s line %s' % (line
, f
.LocalPath(),
56 return [output_api
.PresubmitError('\n'.join(errors
))]
59 def CheckChangeOnUpload(input_api
, output_api
):
60 return CheckChange(input_api
, output_api
)
62 def CheckChangeOnCommit(input_api
, output_api
):
63 return CheckChange(input_api
, output_api
)