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)$',)
14 CC_PERF_TEST
=(r
'^.*_perftest.*\.(cc|h)$',)
16 def CheckAsserts(input_api
, output_api
, white_list
=CC_SOURCE_FILES
, black_list
=None):
17 black_list
= tuple(black_list
or input_api
.DEFAULT_BLACK_LIST
)
18 source_file_filter
= lambda x
: input_api
.FilterSourceFile(x
, white_list
, black_list
)
23 for f
in input_api
.AffectedSourceFiles(source_file_filter
):
24 contents
= input_api
.ReadFile(f
, 'rb')
25 # WebKit ASSERT() is not allowed.
26 if re
.search(r
"\bASSERT\(", contents
):
27 assert_files
.append(f
.LocalPath())
28 # WebKit ASSERT_NOT_REACHED() is not allowed.
29 if re
.search(r
"ASSERT_NOT_REACHED\(", contents
):
30 notreached_files
.append(f
.LocalPath())
33 return [output_api
.PresubmitError(
34 'These files use ASSERT instead of using DCHECK:',
37 return [output_api
.PresubmitError(
38 'These files use ASSERT_NOT_REACHED instead of using NOTREACHED:',
39 items
=notreached_files
)]
42 def CheckSpamLogging(input_api
, output_api
, white_list
=CC_SOURCE_FILES
, black_list
=None):
43 black_list
= tuple(black_list
or input_api
.DEFAULT_BLACK_LIST
)
44 source_file_filter
= lambda x
: input_api
.FilterSourceFile(x
, white_list
, black_list
)
49 for f
in input_api
.AffectedSourceFiles(source_file_filter
):
50 contents
= input_api
.ReadFile(f
, 'rb')
51 if re
.search(r
"\bD?LOG\s*\(\s*INFO\s*\)", contents
):
52 log_info
.append(f
.LocalPath())
53 if re
.search(r
"\bf?printf\(", contents
):
54 printf
.append(f
.LocalPath())
57 return [output_api
.PresubmitError(
58 'These files spam the console log with LOG(INFO):',
61 return [output_api
.PresubmitError(
62 'These files spam the console log with printf/fprintf:',
67 def CheckChangeOnUpload(input_api
, output_api
):
69 results
+= CheckAsserts(input_api
, output_api
)
70 results
+= CheckSpamLogging(input_api
, output_api
, black_list
=CC_PERF_TEST
)
73 def GetPreferredTrySlaves(project
, change
):