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.8.0' | 9 __version__ = '1.8.0' |
10 | 10 |
(...skipping 1125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1136 function_name = 'GetPreferredTryMasters' | 1136 function_name = 'GetPreferredTryMasters' |
1137 if function_name not in context: | 1137 if function_name not in context: |
1138 return {} | 1138 return {} |
1139 get_preferred_try_masters = context[function_name] | 1139 get_preferred_try_masters = context[function_name] |
1140 if not len(inspect.getargspec(get_preferred_try_masters)[0]) == 2: | 1140 if not len(inspect.getargspec(get_preferred_try_masters)[0]) == 2: |
1141 raise PresubmitFailure( | 1141 raise PresubmitFailure( |
1142 'Expected function "GetPreferredTryMasters" to take two arguments.') | 1142 'Expected function "GetPreferredTryMasters" to take two arguments.') |
1143 return get_preferred_try_masters(project, change) | 1143 return get_preferred_try_masters(project, change) |
1144 | 1144 |
1145 | 1145 |
1146 class GetPostUploadExecuter(object): | |
1147 @staticmethod | |
1148 def ExecPresubmitScript(script_text, presubmit_path, cl, change): | |
1149 """Executes PostUploadHook() from a single presubmit script. | |
1150 | |
1151 Args: | |
1152 script_text: The text of the presubmit script. | |
1153 presubmit_path: Project script to run. | |
1154 cl: The Changelist object. | |
1155 change: The Change object. | |
1156 | |
1157 Return: | |
1158 A list of results objects. | |
1159 """ | |
1160 context = {} | |
1161 try: | |
1162 exec script_text in context | |
iannucci
2015/02/25 22:31:04
:(
Though I guess since it's already PRESUBMIT.py
rmistry
2015/02/26 13:28:26
Right, this also follows the same design as GetTry
| |
1163 except Exception, e: | |
1164 raise PresubmitFailure('"%s" had an exception.\n%s' | |
1165 % (presubmit_path, e)) | |
1166 | |
1167 function_name = 'PostUploadHook' | |
1168 if function_name not in context: | |
1169 return {} | |
1170 post_upload_hook = context[function_name] | |
1171 if not len(inspect.getargspec(post_upload_hook)[0]) == 3: | |
1172 raise PresubmitFailure( | |
1173 'Expected function "PostUploadHook" to take three arguments.') | |
1174 return post_upload_hook(cl, change, OutputApi(False)) | |
1175 | |
1176 | |
1146 def DoGetTrySlaves(change, | 1177 def DoGetTrySlaves(change, |
1147 changed_files, | 1178 changed_files, |
1148 repository_root, | 1179 repository_root, |
1149 default_presubmit, | 1180 default_presubmit, |
1150 project, | 1181 project, |
1151 verbose, | 1182 verbose, |
1152 output_stream): | 1183 output_stream): |
1153 """Get the list of try servers from the presubmit scripts (deprecated). | 1184 """Get the list of try servers from the presubmit scripts (deprecated). |
1154 | 1185 |
1155 Args: | 1186 Args: |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1256 # Make sets to lists again for later JSON serialization. | 1287 # Make sets to lists again for later JSON serialization. |
1257 for builders in results.itervalues(): | 1288 for builders in results.itervalues(): |
1258 for builder in builders: | 1289 for builder in builders: |
1259 builders[builder] = list(builders[builder]) | 1290 builders[builder] = list(builders[builder]) |
1260 | 1291 |
1261 if results and verbose: | 1292 if results and verbose: |
1262 output_stream.write('%s\n' % str(results)) | 1293 output_stream.write('%s\n' % str(results)) |
1263 return results | 1294 return results |
1264 | 1295 |
1265 | 1296 |
1297 def DoPostUploadExecuter(change, | |
1298 cl, | |
1299 repository_root, | |
1300 verbose, | |
1301 output_stream): | |
1302 """Execute the post upload hook. | |
1303 | |
1304 Args: | |
1305 change: The Change object. | |
1306 cl: The Changelist object. | |
1307 repository_root: The repository root. | |
1308 verbose: Prints debug info. | |
1309 output_stream: A stream to write debug output to. | |
1310 """ | |
1311 presubmit_files = ListRelevantPresubmitFiles( | |
1312 change.LocalPaths(), repository_root) | |
1313 if not presubmit_files and verbose: | |
1314 output_stream.write("Warning, no PRESUBMIT.py found.\n") | |
1315 results = [] | |
1316 executer = GetPostUploadExecuter() | |
1317 | |
1318 for filename in presubmit_files: | |
iannucci
2015/02/25 22:31:04
is this in general -> specific, or specific -> gen
rmistry
2015/02/26 13:28:26
Thats a good point. It was 1->2. Changed it to 2->
| |
1319 filename = os.path.abspath(filename) | |
1320 if verbose: | |
1321 output_stream.write("Running %s\n" % filename) | |
1322 # Accept CRLF presubmit script. | |
1323 presubmit_script = gclient_utils.FileRead(filename, 'rU') | |
1324 results.extend(executer.ExecPresubmitScript( | |
1325 presubmit_script, filename, cl, change)) | |
1326 output_stream.write('\n') | |
1327 if results: | |
1328 output_stream.write('** Post Upload Hook Messages **\n') | |
1329 for result in results: | |
1330 result.handle(output_stream) | |
1331 output_stream.write('\n') | |
1332 | |
1333 return results | |
1334 | |
1335 | |
1266 class PresubmitExecuter(object): | 1336 class PresubmitExecuter(object): |
1267 def __init__(self, change, committing, rietveld_obj, verbose): | 1337 def __init__(self, change, committing, rietveld_obj, verbose): |
1268 """ | 1338 """ |
1269 Args: | 1339 Args: |
1270 change: The Change object. | 1340 change: The Change object. |
1271 committing: True if 'gcl commit' is running, False if 'gcl upload' is. | 1341 committing: True if 'gcl commit' is running, False if 'gcl upload' is. |
1272 rietveld_obj: rietveld.Rietveld client object. | 1342 rietveld_obj: rietveld.Rietveld client object. |
1273 """ | 1343 """ |
1274 self.change = change | 1344 self.change = change |
1275 self.committing = committing | 1345 self.committing = committing |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1669 except PresubmitFailure, e: | 1739 except PresubmitFailure, e: |
1670 print >> sys.stderr, e | 1740 print >> sys.stderr, e |
1671 print >> sys.stderr, 'Maybe your depot_tools is out of date?' | 1741 print >> sys.stderr, 'Maybe your depot_tools is out of date?' |
1672 print >> sys.stderr, 'If all fails, contact maruel@' | 1742 print >> sys.stderr, 'If all fails, contact maruel@' |
1673 return 2 | 1743 return 2 |
1674 | 1744 |
1675 | 1745 |
1676 if __name__ == '__main__': | 1746 if __name__ == '__main__': |
1677 fix_encoding.fix_encoding() | 1747 fix_encoding.fix_encoding() |
1678 sys.exit(Main(None)) | 1748 sys.exit(Main(None)) |
OLD | NEW |