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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 keyword = 'DO NOT ''SUBMIT' | 105 keyword = 'DO NOT ''SUBMIT' |
106 errors = _FindNewViolationsOfRule(lambda _, line : keyword not in line, | 106 errors = _FindNewViolationsOfRule(lambda _, line : keyword not in line, |
107 input_api, file_filter) | 107 input_api, file_filter) |
108 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) |
109 if text: | 109 if text: |
110 return [output_api.PresubmitError(text)] | 110 return [output_api.PresubmitError(text)] |
111 return [] | 111 return [] |
112 | 112 |
113 | 113 |
114 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): | 115 lint_filters=None, verbose_level=None): |
116 """Checks that all '.cc' and '.h' files pass cpplint.py.""" | 116 """Checks that all '.cc' and '.h' files pass cpplint.py.""" |
117 _RE_IS_TEST = input_api.re.compile(r'.*tests?.(cc|h)$') | 117 _RE_IS_TEST = input_api.re.compile(r'.*tests?.(cc|h)$') |
118 result = [] | 118 result = [] |
119 | 119 |
120 cpplint = input_api.cpplint | 120 cpplint = input_api.cpplint |
121 # Access to a protected member _XX of a client class | 121 # Access to a protected member _XX of a client class |
122 # pylint: disable=W0212 | 122 # pylint: disable=W0212 |
123 cpplint._cpplint_state.ResetErrorCounts() | 123 cpplint._cpplint_state.ResetErrorCounts() |
124 | 124 |
125 lint_filters = lint_filters or DEFAULT_LINT_FILTERS | 125 lint_filters = lint_filters or DEFAULT_LINT_FILTERS |
126 cpplint._SetFilters(','.join(lint_filters)) | 126 cpplint._SetFilters(','.join(lint_filters)) |
127 | 127 |
128 # 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 |
129 # 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 |
130 # --verbose=#. Hopefully, in the future, we can be more verbose. | 130 # --verbose=#. Hopefully, in the future, we can be more verbose. |
131 files = [f.AbsoluteLocalPath() for f in | 131 files = [f.AbsoluteLocalPath() for f in |
132 input_api.AffectedSourceFiles(source_file_filter)] | 132 input_api.AffectedSourceFiles(source_file_filter)] |
133 for file_name in files: | 133 for file_name in files: |
134 if _RE_IS_TEST.match(file_name): | 134 if _RE_IS_TEST.match(file_name): |
135 level = 5 | 135 level = 5 |
136 else: | 136 else: |
137 level = 4 | 137 level = 4 |
138 | 138 |
139 cpplint.ProcessFile(file_name, level) | 139 verbose_level = verbose_level or level |
| 140 cpplint.ProcessFile(file_name, verbose_level) |
140 | 141 |
141 if cpplint._cpplint_state.error_count > 0: | 142 if cpplint._cpplint_state.error_count > 0: |
142 if input_api.is_committing: | 143 if input_api.is_committing: |
143 res_type = output_api.PresubmitError | 144 res_type = output_api.PresubmitError |
144 else: | 145 else: |
145 res_type = output_api.PresubmitPromptWarning | 146 res_type = output_api.PresubmitPromptWarning |
146 result = [res_type('Changelist failed cpplint.py check.')] | 147 result = [res_type('Changelist failed cpplint.py check.')] |
147 | 148 |
148 return result | 149 return result |
149 | 150 |
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 for f in affected_files: | 1117 for f in affected_files: |
1117 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] | 1118 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] |
1118 rc = gn.main(cmd) | 1119 rc = gn.main(cmd) |
1119 if rc == 2: | 1120 if rc == 2: |
1120 warnings.append(output_api.PresubmitPromptWarning( | 1121 warnings.append(output_api.PresubmitPromptWarning( |
1121 '%s requires formatting. Please run `gn format --in-place %s`.' % ( | 1122 '%s requires formatting. Please run `gn format --in-place %s`.' % ( |
1122 f.AbsoluteLocalPath(), f.LocalPath()))) | 1123 f.AbsoluteLocalPath(), f.LocalPath()))) |
1123 # It's just a warning, so ignore other types of failures assuming they'll be | 1124 # It's just a warning, so ignore other types of failures assuming they'll be |
1124 # caught elsewhere. | 1125 # caught elsewhere. |
1125 return warnings | 1126 return warnings |
OLD | NEW |