Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 Chromium media component. | 5 """Top-level presubmit script for Chromium media component. |
| 6 | 6 |
| 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts | 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 8 for more details about the presubmit API built into depot_tools. | 8 for more details about the presubmit API built into depot_tools. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import re | |
| 12 import string | |
| 13 | |
| 14 # Well-defined simple classes containing only <= 4 ints, or <= 2 floats. | |
| 15 PASS_BY_VALUE_TYPES = ['base::Time', | |
| 16 'base::TimeDelta', | |
| 17 'base::TimeTicks', | |
| 18 ] | |
|
sandersd (OOO until July 31)
2015/10/16 21:52:27
Can you check that pyformat agrees with this? If n
mcasas
2015/10/20 00:24:18
If you're happy like that, I'm happy too. Done.
| |
| 19 | |
| 20 PASS_BY_VALUE_RE = re.compile(r'\bconst +' + '%s&' % | |
|
sandersd (OOO until July 31)
2015/10/16 21:52:27
This requires parentheses around %s.
mcasas
2015/10/20 00:24:18
Done.
| |
| 21 string.join(PASS_BY_VALUE_TYPES, '|')) | |
| 22 | |
| 11 def _FilterFile(affected_file): | 23 def _FilterFile(affected_file): |
| 12 """Return true if the file could contain code requiring a presubmit check.""" | 24 """Return true if the file could contain code requiring a presubmit check.""" |
| 13 return affected_file.LocalPath().endswith( | 25 return affected_file.LocalPath().endswith( |
| 14 ('.h', '.cc', '.cpp', '.cxx', '.mm')) | 26 ('.h', '.cc', '.cpp', '.cxx', '.mm')) |
| 15 | 27 |
| 16 | 28 |
| 17 def _CheckForUseOfWrongClock(input_api, output_api): | 29 def _CheckForUseOfWrongClock(input_api, output_api): |
| 18 """Make sure new lines of media code don't use a clock susceptible to skew.""" | 30 """Make sure new lines of media code don't use a clock susceptible to skew.""" |
| 19 | 31 |
| 20 # Regular expression that should detect any explicit references to the | 32 # Regular expression that should detect any explicit references to the |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 'UMA_HISTOGRAM_ENUMERATION reports in src/media/ are expected to adhere\n' | 164 'UMA_HISTOGRAM_ENUMERATION reports in src/media/ are expected to adhere\n' |
| 153 'to the following guidelines:\n' | 165 'to the following guidelines:\n' |
| 154 ' - The max value (3rd argument) should be an enum value equal to the\n' | 166 ' - The max value (3rd argument) should be an enum value equal to the\n' |
| 155 ' last valid value, e.g. FOO_MAX = LAST_VALID_FOO.\n' | 167 ' last valid value, e.g. FOO_MAX = LAST_VALID_FOO.\n' |
| 156 ' - 1 must be added to that max value.\n' | 168 ' - 1 must be added to that max value.\n' |
| 157 'Contact rileya@chromium.org if you have questions.' , problems)] | 169 'Contact rileya@chromium.org if you have questions.' , problems)] |
| 158 | 170 |
| 159 return [] | 171 return [] |
| 160 | 172 |
| 161 | 173 |
| 174 def _CheckPassByValue(input_api, output_api): | |
| 175 local_errors = [] | |
| 176 | |
| 177 for f in input_api.AffectedSourceFiles(_FilterFile): | |
| 178 for line_number, line in f.ChangedContents(): | |
| 179 if PASS_BY_VALUE_RE.search(line.strip()): | |
|
sandersd (OOO until July 31)
2015/10/16 21:52:27
No need to strip the line here.
mcasas
2015/10/20 00:24:18
Done.
| |
| 180 local_errors.append(output_api.PresubmitError( | |
| 181 ' %s:%d passes argument by const ref instead of by value:\n %s' % | |
|
sandersd (OOO until July 31)
2015/10/16 21:52:27
I'm not too happy with this message because it doe
mcasas
2015/10/20 00:24:18
Rephrase to make it look more like the neighbours.
| |
| 182 (f.LocalPath(), line_number, line.strip()))) | |
| 183 return local_errors | |
| 184 | |
| 185 | |
| 162 def _CheckChange(input_api, output_api): | 186 def _CheckChange(input_api, output_api): |
| 163 results = [] | 187 results = [] |
| 164 results.extend(_CheckForUseOfWrongClock(input_api, output_api)) | 188 results.extend(_CheckForUseOfWrongClock(input_api, output_api)) |
| 165 results.extend(_CheckForMessageLoopProxy(input_api, output_api)) | 189 results.extend(_CheckForMessageLoopProxy(input_api, output_api)) |
| 190 results.extend(_CheckPassByValue(input_api, output_api)) | |
| 166 results.extend(_CheckForHistogramOffByOne(input_api, output_api)) | 191 results.extend(_CheckForHistogramOffByOne(input_api, output_api)) |
| 167 return results | 192 return results |
| 168 | 193 |
| 169 | 194 |
| 170 def CheckChangeOnUpload(input_api, output_api): | 195 def CheckChangeOnUpload(input_api, output_api): |
| 171 return _CheckChange(input_api, output_api) | 196 return _CheckChange(input_api, output_api) |
| 172 | 197 |
| 173 | 198 |
| 174 def CheckChangeOnCommit(input_api, output_api): | 199 def CheckChangeOnCommit(input_api, output_api): |
| 175 return _CheckChange(input_api, output_api) | 200 return _CheckChange(input_api, output_api) |
| OLD | NEW |