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 | 14 |
15 def CheckAsserts(input_api, output_api, white_list=CC_SOURCE_FILES, black_list=N
one): | 15 def CheckAsserts(input_api, output_api, white_list=CC_SOURCE_FILES, black_list=N
one): |
16 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) | 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) | 17 source_file_filter = lambda x: input_api.FilterSourceFile(x, white_list, black
_list) |
18 | 18 |
19 assert_files = [] | 19 assert_files = [] |
20 notreached_files = [] | 20 notreached_files = [] |
21 | 21 |
22 for f in input_api.AffectedSourceFiles(source_file_filter): | 22 for f in input_api.AffectedSourceFiles(source_file_filter): |
23 contents = input_api.ReadFile(f, 'rb') | 23 contents = input_api.ReadFile(f, 'rb') |
24 # WebKit ASSERT() is not allowed. | 24 # WebKit ASSERT() is not allowed. |
25 if re.search(r"ASSERT\(", contents): | 25 if re.search(r"\bASSERT\(", contents): |
26 assert_files.append(f.LocalPath()) | 26 assert_files.append(f.LocalPath()) |
27 # WebKit ASSERT_NOT_REACHED() is not allowed. | 27 # WebKit ASSERT_NOT_REACHED() is not allowed. |
28 if re.search(r"ASSERT_NOT_REACHED\(", contents): | 28 if re.search(r"ASSERT_NOT_REACHED\(", contents): |
29 notreached_files.append(f.LocalPath()) | 29 notreached_files.append(f.LocalPath()) |
30 | 30 |
31 if assert_files: | 31 if assert_files: |
32 return [output_api.PresubmitError( | 32 return [output_api.PresubmitError( |
33 'These files use ASSERT instead of using DCHECK:', | 33 'These files use ASSERT instead of using DCHECK:', |
34 items=assert_files)] | 34 items=assert_files)] |
35 if notreached_files: | 35 if notreached_files: |
36 return [output_api.PresubmitError( | 36 return [output_api.PresubmitError( |
37 'These files use ASSERT_NOT_REACHED instead of using NOTREACHED:', | 37 'These files use ASSERT_NOT_REACHED instead of using NOTREACHED:', |
38 items=notreached_files)] | 38 items=notreached_files)] |
39 return [] | 39 return [] |
40 | 40 |
41 def CheckChangeOnUpload(input_api, output_api): | 41 def CheckChangeOnUpload(input_api, output_api): |
42 results = [] | 42 results = [] |
43 results += CheckAsserts(input_api, output_api) | 43 results += CheckAsserts(input_api, output_api) |
44 return results | 44 return results |
45 | 45 |
46 def GetPreferredTrySlaves(project, change): | 46 def GetPreferredTrySlaves(project, change): |
47 return [ | 47 return [ |
48 'linux_layout_rel', | 48 'linux_layout_rel', |
49 ] | 49 ] |
OLD | NEW |