OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 """Top-level presubmit script for cc. | 5 """Top-level presubmit script for cc. |
6 | 6 |
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for | 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for |
8 details on the presubmit API built into gcl. | 8 details on the presubmit API built into gcl. |
9 """ | 9 """ |
10 | 10 |
11 import re | 11 import re |
12 | 12 |
13 CC_SOURCE_FILES=(r'^cc/.*\.(cc|h)$',) | 13 CC_SOURCE_FILES=(r'^cc/.*\.(cc|h)$',) |
14 CC_PERF_TEST =(r'^.*_perftest.*\.(cc|h)$',) | 14 CC_PERF_TEST =(r'^.*_perftest.*\.(cc|h)$',) |
15 | 15 |
| 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 |
| 24 |
| 25 for file_name in files: |
| 26 cpplint.ProcessFile(file_name, level) |
| 27 |
| 28 if not cpplint._cpplint_state.error_count: |
| 29 return [] |
| 30 |
| 31 return [output_api.PresubmitPromptWarning( |
| 32 'Changelist failed cpplint.py check.')] |
| 33 |
16 def CheckAsserts(input_api, output_api, white_list=CC_SOURCE_FILES, black_list=N
one): | 34 def CheckAsserts(input_api, output_api, white_list=CC_SOURCE_FILES, black_list=N
one): |
17 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) | 35 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) | 36 source_file_filter = lambda x: input_api.FilterSourceFile(x, white_list, black
_list) |
19 | 37 |
20 assert_files = [] | 38 assert_files = [] |
21 notreached_files = [] | 39 notreached_files = [] |
22 | 40 |
23 for f in input_api.AffectedSourceFiles(source_file_filter): | 41 for f in input_api.AffectedSourceFiles(source_file_filter): |
24 contents = input_api.ReadFile(f, 'rb') | 42 contents = input_api.ReadFile(f, 'rb') |
25 # WebKit ASSERT() is not allowed. | 43 # WebKit ASSERT() is not allowed. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 return [output_api.PresubmitError( | 79 return [output_api.PresubmitError( |
62 'These files spam the console log with printf/fprintf:', | 80 'These files spam the console log with printf/fprintf:', |
63 items=printf)] | 81 items=printf)] |
64 return [] | 82 return [] |
65 | 83 |
66 | 84 |
67 def CheckChangeOnUpload(input_api, output_api): | 85 def CheckChangeOnUpload(input_api, output_api): |
68 results = [] | 86 results = [] |
69 results += CheckAsserts(input_api, output_api) | 87 results += CheckAsserts(input_api, output_api) |
70 results += CheckSpamLogging(input_api, output_api, black_list=CC_PERF_TEST) | 88 results += CheckSpamLogging(input_api, output_api, black_list=CC_PERF_TEST) |
| 89 results += CheckChangeLintsClean(input_api, output_api) |
71 return results | 90 return results |
72 | 91 |
73 def GetPreferredTrySlaves(project, change): | 92 def GetPreferredTrySlaves(project, change): |
74 return [ | 93 return [ |
75 'linux_layout_rel', | 94 'linux_layout_rel', |
76 ] | 95 ] |
OLD | NEW |