OLD | NEW |
1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 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 ### Description checks | 7 ### Description checks |
8 | 8 |
9 def CheckChangeHasTestField(input_api, output_api): | 9 def CheckChangeHasTestField(input_api, output_api): |
10 """Requires that the changelist have a TEST= field.""" | 10 """Requires that the changelist have a TEST= field.""" |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 if len(bad) == 5: # Just show the first 5 errors. | 268 if len(bad) == 5: # Just show the first 5 errors. |
269 break | 269 break |
270 | 270 |
271 if bad: | 271 if bad: |
272 msg = 'Found lines longer than %s characters (first 5 shown).' % maxlen | 272 msg = 'Found lines longer than %s characters (first 5 shown).' % maxlen |
273 return [output_api.PresubmitPromptWarning(msg, items=bad)] | 273 return [output_api.PresubmitPromptWarning(msg, items=bad)] |
274 else: | 274 else: |
275 return [] | 275 return [] |
276 | 276 |
277 | 277 |
278 def CheckLicense(input_api, output_api, license, source_file_filter=None): | 278 def CheckLicense(input_api, output_api, license, source_file_filter=None, |
| 279 accept_empty_files=True): |
279 """Verifies the license header. | 280 """Verifies the license header. |
280 """ | 281 """ |
281 license_re = input_api.re.compile(license, input_api.re.MULTILINE) | 282 license_re = input_api.re.compile(license, input_api.re.MULTILINE) |
282 bad_files = [] | 283 bad_files = [] |
283 for f in input_api.AffectedSourceFiles(source_file_filter): | 284 for f in input_api.AffectedSourceFiles(source_file_filter): |
284 contents = input_api.ReadFile(f, 'rb') | 285 contents = input_api.ReadFile(f, 'rb') |
| 286 if accept_empty_files and not contents: |
| 287 continue |
285 if not license_re.search(contents): | 288 if not license_re.search(contents): |
286 bad_files.append(f.LocalPath()) | 289 bad_files.append(f.LocalPath()) |
287 if bad_files: | 290 if bad_files: |
288 if input_api.is_committing: | 291 if input_api.is_committing: |
289 res_type = output_api.PresubmitPromptWarning | 292 res_type = output_api.PresubmitPromptWarning |
290 else: | 293 else: |
291 res_type = output_api.PresubmitNotifyResult | 294 res_type = output_api.PresubmitNotifyResult |
292 return [res_type( | 295 return [res_type( |
293 'Found a bad license header in these files:', items=bad_files)] | 296 'Found a bad license header in these files:', items=bad_files)] |
294 return [] | 297 return [] |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 pending_builds_len = len(builder.get('pending_builds', [])) | 524 pending_builds_len = len(builder.get('pending_builds', [])) |
522 if pending_builds_len > max_pendings: | 525 if pending_builds_len > max_pendings: |
523 out.append('%s has %d build(s) pending' % | 526 out.append('%s has %d build(s) pending' % |
524 (builder_name, pending_builds_len)) | 527 (builder_name, pending_builds_len)) |
525 if out: | 528 if out: |
526 return [output_api.PresubmitPromptWarning( | 529 return [output_api.PresubmitPromptWarning( |
527 'Build(s) pending. It is suggested to wait that no more than %d ' | 530 'Build(s) pending. It is suggested to wait that no more than %d ' |
528 'builds are pending.' % max_pendings, | 531 'builds are pending.' % max_pendings, |
529 long_text='\n'.join(out))] | 532 long_text='\n'.join(out))] |
530 return [] | 533 return [] |
OLD | NEW |