Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / cc / PRESUBMIT.py
blobcf9737e59f158512e58aad36de62c841bb461515
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.
9 """
11 import re
13 CC_SOURCE_FILES=(r'^cc/.*\.(cc|h)$',)
14 CC_PERF_TEST =(r'^.*_perftest.*\.(cc|h)$',)
16 def CheckChangeLintsClean(input_api, output_api):
17 import cpplint
18 cpplint._cpplint_state.ResetErrorCounts() # reset global state
19 source_filter = lambda x: input_api.FilterSourceFile(
20 x, white_list=CC_SOURCE_FILES, black_list=None)
21 files = [f.AbsoluteLocalPath() for f in
22 input_api.AffectedSourceFiles(source_filter)]
23 level = 1 # strict, but just warn
25 for file_name in files:
26 cpplint.ProcessFile(file_name, level)
28 if not cpplint._cpplint_state.error_count:
29 return []
31 return [output_api.PresubmitPromptWarning(
32 'Changelist failed cpplint.py check.')]
34 def CheckAsserts(input_api, output_api, white_list=CC_SOURCE_FILES, black_list=None):
35 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST)
36 source_file_filter = lambda x: input_api.FilterSourceFile(x, white_list, black_list)
38 assert_files = []
39 notreached_files = []
41 for f in input_api.AffectedSourceFiles(source_file_filter):
42 contents = input_api.ReadFile(f, 'rb')
43 # WebKit ASSERT() is not allowed.
44 if re.search(r"\bASSERT\(", contents):
45 assert_files.append(f.LocalPath())
46 # WebKit ASSERT_NOT_REACHED() is not allowed.
47 if re.search(r"ASSERT_NOT_REACHED\(", contents):
48 notreached_files.append(f.LocalPath())
50 if assert_files:
51 return [output_api.PresubmitError(
52 'These files use ASSERT instead of using DCHECK:',
53 items=assert_files)]
54 if notreached_files:
55 return [output_api.PresubmitError(
56 'These files use ASSERT_NOT_REACHED instead of using NOTREACHED:',
57 items=notreached_files)]
58 return []
60 def CheckSpamLogging(input_api, output_api, white_list=CC_SOURCE_FILES, black_list=None):
61 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST)
62 source_file_filter = lambda x: input_api.FilterSourceFile(x, white_list, black_list)
64 log_info = []
65 printf = []
67 for f in input_api.AffectedSourceFiles(source_file_filter):
68 contents = input_api.ReadFile(f, 'rb')
69 if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents):
70 log_info.append(f.LocalPath())
71 if re.search(r"\bf?printf\(", contents):
72 printf.append(f.LocalPath())
74 if log_info:
75 return [output_api.PresubmitError(
76 'These files spam the console log with LOG(INFO):',
77 items=log_info)]
78 if printf:
79 return [output_api.PresubmitError(
80 'These files spam the console log with printf/fprintf:',
81 items=printf)]
82 return []
85 def CheckChangeOnUpload(input_api, output_api):
86 results = []
87 results += CheckAsserts(input_api, output_api)
88 results += CheckSpamLogging(input_api, output_api, black_list=CC_PERF_TEST)
89 results += CheckChangeLintsClean(input_api, output_api)
90 return results
92 def GetPreferredTrySlaves(project, change):
93 return [
94 'linux_layout_rel',