OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 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.4' | 9 __version__ = '1.4' |
10 | 10 |
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 | 1033 |
1034 Warning: | 1034 Warning: |
1035 If may_prompt is true, output_stream SHOULD be sys.stdout and input_stream | 1035 If may_prompt is true, output_stream SHOULD be sys.stdout and input_stream |
1036 SHOULD be sys.stdin. | 1036 SHOULD be sys.stdin. |
1037 | 1037 |
1038 Return: | 1038 Return: |
1039 A PresubmitOutput object. Use output.should_continue() to figure out | 1039 A PresubmitOutput object. Use output.should_continue() to figure out |
1040 if there were errors or warnings and the caller should abort. | 1040 if there were errors or warnings and the caller should abort. |
1041 """ | 1041 """ |
1042 output = PresubmitOutput(input_stream, output_stream) | 1042 output = PresubmitOutput(input_stream, output_stream) |
1043 output.write("Running presubmit hooks...\n") | 1043 if committing: |
| 1044 output.write("Running presubmit commit checks ...\n") |
| 1045 else: |
| 1046 output.write("Running presubmit upload checks ...\n") |
1044 start_time = time.time() | 1047 start_time = time.time() |
1045 presubmit_files = ListRelevantPresubmitFiles(change.AbsoluteLocalPaths(True), | 1048 presubmit_files = ListRelevantPresubmitFiles(change.AbsoluteLocalPaths(True), |
1046 change.RepositoryRoot()) | 1049 change.RepositoryRoot()) |
1047 if not presubmit_files and verbose: | 1050 if not presubmit_files and verbose: |
1048 output.write("Warning, no presubmit.py found.\n") | 1051 output.write("Warning, no presubmit.py found.\n") |
1049 results = [] | 1052 results = [] |
1050 executer = PresubmitExecuter(change, committing, tbr, host_url) | 1053 executer = PresubmitExecuter(change, committing, tbr, host_url) |
1051 if default_presubmit: | 1054 if default_presubmit: |
1052 if verbose: | 1055 if verbose: |
1053 output.write("Running default presubmit script.\n") | 1056 output.write("Running default presubmit script.\n") |
(...skipping 11 matching lines...) Expand all Loading... |
1065 notifications = [] | 1068 notifications = [] |
1066 warnings = [] | 1069 warnings = [] |
1067 for result in results: | 1070 for result in results: |
1068 if result.fatal: | 1071 if result.fatal: |
1069 errors.append(result) | 1072 errors.append(result) |
1070 elif result.should_prompt: | 1073 elif result.should_prompt: |
1071 warnings.append(result) | 1074 warnings.append(result) |
1072 else: | 1075 else: |
1073 notifications.append(result) | 1076 notifications.append(result) |
1074 | 1077 |
| 1078 output.write('\n') |
1075 for name, items in (('Messages', notifications), | 1079 for name, items in (('Messages', notifications), |
1076 ('Warnings', warnings), | 1080 ('Warnings', warnings), |
1077 ('ERRORS', errors)): | 1081 ('ERRORS', errors)): |
1078 if items: | 1082 if items: |
1079 output.write('** Presubmit %s **\n' % name) | 1083 output.write('** Presubmit %s **\n' % name) |
1080 for item in items: | 1084 for item in items: |
1081 item.handle(output) | 1085 item.handle(output) |
1082 output.write('\n') | 1086 output.write('\n') |
1083 | 1087 |
1084 total_time = time.time() - start_time | 1088 total_time = time.time() - start_time |
1085 if total_time > 1.0: | 1089 if total_time > 1.0: |
1086 output.write("Presubmit checks took %.1fs to calculate.\n" % total_time) | 1090 output.write("Presubmit checks took %.1fs to calculate.\n\n" % total_time) |
1087 | 1091 |
1088 if not errors and warnings: | 1092 if not errors: |
1089 if may_prompt: | 1093 if not warnings: |
| 1094 output.write('Presubmit checks passed.\n') |
| 1095 elif may_prompt: |
1090 output.prompt_yes_no('There were presubmit warnings. ' | 1096 output.prompt_yes_no('There were presubmit warnings. ' |
1091 'Are you sure you wish to continue? (y/N): ') | 1097 'Are you sure you wish to continue? (y/N): ') |
1092 else: | 1098 else: |
1093 output.fail() | 1099 output.fail() |
1094 | 1100 |
1095 global _ASKED_FOR_FEEDBACK | 1101 global _ASKED_FOR_FEEDBACK |
1096 # Ask for feedback one time out of 5. | 1102 # Ask for feedback one time out of 5. |
1097 if (len(results) and random.randint(0, 4) == 0 and not _ASKED_FOR_FEEDBACK): | 1103 if (len(results) and random.randint(0, 4) == 0 and not _ASKED_FOR_FEEDBACK): |
1098 output.write("Was the presubmit check useful? Please send feedback " | 1104 output.write("Was the presubmit check useful? Please send feedback " |
1099 "& hate mail to maruel@chromium.org!\n") | 1105 "& hate mail to maruel@chromium.org!\n") |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1189 sys.stdout, | 1195 sys.stdout, |
1190 sys.stdin, | 1196 sys.stdin, |
1191 options.default_presubmit, | 1197 options.default_presubmit, |
1192 options.may_prompt) | 1198 options.may_prompt) |
1193 return not results.should_continue() | 1199 return not results.should_continue() |
1194 | 1200 |
1195 | 1201 |
1196 if __name__ == '__main__': | 1202 if __name__ == '__main__': |
1197 fix_encoding.fix_encoding() | 1203 fix_encoding.fix_encoding() |
1198 sys.exit(Main(None)) | 1204 sys.exit(Main(None)) |
OLD | NEW |