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 | |
| 11 def _FilterFile(affected_file): | 14 def _FilterFile(affected_file): |
| 12 """Return true if the file could contain code requiring a presubmit check.""" | 15 """Return true if the file could contain code requiring a presubmit check.""" |
| 13 return affected_file.LocalPath().endswith( | 16 return affected_file.LocalPath().endswith( |
| 14 ('.h', '.cc', '.cpp', '.cxx', '.mm')) | 17 ('.h', '.cc', '.cpp', '.cxx', '.mm')) |
| 15 | 18 |
| 16 | 19 |
| 17 def _CheckForUseOfWrongClock(input_api, output_api): | 20 def _CheckForUseOfWrongClock(input_api, output_api): |
| 18 """Make sure new lines of media code don't use a clock susceptible to skew.""" | 21 """Make sure new lines of media code don't use a clock susceptible to skew.""" |
| 19 | 22 |
| 20 # Regular expression that should detect any explicit references to the | 23 # Regular expression that should detect any explicit references to the |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 return [output_api.PresubmitError( | 154 return [output_api.PresubmitError( |
| 152 'UMA_HISTOGRAM_ENUMERATION reports in src/media/ are expected to adhere\n' | 155 'UMA_HISTOGRAM_ENUMERATION reports in src/media/ are expected to adhere\n' |
| 153 'to the following guidelines:\n' | 156 'to the following guidelines:\n' |
| 154 ' - The max value (3rd argument) should be an enum value equal to the\n' | 157 ' - 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' | 158 ' last valid value, e.g. FOO_MAX = LAST_VALID_FOO.\n' |
| 156 ' - 1 must be added to that max value.\n' | 159 ' - 1 must be added to that max value.\n' |
| 157 'Contact rileya@chromium.org if you have questions.' , problems)] | 160 'Contact rileya@chromium.org if you have questions.' , problems)] |
| 158 | 161 |
| 159 return [] | 162 return [] |
| 160 | 163 |
| 164 def _CheckPassByValue(input_api, | |
|
sandersd (OOO until July 31)
2015/10/16 00:54:31
No need to wrap arguments.
mcasas
2015/10/16 18:00:11
Done.
| |
| 165 output_api): | |
| 166 local_errors = [] | |
| 167 | |
| 168 # Well-defined simple classes containing only <= 4 ints, or <= 2 floats. | |
| 169 pass_by_value_types = ['base::Time', | |
| 170 'base::TimeTicks', | |
| 171 ] | |
| 172 | |
| 173 for f in input_api.AffectedSourceFiles(_FilterFile): | |
| 174 contents = input_api.ReadFile(f, 'rb') | |
| 175 match = re.search( | |
| 176 r'\bconst +' + '(?P<type>(%s))&' % | |
|
sandersd (OOO until July 31)
2015/10/16 00:54:31
This regex should be precompiled, eg:
PASS_BY_VAL
mcasas
2015/10/16 18:00:11
Done.
| |
| 177 string.join(pass_by_value_types, '|'), | |
|
sandersd (OOO until July 31)
2015/10/16 00:54:31
Instead of building 'const foo&|cost bar&', it wou
mcasas
2015/10/16 18:00:11
Isn't it what's done? Regexp is
r'... <type>(%s))
sandersd (OOO until July 31)
2015/10/16 18:27:12
Hmm, you're correct, but that means there is no ne
mcasas
2015/10/16 21:40:42
Done.
| |
| 178 contents) | |
| 179 if match: | |
|
sandersd (OOO until July 31)
2015/10/16 00:54:31
Note that there is also .findall(), which iterates
mcasas
2015/10/16 18:00:11
My first goal was to stick as much as possible to
sandersd (OOO until July 31)
2015/10/16 18:27:12
Probably best to list them all, it's a trivial cha
mcasas
2015/10/16 21:40:42
Not that trivial since find_all() would not give t
| |
| 180 local_errors.append(output_api.PresubmitError( | |
| 181 '%s passes %s by const ref instead of by value.' % | |
| 182 (f.LocalPath(), match.group('type')))) | |
| 183 return local_errors | |
| 184 | |
| 161 | 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 |