Index: presubmit_support.py |
=================================================================== |
--- presubmit_support.py (revision 102922) |
+++ presubmit_support.py (working copy) |
@@ -16,6 +16,7 @@ |
import cStringIO # Exposed through the API. |
import fnmatch |
import glob |
+import inspect |
import logging |
import marshal # Exposed through the API. |
import optparse |
@@ -875,7 +876,7 @@ |
class GetTrySlavesExecuter(object): |
@staticmethod |
- def ExecPresubmitScript(script_text, presubmit_path, project): |
+ def ExecPresubmitScript(script_text, presubmit_path, project, change): |
"""Executes GetPreferredTrySlaves() from a single presubmit script. |
Args: |
@@ -894,10 +895,14 @@ |
function_name = 'GetPreferredTrySlaves' |
if function_name in context: |
- try: |
- result = eval(function_name + '(' + repr(project) + ')', context) |
- except TypeError: |
- result = eval(function_name + '()', context) |
+ get_preferred_try_slaves = context[function_name] |
+ function_info = inspect.getargspec(get_preferred_try_slaves) |
+ if len(function_info[0]) == 1: |
+ result = get_preferred_try_slaves(project) |
+ elif len(function_info[0]) == 2: |
+ result = get_preferred_try_slaves(project, change) |
+ else: |
+ result = get_preferred_try_slaves() |
if not isinstance(result, types.ListType): |
raise PresubmitFailure( |
'Presubmit functions must return a list, got a %s instead: %s' % |
@@ -913,7 +918,8 @@ |
return result |
-def DoGetTrySlaves(changed_files, |
+def DoGetTrySlaves(change, |
+ changed_files, |
repository_root, |
default_presubmit, |
project, |
@@ -942,7 +948,7 @@ |
output_stream.write("Running default presubmit script.\n") |
fake_path = os.path.join(repository_root, 'PRESUBMIT.py') |
results += executer.ExecPresubmitScript( |
- default_presubmit, fake_path, project) |
+ default_presubmit, fake_path, project, change) |
for filename in presubmit_files: |
filename = os.path.abspath(filename) |
if verbose: |
@@ -950,7 +956,7 @@ |
# Accept CRLF presubmit script. |
presubmit_script = gclient_utils.FileRead(filename, 'rU') |
results += executer.ExecPresubmitScript( |
- presubmit_script, filename, project) |
+ presubmit_script, filename, project, change) |
slaves = list(set(results)) |
if slaves and verbose: |