1 # Copyright (c) 2012 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.
5 """Top-level presubmit script for cc.
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
8 details on the presubmit API built into gcl.
13 CC_SOURCE_FILES
=(r
'^cc/.*\.(cc|h)$',)
15 def CheckAsserts(input_api
, output_api
, white_list
=CC_SOURCE_FILES
, black_list
=None):
16 black_list
= tuple(black_list
or input_api
.DEFAULT_BLACK_LIST
)
17 source_file_filter
= lambda x
: input_api
.FilterSourceFile(x
, white_list
, black_list
)
22 for f
in input_api
.AffectedSourceFiles(source_file_filter
):
23 contents
= input_api
.ReadFile(f
, 'rb')
24 # WebKit ASSERT() is not allowed.
25 if re
.search(r
"\bASSERT\(", contents
):
26 assert_files
.append(f
.LocalPath())
27 # WebKit ASSERT_NOT_REACHED() is not allowed.
28 if re
.search(r
"ASSERT_NOT_REACHED\(", contents
):
29 notreached_files
.append(f
.LocalPath())
32 return [output_api
.PresubmitError(
33 'These files use ASSERT instead of using DCHECK:',
36 return [output_api
.PresubmitError(
37 'These files use ASSERT_NOT_REACHED instead of using NOTREACHED:',
38 items
=notreached_files
)]
41 def CheckChangeOnUpload(input_api
, output_api
):
43 results
+= CheckAsserts(input_api
, output_api
)
46 def GetPreferredTrySlaves(project
, change
):