OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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.7.0' | 9 __version__ = '1.7.0' |
10 | 10 |
(...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1074 """ | 1074 """ |
1075 presubmit_files = ListRelevantPresubmitFiles(changed_files, repository_root) | 1075 presubmit_files = ListRelevantPresubmitFiles(changed_files, repository_root) |
1076 if not presubmit_files and verbose: | 1076 if not presubmit_files and verbose: |
1077 output_stream.write("Warning, no presubmit.py found.\n") | 1077 output_stream.write("Warning, no presubmit.py found.\n") |
1078 results = [] | 1078 results = [] |
1079 executer = GetTrySlavesExecuter() | 1079 executer = GetTrySlavesExecuter() |
1080 if default_presubmit: | 1080 if default_presubmit: |
1081 if verbose: | 1081 if verbose: |
1082 output_stream.write("Running default presubmit script.\n") | 1082 output_stream.write("Running default presubmit script.\n") |
1083 fake_path = os.path.join(repository_root, 'PRESUBMIT.py') | 1083 fake_path = os.path.join(repository_root, 'PRESUBMIT.py') |
1084 results += executer.ExecPresubmitScript( | 1084 result = executer.ExecPresubmitScript( |
M-A Ruel
2013/11/15 20:09:33
I dislike using += on list anyway.
| |
1085 default_presubmit, fake_path, project, change) | 1085 default_presubmit, fake_path, project, change) |
1086 if (all(isinstance(i, tuple) for i in result) or | |
M-A Ruel
2013/11/15 20:09:33
Add a comment:
# Ensure it's either all old-style
| |
1087 all(isinstance(i, basestring) for i in result)): | |
1088 results += result | |
1089 else: | |
1090 raise ValueError('PRESUBMIT.py returned invalid trybot specification!') | |
1086 for filename in presubmit_files: | 1091 for filename in presubmit_files: |
M-A Ruel
2013/11/15 20:09:33
is this missing an else: ?
ghost stip (do not use)
2013/11/22 01:24:16
I don't think so? this is how the code was before
| |
1087 filename = os.path.abspath(filename) | 1092 filename = os.path.abspath(filename) |
1088 if verbose: | 1093 if verbose: |
1089 output_stream.write("Running %s\n" % filename) | 1094 output_stream.write("Running %s\n" % filename) |
1090 # Accept CRLF presubmit script. | 1095 # Accept CRLF presubmit script. |
1091 presubmit_script = gclient_utils.FileRead(filename, 'rU') | 1096 presubmit_script = gclient_utils.FileRead(filename, 'rU') |
1092 results += executer.ExecPresubmitScript( | 1097 result = executer.ExecPresubmitScript( |
1093 presubmit_script, filename, project, change) | 1098 presubmit_script, filename, project, change) |
1099 if (all(isinstance(i, tuple) for i in result) or | |
1100 all(isinstance(i, basestring) for i in result)): | |
1101 results += result | |
M-A Ruel
2013/11/15 20:09:33
results.extend(result)
| |
1102 else: | |
1103 raise ValueError('%s returned invalid trybot specification!' % filename) | |
1094 | 1104 |
1095 if all(isinstance(i, tuple) for i in results): | 1105 |
1096 # New-style [('bot', set(['tests']))] format. | 1106 slave_dict = {} |
1097 slave_dict = {} | 1107 old_style = filter(lambda x: isinstance(x, basestring), results) |
1098 for result in results: | 1108 new_style = filter(lambda x: isinstance(x, tuple), results) |
1099 slave_dict.setdefault(result[0], set()).update(result[1]) | 1109 |
1100 slaves = list(slave_dict.iteritems()) | 1110 for result in new_style: |
1101 elif all(isinstance(i, basestring) for i in results): | 1111 slave_dict.setdefault(result[0], set()).update(result[1]) |
1102 # Old-style ['bot'] format. | 1112 slaves = list(slave_dict.iteritems()) |
1103 slaves = list(set(results)) | 1113 |
1104 else: | 1114 slaves += list(set(old_style)) |
1105 raise ValueError('PRESUBMIT.py returned invalid trybot specification!') | |
1106 | 1115 |
1107 if slaves and verbose: | 1116 if slaves and verbose: |
1108 output_stream.write(', '.join(slaves)) | 1117 output_stream.write(', '.join((str(x) for x in slaves))) |
1109 output_stream.write('\n') | 1118 output_stream.write('\n') |
1110 return slaves | 1119 return slaves |
1111 | 1120 |
1112 | 1121 |
1113 class PresubmitExecuter(object): | 1122 class PresubmitExecuter(object): |
1114 def __init__(self, change, committing, rietveld_obj, verbose): | 1123 def __init__(self, change, committing, rietveld_obj, verbose): |
1115 """ | 1124 """ |
1116 Args: | 1125 Args: |
1117 change: The Change object. | 1126 change: The Change object. |
1118 committing: True if 'gcl commit' is running, False if 'gcl upload' is. | 1127 committing: True if 'gcl commit' is running, False if 'gcl upload' is. |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1446 except PresubmitFailure, e: | 1455 except PresubmitFailure, e: |
1447 print >> sys.stderr, e | 1456 print >> sys.stderr, e |
1448 print >> sys.stderr, 'Maybe your depot_tools is out of date?' | 1457 print >> sys.stderr, 'Maybe your depot_tools is out of date?' |
1449 print >> sys.stderr, 'If all fails, contact maruel@' | 1458 print >> sys.stderr, 'If all fails, contact maruel@' |
1450 return 2 | 1459 return 2 |
1451 | 1460 |
1452 | 1461 |
1453 if __name__ == '__main__': | 1462 if __name__ == '__main__': |
1454 fix_encoding.fix_encoding() | 1463 fix_encoding.fix_encoding() |
1455 sys.exit(Main(None)) | 1464 sys.exit(Main(None)) |
OLD | NEW |