Chromium Code Reviews| 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.6.2' | 9 __version__ = '1.6.2' |
| 10 | 10 |
| (...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1024 result = get_preferred_try_slaves(project) | 1024 result = get_preferred_try_slaves(project) |
| 1025 elif len(function_info[0]) == 2: | 1025 elif len(function_info[0]) == 2: |
| 1026 result = get_preferred_try_slaves(project, change) | 1026 result = get_preferred_try_slaves(project, change) |
| 1027 else: | 1027 else: |
| 1028 result = get_preferred_try_slaves() | 1028 result = get_preferred_try_slaves() |
| 1029 if not isinstance(result, types.ListType): | 1029 if not isinstance(result, types.ListType): |
| 1030 raise PresubmitFailure( | 1030 raise PresubmitFailure( |
| 1031 'Presubmit functions must return a list, got a %s instead: %s' % | 1031 'Presubmit functions must return a list, got a %s instead: %s' % |
| 1032 (type(result), str(result))) | 1032 (type(result), str(result))) |
| 1033 for item in result: | 1033 for item in result: |
| 1034 if not isinstance(item, basestring): | 1034 if not isinstance(item, basestring): |
|
M-A Ruel
2013/11/01 13:13:57
Use positive checks instead of negative checks.
i
| |
| 1035 raise PresubmitFailure('All try slaves names must be strings.') | 1035 if not isinstance(item, tuple): |
| 1036 if item != item.strip(): | 1036 raise PresubmitFailure('PRESUBMIT.py returned invalid tryslave/test' |
| 1037 ' format.') | |
| 1038 # New-style [('bot', set(['tests']))] format. | |
| 1039 botname = item[0] | |
| 1040 else: | |
| 1041 # Old-style ['bot'] format. | |
| 1042 botname = item | |
| 1043 | |
| 1044 if botname != botname.strip(): | |
| 1037 raise PresubmitFailure( | 1045 raise PresubmitFailure( |
| 1038 'Try slave names cannot start/end with whitespace') | 1046 'Try slave names cannot start/end with whitespace') |
| 1039 if ',' in item: | 1047 if ',' in botname: |
| 1040 raise PresubmitFailure( | 1048 raise PresubmitFailure( |
| 1041 'Do not use \',\' separated builder or test names: %s' % item) | 1049 'Do not use \',\' separated builder or test names: %s' % botname) |
| 1042 else: | 1050 else: |
| 1043 result = [] | 1051 result = [] |
| 1044 return result | 1052 return result |
| 1045 | 1053 |
| 1046 | 1054 |
| 1047 def DoGetTrySlaves(change, | 1055 def DoGetTrySlaves(change, |
| 1048 changed_files, | 1056 changed_files, |
| 1049 repository_root, | 1057 repository_root, |
| 1050 default_presubmit, | 1058 default_presubmit, |
| 1051 project, | 1059 project, |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1077 default_presubmit, fake_path, project, change) | 1085 default_presubmit, fake_path, project, change) |
| 1078 for filename in presubmit_files: | 1086 for filename in presubmit_files: |
| 1079 filename = os.path.abspath(filename) | 1087 filename = os.path.abspath(filename) |
| 1080 if verbose: | 1088 if verbose: |
| 1081 output_stream.write("Running %s\n" % filename) | 1089 output_stream.write("Running %s\n" % filename) |
| 1082 # Accept CRLF presubmit script. | 1090 # Accept CRLF presubmit script. |
| 1083 presubmit_script = gclient_utils.FileRead(filename, 'rU') | 1091 presubmit_script = gclient_utils.FileRead(filename, 'rU') |
| 1084 results += executer.ExecPresubmitScript( | 1092 results += executer.ExecPresubmitScript( |
| 1085 presubmit_script, filename, project, change) | 1093 presubmit_script, filename, project, change) |
| 1086 | 1094 |
| 1087 slaves = list(set(results)) | 1095 if results and isinstance(results[0], tuple): |
|
M-A Ruel
2013/11/01 13:13:57
do you want to use all()?
I'd prefer to enforce:
| |
| 1096 # New-style [('bot', set(['tests']))] format. | |
| 1097 slave_dict = {} | |
| 1098 for result in results: | |
| 1099 slave_dict.setdefault(result[0], set()).update(result[1]) | |
| 1100 slaves = list(slave_dict.iteritems()) | |
| 1101 else: | |
| 1102 # Old-style ['bot'] format. | |
| 1103 slaves = list(set(results)) | |
| 1104 | |
| 1088 if slaves and verbose: | 1105 if slaves and verbose: |
| 1089 output_stream.write(', '.join(slaves)) | 1106 output_stream.write(', '.join(slaves)) |
| 1090 output_stream.write('\n') | 1107 output_stream.write('\n') |
| 1091 return slaves | 1108 return slaves |
| 1092 | 1109 |
| 1093 | 1110 |
| 1094 class PresubmitExecuter(object): | 1111 class PresubmitExecuter(object): |
| 1095 def __init__(self, change, committing, rietveld_obj, verbose): | 1112 def __init__(self, change, committing, rietveld_obj, verbose): |
| 1096 """ | 1113 """ |
| 1097 Args: | 1114 Args: |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1427 except PresubmitFailure, e: | 1444 except PresubmitFailure, e: |
| 1428 print >> sys.stderr, e | 1445 print >> sys.stderr, e |
| 1429 print >> sys.stderr, 'Maybe your depot_tools is out of date?' | 1446 print >> sys.stderr, 'Maybe your depot_tools is out of date?' |
| 1430 print >> sys.stderr, 'If all fails, contact maruel@' | 1447 print >> sys.stderr, 'If all fails, contact maruel@' |
| 1431 return 2 | 1448 return 2 |
| 1432 | 1449 |
| 1433 | 1450 |
| 1434 if __name__ == '__main__': | 1451 if __name__ == '__main__': |
| 1435 fix_encoding.fix_encoding() | 1452 fix_encoding.fix_encoding() |
| 1436 sys.exit(Main(None)) | 1453 sys.exit(Main(None)) |
| OLD | NEW |