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 """Generic presubmit checks that can be reused by other presubmit checks.""" | 5 """Generic presubmit checks that can be reused by other presubmit checks.""" |
6 | 6 |
7 import os as _os | 7 import os as _os |
8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) | 8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) |
9 | 9 |
10 # Justifications for each filter: | |
11 # | |
12 # - build/include : Too many; fix in the future. | |
13 # - build/include_order : Not happening; #ifdefed includes. | |
14 # - build/namespace : I'm surprised by how often we violate this rule. | |
15 # - readability/casting : Mistakes a whole bunch of function pointer. | |
16 # - runtime/int : Can be fixed long term; volume of errors too high | |
17 # - runtime/virtual : Broken now, but can be fixed in the future? | |
18 # - whitespace/braces : We have a lot of explicit scoping in chrome code. | |
19 # - readability/inheritance : Temporary, while the OVERRIDE and FINAL fixup | |
20 # is in progress. | |
21 DEFAULT_LINT_FILTERS = [ | |
tfarina
2014/12/10 00:36:11
Looks like this is wrong:
File "/home/tfarina/dep
Dirk Pranke
2014/12/10 02:13:18
The original thing was a single comma-separated st
Dirk Pranke
2014/12/10 02:15:18
Er, I mean, leave this as a list, and change the _
tfarina
2014/12/10 03:40:26
Done.
| |
22 '-build/include', | |
23 '-build/include_order', | |
24 '-build/namespace', | |
25 '-readability/casting', | |
26 '-runtime/int', | |
27 '-runtime/virtual', | |
28 '-whitespace/braces', | |
29 '-readability/inheritance' | |
30 ] | |
10 | 31 |
11 ### Description checks | 32 ### Description checks |
12 | 33 |
13 def CheckChangeHasTestField(input_api, output_api): | 34 def CheckChangeHasTestField(input_api, output_api): |
14 """Requires that the changelist have a TEST= field.""" | 35 """Requires that the changelist have a TEST= field.""" |
15 if input_api.change.TEST: | 36 if input_api.change.TEST: |
16 return [] | 37 return [] |
17 else: | 38 else: |
18 return [output_api.PresubmitNotifyResult( | 39 return [output_api.PresubmitNotifyResult( |
19 'If this change requires manual test instructions to QA team, add ' | 40 'If this change requires manual test instructions to QA team, add ' |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 file_filter = lambda x : x | 104 file_filter = lambda x : x |
84 keyword = 'DO NOT ''SUBMIT' | 105 keyword = 'DO NOT ''SUBMIT' |
85 errors = _FindNewViolationsOfRule(lambda _, line : keyword not in line, | 106 errors = _FindNewViolationsOfRule(lambda _, line : keyword not in line, |
86 input_api, file_filter) | 107 input_api, file_filter) |
87 text = '\n'.join('Found %s in %s' % (keyword, loc) for loc in errors) | 108 text = '\n'.join('Found %s in %s' % (keyword, loc) for loc in errors) |
88 if text: | 109 if text: |
89 return [output_api.PresubmitError(text)] | 110 return [output_api.PresubmitError(text)] |
90 return [] | 111 return [] |
91 | 112 |
92 | 113 |
93 def CheckChangeLintsClean(input_api, output_api, source_file_filter=None): | 114 def CheckChangeLintsClean(input_api, output_api, source_file_filter=None, |
115 lint_filters=None): | |
94 """Checks that all '.cc' and '.h' files pass cpplint.py.""" | 116 """Checks that all '.cc' and '.h' files pass cpplint.py.""" |
95 _RE_IS_TEST = input_api.re.compile(r'.*tests?.(cc|h)$') | 117 _RE_IS_TEST = input_api.re.compile(r'.*tests?.(cc|h)$') |
96 result = [] | 118 result = [] |
97 | 119 |
98 cpplint = input_api.cpplint | 120 cpplint = input_api.cpplint |
99 # Access to a protected member _XX of a client class | 121 # Access to a protected member _XX of a client class |
100 # pylint: disable=W0212 | 122 # pylint: disable=W0212 |
101 cpplint._cpplint_state.ResetErrorCounts() | 123 cpplint._cpplint_state.ResetErrorCounts() |
102 | 124 |
103 # Justifications for each filter: | 125 lint_filters = lint_filters or DEFAULT_LINT_FILTERS |
104 # | 126 cpplint._SetFilters(lint_filters) |
105 # - build/include : Too many; fix in the future. | |
106 # - build/include_order : Not happening; #ifdefed includes. | |
107 # - build/namespace : I'm surprised by how often we violate this rule. | |
108 # - readability/casting : Mistakes a whole bunch of function pointer. | |
109 # - runtime/int : Can be fixed long term; volume of errors too high | |
110 # - runtime/virtual : Broken now, but can be fixed in the future? | |
111 # - whitespace/braces : We have a lot of explicit scoping in chrome code. | |
112 # - readability/inheritance : Temporary, while the OVERRIDE and FINAL fixup | |
113 # is in progress. | |
114 cpplint._SetFilters('-build/include,-build/include_order,-build/namespace,' | |
115 '-readability/casting,-runtime/int,-runtime/virtual,' | |
116 '-whitespace/braces,-readability/inheritance') | |
117 | 127 |
118 # We currently are more strict with normal code than unit tests; 4 and 5 are | 128 # We currently are more strict with normal code than unit tests; 4 and 5 are |
119 # the verbosity level that would normally be passed to cpplint.py through | 129 # the verbosity level that would normally be passed to cpplint.py through |
120 # --verbose=#. Hopefully, in the future, we can be more verbose. | 130 # --verbose=#. Hopefully, in the future, we can be more verbose. |
121 files = [f.AbsoluteLocalPath() for f in | 131 files = [f.AbsoluteLocalPath() for f in |
122 input_api.AffectedSourceFiles(source_file_filter)] | 132 input_api.AffectedSourceFiles(source_file_filter)] |
123 for file_name in files: | 133 for file_name in files: |
124 if _RE_IS_TEST.match(file_name): | 134 if _RE_IS_TEST.match(file_name): |
125 level = 5 | 135 level = 5 |
126 else: | 136 else: |
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1125 for f in affected_files: | 1135 for f in affected_files: |
1126 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] | 1136 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] |
1127 rc = gn.main(cmd) | 1137 rc = gn.main(cmd) |
1128 if rc == 2: | 1138 if rc == 2: |
1129 warnings.append(output_api.PresubmitPromptWarning( | 1139 warnings.append(output_api.PresubmitPromptWarning( |
1130 '%s requires formatting. Please run `gn format --in-place %s`.' % ( | 1140 '%s requires formatting. Please run `gn format --in-place %s`.' % ( |
1131 f.AbsoluteLocalPath(), f.LocalPath()))) | 1141 f.AbsoluteLocalPath(), f.LocalPath()))) |
1132 # It's just a warning, so ignore other types of failures assuming they'll be | 1142 # It's just a warning, so ignore other types of failures assuming they'll be |
1133 # caught elsewhere. | 1143 # caught elsewhere. |
1134 return warnings | 1144 return warnings |
OLD | NEW |