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

Side by Side Diff: presubmit_support.py

Issue 115616: Add repository root presubmit support. (Closed)
Patch Set: Fix diff to not include the prior patches. Created 11 years, 7 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 | « gcl.py ('k') | tests/gcl_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 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Enables directory-specific presubmit checks to run at upload and/or commit. 6 """Enables directory-specific presubmit checks to run at upload and/or commit.
7 """ 7 """
8 8
9 __version__ = '1.0.1' 9 __version__ = '1.0.1'
10 10
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 else: 596 else:
597 result = () # no error since the script doesn't care about current event. 597 result = () # no error since the script doesn't care about current event.
598 598
599 return result 599 return result
600 600
601 601
602 def DoPresubmitChecks(change_info, 602 def DoPresubmitChecks(change_info,
603 committing, 603 committing,
604 verbose, 604 verbose,
605 output_stream, 605 output_stream,
606 input_stream): 606 input_stream,
607 default_presubmit):
607 """Runs all presubmit checks that apply to the files in the change. 608 """Runs all presubmit checks that apply to the files in the change.
608 609
609 This finds all PRESUBMIT.py files in directories enclosing the files in the 610 This finds all PRESUBMIT.py files in directories enclosing the files in the
610 change (up to the repository root) and calls the relevant entrypoint function 611 change (up to the repository root) and calls the relevant entrypoint function
611 depending on whether the change is being committed or uploaded. 612 depending on whether the change is being committed or uploaded.
612 613
613 Prints errors, warnings and notifications. Prompts the user for warnings 614 Prints errors, warnings and notifications. Prompts the user for warnings
614 when needed. 615 when needed.
615 616
616 Args: 617 Args:
617 change_info: The ChangeInfo object for the change. 618 change_info: The ChangeInfo object for the change.
618 committing: True if 'gcl commit' is running, False if 'gcl upload' is. 619 committing: True if 'gcl commit' is running, False if 'gcl upload' is.
619 verbose: Prints debug info. 620 verbose: Prints debug info.
620 output_stream: A stream to write output from presubmit tests to. 621 output_stream: A stream to write output from presubmit tests to.
621 input_stream: A stream to read input from the user. 622 input_stream: A stream to read input from the user.
623 default_presubmit: A default presubmit script to execute in any case.
622 624
623 Return: 625 Return:
624 True if execution can continue, False if not. 626 True if execution can continue, False if not.
625 """ 627 """
626 presubmit_files = ListRelevantPresubmitFiles(change_info.FileList()) 628 presubmit_files = ListRelevantPresubmitFiles(change_info.FileList())
627 if not presubmit_files and verbose: 629 if not presubmit_files and verbose:
628 print "Warning, no presubmit.py found." 630 output_stream.write("Warning, no presubmit.py found.")
629 results = [] 631 results = []
630 executer = PresubmitExecuter(change_info, committing) 632 executer = PresubmitExecuter(change_info, committing)
633 if default_presubmit:
634 if verbose:
635 output_stream.write("Running default presubmit script")
636 results += executer.ExecPresubmitScript(default_presubmit, 'PRESUBMIT.py')
631 for filename in presubmit_files: 637 for filename in presubmit_files:
632 filename = os.path.abspath(filename) 638 filename = os.path.abspath(filename)
633 if verbose: 639 if verbose:
634 print "Running %s" % filename 640 output_stream.write("Running %s" % filename)
635 # Accept CRLF presubmit script. 641 # Accept CRLF presubmit script.
636 presubmit_script = gcl.ReadFile(filename, 'rU') 642 presubmit_script = gcl.ReadFile(filename, 'rU')
637 results += executer.ExecPresubmitScript(presubmit_script, filename) 643 results += executer.ExecPresubmitScript(presubmit_script, filename)
638 644
639 errors = [] 645 errors = []
640 notifications = [] 646 notifications = []
641 warnings = [] 647 warnings = []
642 for result in results: 648 for result in results:
643 if not result.IsFatal() and not result.ShouldPrompt(): 649 if not result.IsFatal() and not result.ShouldPrompt():
644 notifications.append(result) 650 notifications.append(result)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 parser.add_option("-c", "--commit", action="store_true", 700 parser.add_option("-c", "--commit", action="store_true",
695 help="Use commit instead of upload checks") 701 help="Use commit instead of upload checks")
696 parser.add_option("-r", "--recursive", action="store_true", 702 parser.add_option("-r", "--recursive", action="store_true",
697 help="Act recursively") 703 help="Act recursively")
698 parser.add_option("-v", "--verbose", action="store_true", 704 parser.add_option("-v", "--verbose", action="store_true",
699 help="Verbose output") 705 help="Verbose output")
700 options, args = parser.parse_args(argv[1:]) 706 options, args = parser.parse_args(argv[1:])
701 files = ParseFiles(args, options.recursive) 707 files = ParseFiles(args, options.recursive)
702 if options.verbose: 708 if options.verbose:
703 print "Found %d files." % len(files) 709 print "Found %d files." % len(files)
704 return DoPresubmitChecks(gcl.ChangeInfo(name='temp', files=files), 710 return not DoPresubmitChecks(gcl.ChangeInfo(name='temp', files=files),
705 options.commit, 711 options.commit,
706 options.verbose, 712 options.verbose,
707 sys.stdout, 713 sys.stdout,
708 sys.stdin) 714 sys.stdin,
715 default_presubmit=None)
709 716
710 717
711 if __name__ == '__main__': 718 if __name__ == '__main__':
712 sys.exit(Main(sys.argv)) 719 sys.exit(Main(sys.argv))
OLDNEW
« no previous file with comments | « gcl.py ('k') | tests/gcl_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698