Index: presubmit_support.py |
diff --git a/presubmit_support.py b/presubmit_support.py |
index fe3de7b05907f51e080b2093623f0b573c13fc0c..ca54dd14b3de5226e9d56b4c7118ac61d515941c 100755 |
--- a/presubmit_support.py |
+++ b/presubmit_support.py |
@@ -1084,83 +1084,6 @@ def ListRelevantPresubmitFiles(files, root): |
return results |
-class GetTrySlavesExecuter(object): |
- @staticmethod |
- def ExecPresubmitScript(script_text, presubmit_path, project, change): |
- """Executes GetPreferredTrySlaves() from a single presubmit script. |
- |
- This will soon be deprecated and replaced by GetPreferredTryMasters(). |
- |
- Args: |
- 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: |
- A list of try slaves. |
- """ |
- context = {} |
- main_path = os.getcwd() |
- try: |
- os.chdir(os.path.dirname(presubmit_path)) |
- exec script_text in context |
- except Exception, e: |
- raise PresubmitFailure('"%s" had an exception.\n%s' % (presubmit_path, e)) |
- finally: |
- os.chdir(main_path) |
- |
- function_name = 'GetPreferredTrySlaves' |
- if function_name in 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' % |
- (type(result), str(result))) |
- for item in result: |
- if isinstance(item, basestring): |
- # Old-style ['bot'] format. |
- botname = item |
- elif isinstance(item, tuple): |
- # New-style [('bot', set(['tests']))] format. |
- botname = item[0] |
- else: |
- raise PresubmitFailure('PRESUBMIT.py returned invalid tryslave/test' |
- ' format.') |
- |
- if botname != botname.strip(): |
- raise PresubmitFailure( |
- 'Try slave names cannot start/end with whitespace') |
- if ',' in botname: |
- raise PresubmitFailure( |
- 'Do not use \',\' separated builder or test names: %s' % botname) |
- else: |
- result = [] |
- |
- def valid_oldstyle(result): |
- return all(isinstance(i, basestring) for i in result) |
- |
- def valid_newstyle(result): |
- return (all(isinstance(i, tuple) for i in result) and |
- all(len(i) == 2 for i in result) and |
- all(isinstance(i[0], basestring) for i in result) and |
- all(isinstance(i[1], set) for i in result) |
- ) |
- |
- # Ensure it's either all old-style or all new-style. |
- if not valid_oldstyle(result) and not valid_newstyle(result): |
- raise PresubmitFailure( |
- 'PRESUBMIT.py returned invalid trybot specification!') |
- |
- return result |
- |
- |
class GetTryMastersExecuter(object): |
@staticmethod |
def ExecPresubmitScript(script_text, presubmit_path, project, change): |
@@ -1222,64 +1145,6 @@ class GetPostUploadExecuter(object): |
return post_upload_hook(cl, change, OutputApi(False)) |
-def DoGetTrySlaves(change, |
- changed_files, |
- repository_root, |
- default_presubmit, |
- project, |
- verbose, |
- output_stream): |
- """Get the list of try servers from the presubmit scripts (deprecated). |
- |
- Args: |
- changed_files: List of modified files. |
- repository_root: The repository root. |
- 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. |
- output_stream: A stream to write debug output to. |
- |
- Return: |
- List of try slaves |
- """ |
- presubmit_files = ListRelevantPresubmitFiles(changed_files, repository_root) |
- if not presubmit_files and verbose: |
- output_stream.write("Warning, no PRESUBMIT.py found.\n") |
- results = [] |
- executer = GetTrySlavesExecuter() |
- |
- if default_presubmit: |
- if verbose: |
- output_stream.write("Running default presubmit script.\n") |
- fake_path = os.path.join(repository_root, 'PRESUBMIT.py') |
- results.extend(executer.ExecPresubmitScript( |
- default_presubmit, fake_path, project, change)) |
- for filename in presubmit_files: |
- filename = os.path.abspath(filename) |
- if verbose: |
- output_stream.write("Running %s\n" % filename) |
- # Accept CRLF presubmit script. |
- presubmit_script = gclient_utils.FileRead(filename, 'rU') |
- results.extend(executer.ExecPresubmitScript( |
- presubmit_script, filename, project, change)) |
- |
- |
- slave_dict = {} |
- old_style = filter(lambda x: isinstance(x, basestring), results) |
- new_style = filter(lambda x: isinstance(x, tuple), results) |
- |
- for result in new_style: |
- slave_dict.setdefault(result[0], set()).update(result[1]) |
- slaves = list(slave_dict.items()) |
- |
- slaves.extend(set(old_style)) |
- |
- if slaves and verbose: |
- output_stream.write(', '.join((str(x) for x in slaves))) |
- output_stream.write('\n') |
- return slaves |
- |
- |
def _MergeMasters(masters1, masters2): |
"""Merges two master maps. Merges also the tests of each builder.""" |
result = {} |