Commit 78230020 authored by bradnelson@google.com's avatar bradnelson@google.com

Allowing project name to be used to select groups of bots.

BUG=79546
TEST=None
Review URL: http://codereview.chromium.org/7063004

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@86460 0039d316-1c4b-4281-b951-d872f2087c98
parent 711a16a9
...@@ -869,11 +869,13 @@ def ListRelevantPresubmitFiles(files, root): ...@@ -869,11 +869,13 @@ def ListRelevantPresubmitFiles(files, root):
class GetTrySlavesExecuter(object): class GetTrySlavesExecuter(object):
@staticmethod @staticmethod
def ExecPresubmitScript(script_text, presubmit_path): def ExecPresubmitScript(script_text, presubmit_path, project):
"""Executes GetPreferredTrySlaves() from a single presubmit script. """Executes GetPreferredTrySlaves() from a single presubmit script.
Args: Args:
script_text: The text of the presubmit script. script_text: The text of the presubmit script.
presubmit_path: Project script to run.
project: Project name to pass to presubmit script for bot selection.
Return: Return:
A list of try slaves. A list of try slaves.
...@@ -886,7 +888,10 @@ class GetTrySlavesExecuter(object): ...@@ -886,7 +888,10 @@ class GetTrySlavesExecuter(object):
function_name = 'GetPreferredTrySlaves' function_name = 'GetPreferredTrySlaves'
if function_name in context: if function_name in context:
result = eval(function_name + '()', context) try:
result = eval(function_name + '(' + repr(project) + ')', context)
except TypeError:
result = eval(function_name + '()', context)
if not isinstance(result, types.ListType): if not isinstance(result, types.ListType):
raise PresubmitFailure( raise PresubmitFailure(
'Presubmit functions must return a list, got a %s instead: %s' % 'Presubmit functions must return a list, got a %s instead: %s' %
...@@ -905,6 +910,7 @@ class GetTrySlavesExecuter(object): ...@@ -905,6 +910,7 @@ class GetTrySlavesExecuter(object):
def DoGetTrySlaves(changed_files, def DoGetTrySlaves(changed_files,
repository_root, repository_root,
default_presubmit, default_presubmit,
project,
verbose, verbose,
output_stream): output_stream):
"""Get the list of try servers from the presubmit scripts. """Get the list of try servers from the presubmit scripts.
...@@ -913,6 +919,7 @@ def DoGetTrySlaves(changed_files, ...@@ -913,6 +919,7 @@ def DoGetTrySlaves(changed_files,
changed_files: List of modified files. changed_files: List of modified files.
repository_root: The repository root. repository_root: The repository root.
default_presubmit: A default presubmit script to execute in any case. default_presubmit: A default presubmit script to execute in any case.
project: Optional name of a project used in selecting trybots.
verbose: Prints debug info. verbose: Prints debug info.
output_stream: A stream to write debug output to. output_stream: A stream to write debug output to.
...@@ -928,14 +935,16 @@ def DoGetTrySlaves(changed_files, ...@@ -928,14 +935,16 @@ def DoGetTrySlaves(changed_files,
if verbose: if verbose:
output_stream.write("Running default presubmit script.\n") output_stream.write("Running default presubmit script.\n")
fake_path = os.path.join(repository_root, 'PRESUBMIT.py') fake_path = os.path.join(repository_root, 'PRESUBMIT.py')
results += executer.ExecPresubmitScript(default_presubmit, fake_path) results += executer.ExecPresubmitScript(
default_presubmit, fake_path, project)
for filename in presubmit_files: for filename in presubmit_files:
filename = os.path.abspath(filename) filename = os.path.abspath(filename)
if verbose: if verbose:
output_stream.write("Running %s\n" % filename) output_stream.write("Running %s\n" % filename)
# Accept CRLF presubmit script. # Accept CRLF presubmit script.
presubmit_script = gclient_utils.FileRead(filename, 'rU') presubmit_script = gclient_utils.FileRead(filename, 'rU')
results += executer.ExecPresubmitScript(presubmit_script, filename) results += executer.ExecPresubmitScript(
presubmit_script, filename, project)
slaves = list(set(results)) slaves = list(set(results))
if slaves and verbose: if slaves and verbose:
......
...@@ -714,6 +714,7 @@ def TryChange(argv, ...@@ -714,6 +714,7 @@ def TryChange(argv,
checkouts[0].GetFileNames(), checkouts[0].GetFileNames(),
checkouts[0].checkout_root, checkouts[0].checkout_root,
root_presubmit, root_presubmit,
options.project,
False, False,
sys.stdout) sys.stdout)
except ImportError: except ImportError:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment