| 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: | 10 # Justifications for each filter: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 '-build/include', | 22 '-build/include', |
| 23 '-build/include_order', | 23 '-build/include_order', |
| 24 '-build/namespace', | 24 '-build/namespace', |
| 25 '-readability/casting', | 25 '-readability/casting', |
| 26 '-runtime/int', | 26 '-runtime/int', |
| 27 '-runtime/virtual', | 27 '-runtime/virtual', |
| 28 '-whitespace/braces', | 28 '-whitespace/braces', |
| 29 '-readability/inheritance' | 29 '-readability/inheritance' |
| 30 ] | 30 ] |
| 31 | 31 |
| 32 # These filters will always be removed, even if the caller specifies a filter |
| 33 # set, as they are problematic or broken in some way. |
| 34 # |
| 35 # Justifications for each filter: |
| 36 # - build/c++11 : Rvalue ref checks are unreliable (false positives), |
| 37 # include file and feature blacklists are |
| 38 # google3-specific. |
| 39 BLACKLIST_LINT_FILTERS = [ |
| 40 '-build/c++11', |
| 41 ] |
| 42 |
| 32 ### Description checks | 43 ### Description checks |
| 33 | 44 |
| 34 def CheckChangeHasTestField(input_api, output_api): | 45 def CheckChangeHasTestField(input_api, output_api): |
| 35 """Requires that the changelist have a TEST= field.""" | 46 """Requires that the changelist have a TEST= field.""" |
| 36 if input_api.change.TEST: | 47 if input_api.change.TEST: |
| 37 return [] | 48 return [] |
| 38 else: | 49 else: |
| 39 return [output_api.PresubmitNotifyResult( | 50 return [output_api.PresubmitNotifyResult( |
| 40 'If this change requires manual test instructions to QA team, add ' | 51 'If this change requires manual test instructions to QA team, add ' |
| 41 'TEST=[instructions].')] | 52 'TEST=[instructions].')] |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 """Checks that all '.cc' and '.h' files pass cpplint.py.""" | 127 """Checks that all '.cc' and '.h' files pass cpplint.py.""" |
| 117 _RE_IS_TEST = input_api.re.compile(r'.*tests?.(cc|h)$') | 128 _RE_IS_TEST = input_api.re.compile(r'.*tests?.(cc|h)$') |
| 118 result = [] | 129 result = [] |
| 119 | 130 |
| 120 cpplint = input_api.cpplint | 131 cpplint = input_api.cpplint |
| 121 # Access to a protected member _XX of a client class | 132 # Access to a protected member _XX of a client class |
| 122 # pylint: disable=W0212 | 133 # pylint: disable=W0212 |
| 123 cpplint._cpplint_state.ResetErrorCounts() | 134 cpplint._cpplint_state.ResetErrorCounts() |
| 124 | 135 |
| 125 lint_filters = lint_filters or DEFAULT_LINT_FILTERS | 136 lint_filters = lint_filters or DEFAULT_LINT_FILTERS |
| 137 lint_filters.extend(BLACKLIST_LINT_FILTERS) |
| 126 cpplint._SetFilters(','.join(lint_filters)) | 138 cpplint._SetFilters(','.join(lint_filters)) |
| 127 | 139 |
| 128 # We currently are more strict with normal code than unit tests; 4 and 5 are | 140 # We currently are more strict with normal code than unit tests; 4 and 5 are |
| 129 # the verbosity level that would normally be passed to cpplint.py through | 141 # the verbosity level that would normally be passed to cpplint.py through |
| 130 # --verbose=#. Hopefully, in the future, we can be more verbose. | 142 # --verbose=#. Hopefully, in the future, we can be more verbose. |
| 131 files = [f.AbsoluteLocalPath() for f in | 143 files = [f.AbsoluteLocalPath() for f in |
| 132 input_api.AffectedSourceFiles(source_file_filter)] | 144 input_api.AffectedSourceFiles(source_file_filter)] |
| 133 for file_name in files: | 145 for file_name in files: |
| 134 if _RE_IS_TEST.match(file_name): | 146 if _RE_IS_TEST.match(file_name): |
| 135 level = 5 | 147 level = 5 |
| (...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 for f in affected_files: | 1130 for f in affected_files: |
| 1119 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] | 1131 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] |
| 1120 rc = gn.main(cmd) | 1132 rc = gn.main(cmd) |
| 1121 if rc == 2: | 1133 if rc == 2: |
| 1122 warnings.append(output_api.PresubmitPromptWarning( | 1134 warnings.append(output_api.PresubmitPromptWarning( |
| 1123 '%s requires formatting. Please run `gn format --in-place %s`.' % ( | 1135 '%s requires formatting. Please run `gn format --in-place %s`.' % ( |
| 1124 f.AbsoluteLocalPath(), f.LocalPath()))) | 1136 f.AbsoluteLocalPath(), f.LocalPath()))) |
| 1125 # It's just a warning, so ignore other types of failures assuming they'll be | 1137 # It's just a warning, so ignore other types of failures assuming they'll be |
| 1126 # caught elsewhere. | 1138 # caught elsewhere. |
| 1127 return warnings | 1139 return warnings |
| OLD | NEW |