Commit 5ca2762d authored by stip@chromium.org's avatar stip@chromium.org

Allow PRESUBMIT.py files to have old and new-style trybot specifications (as...

Allow PRESUBMIT.py files to have old and new-style trybot specifications (as long as each file is consistent).

BUG=278554

Review URL: https://codereview.chromium.org/74163002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@241590 0039d316-1c4b-4281-b951-d872f2087c98
parent daee1d31
...@@ -1055,6 +1055,22 @@ class GetTrySlavesExecuter(object): ...@@ -1055,6 +1055,22 @@ class GetTrySlavesExecuter(object):
'Do not use \',\' separated builder or test names: %s' % botname) 'Do not use \',\' separated builder or test names: %s' % botname)
else: else:
result = [] 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 return result
...@@ -1083,35 +1099,35 @@ def DoGetTrySlaves(change, ...@@ -1083,35 +1099,35 @@ def DoGetTrySlaves(change,
output_stream.write("Warning, no presubmit.py found.\n") output_stream.write("Warning, no presubmit.py found.\n")
results = [] results = []
executer = GetTrySlavesExecuter() executer = GetTrySlavesExecuter()
if default_presubmit: if default_presubmit:
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( results.extend(executer.ExecPresubmitScript(
default_presubmit, fake_path, project, change) default_presubmit, fake_path, project, change))
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( results.extend(executer.ExecPresubmitScript(
presubmit_script, filename, project, change) presubmit_script, filename, project, change))
if all(isinstance(i, tuple) for i in results):
# New-style [('bot', set(['tests']))] format. slave_dict = {}
slave_dict = {} old_style = filter(lambda x: isinstance(x, basestring), results)
for result in results: new_style = filter(lambda x: isinstance(x, tuple), results)
slave_dict.setdefault(result[0], set()).update(result[1])
slaves = list(slave_dict.iteritems()) for result in new_style:
elif all(isinstance(i, basestring) for i in results): slave_dict.setdefault(result[0], set()).update(result[1])
# Old-style ['bot'] format. slaves = list(slave_dict.items())
slaves = list(set(results))
else: slaves.extend(set(old_style))
raise ValueError('PRESUBMIT.py returned invalid trybot specification!')
if slaves and verbose: if slaves and verbose:
output_stream.write(', '.join(slaves)) output_stream.write(', '.join((str(x) for x in slaves)))
output_stream.write('\n') output_stream.write('\n')
return slaves return slaves
......
...@@ -923,7 +923,11 @@ def CheckChangeOnCommit(input_api, output_api): ...@@ -923,7 +923,11 @@ def CheckChangeOnCommit(input_api, output_api):
starts_with_space_result = [' starts_with_space'] starts_with_space_result = [' starts_with_space']
not_list_result1 = "'foo'" not_list_result1 = "'foo'"
not_list_result2 = "('a', 'tuple')" not_list_result2 = "('a', 'tuple')"
for result in starts_with_space_result, not_list_result1, not_list_result2: mixed_old_and_new = ['bot', ('bot2', set(['test']))]
not_set = [('bot2', ['test'])]
for result in (
starts_with_space_result, not_list_result1, not_list_result2,
mixed_old_and_new, not_set):
self.assertRaises(presubmit.PresubmitFailure, self.assertRaises(presubmit.PresubmitFailure,
executer.ExecPresubmitScript, executer.ExecPresubmitScript,
self.presubmit_tryslave % result, '', '', change) self.presubmit_tryslave % result, '', '', change)
...@@ -932,7 +936,9 @@ def CheckChangeOnCommit(input_api, output_api): ...@@ -932,7 +936,9 @@ def CheckChangeOnCommit(input_api, output_api):
expected_result = ['1', '2', '3'] expected_result = ['1', '2', '3']
empty_result = [] empty_result = []
space_in_name_result = ['foo bar', '1\t2 3'] space_in_name_result = ['foo bar', '1\t2 3']
for result in expected_result, empty_result, space_in_name_result: new_style = [('bot', set(['cool', 'tests']))]
for result in (
expected_result, empty_result, space_in_name_result, new_style):
self.assertEqual( self.assertEqual(
result, result,
executer.ExecPresubmitScript( executer.ExecPresubmitScript(
......
...@@ -381,14 +381,14 @@ def _GenTSBotSpec(checkouts, change, changed_files, options): ...@@ -381,14 +381,14 @@ def _GenTSBotSpec(checkouts, change, changed_files, options):
options.verbose, options.verbose,
sys.stdout) sys.stdout)
if trybots: if trybots:
if isinstance(trybots[0], basestring): old_style = filter(lambda x: isinstance(x, basestring), trybots)
# PRESUBMIT.py sent us an old-style string list of bots. new_style = filter(lambda x: isinstance(x, tuple), trybots)
# _ParseBotList's testfilter is set to None otherwise it will complain.
bot_spec = _ApplyTestFilter(options.testfilter, # _ParseBotList's testfilter is set to None otherwise it will complain.
_ParseBotList(trybots, None)) bot_spec = _ApplyTestFilter(options.testfilter,
else: _ParseBotList(old_style, None))
# PRESUBMIT.py sent us a new-style (bot, set()) specification.
bot_spec = _ApplyTestFilter(options.testfilter, trybots) bot_spec.extend(_ApplyTestFilter(options.testfilter, new_style))
except ImportError: except ImportError:
pass pass
......
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