Commit 662d513f authored by Josip Sokcevic's avatar Josip Sokcevic Committed by LUCI CQ

Remove unused function GetPreferredTryMasters

Only usage was in v8, and that was removed in 2016:
http://crrev/45ec73da150e02fac1fc1dc15e3f14cb5bc2b45f

R=tandrii@chromium.org

Change-Id: I6aebcf1fc0cc29440b0b9c9b45d4e3fc35a38e53
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3214209Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@google.com>
Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
parent 2ae7735d
......@@ -1342,37 +1342,6 @@ def ListRelevantPresubmitFiles(files, root):
return results
class GetTryMastersExecuter(object):
@staticmethod
def ExecPresubmitScript(script_text, presubmit_path, project, change):
"""Executes GetPreferredTryMasters() from a single presubmit script.
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 map of try masters to map of builders to set of tests.
"""
context = {}
try:
exec(compile(script_text, 'PRESUBMIT.py', 'exec', dont_inherit=True),
context)
except Exception as e:
raise PresubmitFailure('"%s" had an exception.\n%s'
% (presubmit_path, e))
function_name = 'GetPreferredTryMasters'
if function_name not in context:
return {}
get_preferred_try_masters = context[function_name]
if not len(inspect.getargspec(get_preferred_try_masters)[0]) == 2:
raise PresubmitFailure(
'Expected function "GetPreferredTryMasters" to take two arguments.')
return get_preferred_try_masters(project, change)
class GetPostUploadExecuter(object):
@staticmethod
def ExecPresubmitScript(script_text, presubmit_path, gerrit_obj, change):
......@@ -1416,57 +1385,6 @@ def _MergeMasters(masters1, masters2):
return result
def DoGetTryMasters(change,
changed_files,
repository_root,
default_presubmit,
project,
verbose,
output_stream):
"""Get the list of try masters from the presubmit scripts.
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:
Map of try masters to map of builders to set of tests.
"""
presubmit_files = ListRelevantPresubmitFiles(changed_files, repository_root)
if not presubmit_files and verbose:
output_stream.write('Warning, no PRESUBMIT.py found.\n')
results = {}
executer = GetTryMastersExecuter()
if default_presubmit:
if verbose:
output_stream.write('Running default presubmit script.\n')
fake_path = os.path.join(repository_root, 'PRESUBMIT.py')
results = _MergeMasters(results, 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 = _MergeMasters(results, executer.ExecPresubmitScript(
presubmit_script, filename, project, change))
# Make sets to lists again for later JSON serialization.
for builders in results.values():
for builder in builders:
builders[builder] = list(builders[builder])
if results and verbose:
output_stream.write('%s\n' % str(results))
return results
def DoPostUploadExecuter(change,
gerrit_obj,
verbose):
......
......@@ -893,27 +893,6 @@ def CheckChangeOnCommit(input_api, output_api):
'on the file to figure out who to ask for help.\n')
self.assertEqual(sys.stdout.getvalue(), text)
def testGetTryMastersExecuter(self):
change = self.ExampleChange(
extra_lines=['STORY=http://tracker.com/42', 'BUG=boo\n'])
executer = presubmit.GetTryMastersExecuter()
self.assertEqual({}, executer.ExecPresubmitScript('', '', '', change))
self.assertEqual({},
executer.ExecPresubmitScript('def foo():\n return\n', '', '', change))
expected_result = {'m1': {'s1': set(['t1', 't2'])},
'm2': {'s1': set(['defaulttests']),
's2': set(['defaulttests'])}}
empty_result1 = {}
empty_result2 = {'m': {}}
space_in_name_result = {'m r': {'s\tv': set(['t1'])}}
for result in (
expected_result, empty_result1, empty_result2, space_in_name_result):
self.assertEqual(
result,
executer.ExecPresubmitScript(
self.presubmit_trymaster % result, '', '', change))
def ExampleChange(self, extra_lines=None):
"""Returns an example Change instance for tests."""
description_lines = [
......@@ -955,44 +934,6 @@ def CheckChangeOnCommit(input_api, output_api):
for permutation in itertools.permutations(parts):
self.assertEqual(expected, functools.reduce(merge, permutation, {}))
def testDoGetTryMasters(self):
root_text = (self.presubmit_trymaster
% '{"t1.cr": {"win": set(["defaulttests"])}}')
linux_text = (self.presubmit_trymaster
% ('{"t1.cr": {"linux1": set(["t1"])},'
' "t2.cr": {"linux2": set(["defaulttests"])}}'))
filename = 'foo.cc'
filename_linux = os.path.join('linux_only', 'penguin.cc')
root_presubmit = os.path.join(self.fake_root_dir, 'PRESUBMIT.py')
linux_presubmit = os.path.join(
self.fake_root_dir, 'linux_only', 'PRESUBMIT.py')
os.path.isfile.side_effect = (
lambda f: f in [root_presubmit, linux_presubmit])
os.listdir.return_value = ['PRESUBMIT.py']
gclient_utils.FileRead.side_effect = (
lambda f, _: root_text if f == root_presubmit else linux_text)
change = presubmit.Change(
'mychange', '', self.fake_root_dir, [], 0, 0, None)
output = StringIO()
self.assertEqual({'t1.cr': {'win': ['defaulttests']}},
presubmit.DoGetTryMasters(change, [filename],
self.fake_root_dir,
None, None, False, output))
output = StringIO()
expected = {
't1.cr': {'win': ['defaulttests'], 'linux1': ['t1']},
't2.cr': {'linux2': ['defaulttests']},
}
self.assertEqual(expected,
presubmit.DoGetTryMasters(change,
[filename, filename_linux],
self.fake_root_dir, None, None,
False, output))
def testMainPostUpload(self):
os.path.isfile.side_effect = lambda f: 'PRESUBMIT.py' in f
os.listdir.return_value = ['PRESUBMIT.py']
......
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