Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(477)

Side by Side Diff: presubmit_canned_checks.py

Issue 4310001: Make CheckLicense() to not trigger on empty files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 []
OLDNEW
« no previous file with comments | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698