Chromium Code Reviews| 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 """Top-level presubmit script for Chromium. | 5 """Top-level presubmit script for Chromium. |
| 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 gcl. | 8 for more details about the presubmit API built into gcl. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 ) | 50 ) |
| 51 | 51 |
| 52 _TEST_ONLY_WARNING = ( | 52 _TEST_ONLY_WARNING = ( |
| 53 'You might be calling functions intended only for testing from\n' | 53 'You might be calling functions intended only for testing from\n' |
| 54 'production code. It is OK to ignore this warning if you know what\n' | 54 'production code. It is OK to ignore this warning if you know what\n' |
| 55 'you are doing, as the heuristics used to detect the situation are\n' | 55 'you are doing, as the heuristics used to detect the situation are\n' |
| 56 'not perfect. The commit queue will not block on this warning.\n' | 56 'not perfect. The commit queue will not block on this warning.\n' |
| 57 'Email joi@chromium.org if you have questions.') | 57 'Email joi@chromium.org if you have questions.') |
| 58 | 58 |
| 59 | 59 |
| 60 _HTTPS_ONLY_WARNING = ( | |
| 61 'You should prefer to refer to HTTPS URLs, rather than HTTP URLs.\n' | |
| 62 'Do not bypass this warning if there is an equivalent HTTPS endpoint\n' | |
| 63 'that you could refer to instead.') | |
| 64 | |
| 65 | |
| 60 _INCLUDE_ORDER_WARNING = ( | 66 _INCLUDE_ORDER_WARNING = ( |
| 61 'Your #include order seems to be broken. Send mail to\n' | 67 'Your #include order seems to be broken. Send mail to\n' |
| 62 'marja@chromium.org if this is not the case.') | 68 'marja@chromium.org if this is not the case.') |
| 63 | 69 |
| 64 | 70 |
| 65 _BANNED_OBJC_FUNCTIONS = ( | 71 _BANNED_OBJC_FUNCTIONS = ( |
| 66 ( | 72 ( |
| 67 'addTrackingRect:', | 73 'addTrackingRect:', |
| 68 ( | 74 ( |
| 69 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is' | 75 'The use of -[NSView addTrackingRect:owner:userData:assumeInside:] is' |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 if problems: | 221 if problems: |
| 216 if not input_api.is_committing: | 222 if not input_api.is_committing: |
| 217 return [output_api.PresubmitPromptWarning(_TEST_ONLY_WARNING, problems)] | 223 return [output_api.PresubmitPromptWarning(_TEST_ONLY_WARNING, problems)] |
| 218 else: | 224 else: |
| 219 # We don't warn on commit, to avoid stopping commits going through CQ. | 225 # We don't warn on commit, to avoid stopping commits going through CQ. |
| 220 return [output_api.PresubmitNotifyResult(_TEST_ONLY_WARNING, problems)] | 226 return [output_api.PresubmitNotifyResult(_TEST_ONLY_WARNING, problems)] |
| 221 else: | 227 else: |
| 222 return [] | 228 return [] |
| 223 | 229 |
| 224 | 230 |
| 231 def _CheckNoHttpUrls(input_api, output_api): | |
| 232 """Attempts to prevent use of http:// URLs. Production Chrome code, and | |
| 233 Chromium infrastructure code, should strive to use https:// URLs (preferably | |
| 234 HSTS and with pinned public keys, as well). Some URLs will not be | |
| 235 translatable, but gradually the number of those should diminish. | |
| 236 """ | |
| 237 | |
| 238 # Include all sorts of files, both code and infrastructure scripts. | |
| 239 file_inclusion_pattern = r'.+\.(h|cc|cpp|cxx|mm|py|bat|sh)$' | |
| 240 | |
| 241 inclusion_pattern = input_api.re.compile(r'http:/', input_api.re.IGNORECASE) | |
|
M-A Ruel
2013/01/08 02:51:11
Why not http:// ?
| |
| 242 # Allow http:/ in comments? Only if it turns out to be necessary. | |
|
M-A Ruel
2013/01/08 02:51:11
At least for me, I know I've been using http://chr
| |
| 243 #exclusion_pattern = input_api.re.compile(r'(#|//|/\*| \*).*http:/', | |
| 244 # input_api.re.IGNORECASE) | |
| 245 | |
| 246 def FilterFile(affected_file): | |
| 247 return input_api.FilterSourceFile( | |
| 248 affected_file, | |
| 249 white_list=(file_inclusion_pattern, ), | |
| 250 black_list=()) | |
|
M-A Ruel
2013/01/08 02:51:11
no need to put black_list then.
| |
| 251 | |
| 252 problems = [] | |
| 253 for f in input_api.AffectedSourceFiles(FilterFile): | |
| 254 local_path = f.LocalPath() | |
| 255 lines = input_api.ReadFile(f).splitlines() | |
| 256 line_number = 0 | |
| 257 for line in lines: | |
|
M-A Ruel
2013/01/08 02:51:11
for line_number, line in enumerate(input_api.ReadF
| |
| 258 if (inclusion_pattern.search(line)): | |
| 259 #and not exclusion_pattern.search(line)): | |
| 260 problems.append( | |
| 261 '%s:%d\n %s' % (local_path, line_number, line.strip())) | |
| 262 line_number += 1 | |
| 263 | |
| 264 if problems: | |
| 265 if not input_api.is_committing: | |
|
M-A Ruel
2013/01/08 02:51:11
Remove the not and inverse the lines:
if input_a
| |
| 266 return [output_api.PresubmitPromptWarning(_HTTPS_ONLY_WARNING, problems)] | |
| 267 else: | |
| 268 # We don't warn on commit, to avoid stopping commits going through CQ. | |
| 269 return [output_api.PresubmitNotifyResult(_HTTPS_ONLY_WARNING, problems)] | |
| 270 else: | |
|
M-A Ruel
2013/01/08 02:51:11
optional style nit: "else:" is not needed
| |
| 271 return [] | |
| 272 | |
| 273 | |
| 225 def _CheckNoIOStreamInHeaders(input_api, output_api): | 274 def _CheckNoIOStreamInHeaders(input_api, output_api): |
| 226 """Checks to make sure no .h files include <iostream>.""" | 275 """Checks to make sure no .h files include <iostream>.""" |
| 227 files = [] | 276 files = [] |
| 228 pattern = input_api.re.compile(r'^#include\s*<iostream>', | 277 pattern = input_api.re.compile(r'^#include\s*<iostream>', |
| 229 input_api.re.MULTILINE) | 278 input_api.re.MULTILINE) |
| 230 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): | 279 for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): |
| 231 if not f.LocalPath().endswith('.h'): | 280 if not f.LocalPath().endswith('.h'): |
| 232 continue | 281 continue |
| 233 contents = input_api.ReadFile(f) | 282 contents = input_api.ReadFile(f) |
| 234 if pattern.search(contents): | 283 if pattern.search(contents): |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 858 'win_aura', | 907 'win_aura', |
| 859 'win_rel', | 908 'win_rel', |
| 860 ] | 909 ] |
| 861 | 910 |
| 862 # Match things like path/aura/file.cc and path/file_aura.cc. | 911 # Match things like path/aura/file.cc and path/file_aura.cc. |
| 863 # Same for chromeos. | 912 # Same for chromeos. |
| 864 if any(re.search('[/_](aura|chromeos)', f) for f in files): | 913 if any(re.search('[/_](aura|chromeos)', f) for f in files): |
| 865 trybots += ['linux_chromeos_clang:compile', 'linux_chromeos_asan'] | 914 trybots += ['linux_chromeos_clang:compile', 'linux_chromeos_asan'] |
| 866 | 915 |
| 867 return trybots | 916 return trybots |
| OLD | NEW |