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

Side by Side Diff: presubmit_canned_checks.py

Issue 15898005: presubmit: Call 'git diff' once per change instead of once per file (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Fix language in git_cl.py Created 7 years, 6 months 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
« no previous file with comments | « patch.py ('k') | presubmit_support.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) 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 """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 import os as _os 7 import os as _os
8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) 8 _HERE = _os.path.dirname(_os.path.abspath(__file__))
9 9
10 10
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 'mk': 200, 321 'mk': 200,
322 '': maxlen, 322 '': maxlen,
323 } 323 }
324 # Note: these are C++ specific but processed on all languages. :( 324 # Note: these are C++ specific but processed on all languages. :(
325 MACROS = ('#define', '#include', '#import', '#pragma', '#if', '#endif') 325 MACROS = ('#define', '#include', '#import', '#pragma', '#if', '#endif')
326 326
327 # Special java statements. 327 # Special java statements.
328 SPECIAL_JAVA_STARTS = ('package ', 'import ') 328 SPECIAL_JAVA_STARTS = ('package ', 'import ')
329 329
330 def no_long_lines(file_extension, line): 330 def no_long_lines(file_extension, line):
331 # Allow special java statements to be as long as neccessary. 331 # Allow special java statements to be as long as necessary.
332 if file_extension == 'java' and line.startswith(SPECIAL_JAVA_STARTS): 332 if file_extension == 'java' and line.startswith(SPECIAL_JAVA_STARTS):
333 return True 333 return True
334 334
335 file_maxlen = maxlens.get(file_extension, maxlens['']) 335 file_maxlen = maxlens.get(file_extension, maxlens[''])
336 # Stupidly long symbols that needs to be worked around if takes 66% of line. 336 # Stupidly long symbols that needs to be worked around if takes 66% of line.
337 long_symbol = file_maxlen * 2 / 3 337 long_symbol = file_maxlen * 2 / 3
338 # Hard line length limit at 50% more. 338 # Hard line length limit at 50% more.
339 extra_maxlen = file_maxlen * 3 / 2 339 extra_maxlen = file_maxlen * 3 / 2
340 340
341 line_len = len(line) 341 line_len = len(line)
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 long_text=long_text)] 480 long_text=long_text)]
481 except IOError as e: 481 except IOError as e:
482 return [output_api.PresubmitError('Error fetching tree status.', 482 return [output_api.PresubmitError('Error fetching tree status.',
483 long_text=str(e))] 483 long_text=str(e))]
484 return [] 484 return []
485 485
486 def GetUnitTestsInDirectory( 486 def GetUnitTestsInDirectory(
487 input_api, output_api, directory, whitelist=None, blacklist=None): 487 input_api, output_api, directory, whitelist=None, blacklist=None):
488 """Lists all files in a directory and runs them. Doesn't recurse. 488 """Lists all files in a directory and runs them. Doesn't recurse.
489 489
490 It's mainly a wrapper for RunUnitTests. USe whitelist and blacklist to filter 490 It's mainly a wrapper for RunUnitTests. Use whitelist and blacklist to filter
491 tests accordingly. 491 tests accordingly.
492 """ 492 """
493 unit_tests = [] 493 unit_tests = []
494 test_path = input_api.os_path.abspath( 494 test_path = input_api.os_path.abspath(
495 input_api.os_path.join(input_api.PresubmitLocalPath(), directory)) 495 input_api.os_path.join(input_api.PresubmitLocalPath(), directory))
496 496
497 def check(filename, filters): 497 def check(filename, filters):
498 return any(True for i in filters if input_api.re.match(i, filename)) 498 return any(True for i in filters if input_api.re.match(i, filename))
499 499
500 to_run = found = 0 500 to_run = found = 0
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 if input_api.verbose: 540 if input_api.verbose:
541 print('Running %s' % unit_test) 541 print('Running %s' % unit_test)
542 cmd.append('--verbose') 542 cmd.append('--verbose')
543 results.append(input_api.Command( 543 results.append(input_api.Command(
544 name=unit_test, 544 name=unit_test,
545 cmd=cmd, 545 cmd=cmd,
546 kwargs={'cwd': input_api.PresubmitLocalPath()}, 546 kwargs={'cwd': input_api.PresubmitLocalPath()},
547 message=message_type)) 547 message=message_type))
548 return results 548 return results
549 549
550
550 def GetPythonUnitTests(input_api, output_api, unit_tests): 551 def GetPythonUnitTests(input_api, output_api, unit_tests):
551 """Run the unit tests out of process, capture the output and use the result 552 """Run the unit tests out of process, capture the output and use the result
552 code to determine success. 553 code to determine success.
553 554
554 DEPRECATED. 555 DEPRECATED.
555 """ 556 """
556 # We don't want to hinder users from uploading incomplete patches. 557 # We don't want to hinder users from uploading incomplete patches.
557 if input_api.is_committing: 558 if input_api.is_committing:
558 message_type = output_api.PresubmitError 559 message_type = output_api.PresubmitError
559 else: 560 else:
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 snapshot("checking description") 1022 snapshot("checking description")
1022 results.extend(input_api.canned_checks.CheckChangeHasDescription( 1023 results.extend(input_api.canned_checks.CheckChangeHasDescription(
1023 input_api, output_api)) 1024 input_api, output_api))
1024 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription( 1025 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription(
1025 input_api, output_api)) 1026 input_api, output_api))
1026 snapshot("checking do not submit in files") 1027 snapshot("checking do not submit in files")
1027 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles( 1028 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles(
1028 input_api, output_api)) 1029 input_api, output_api))
1029 snapshot("done") 1030 snapshot("done")
1030 return results 1031 return results
OLDNEW
« no previous file with comments | « patch.py ('k') | presubmit_support.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698