Commit ecee74ca authored by Aaron Gable's avatar Aaron Gable Committed by Commit Bot

presubmit: don't die when skipping unknown checks

If someone doesn't want to run a check, and that check doesn't
exist... great! We won't be running that check anyway.

R=iannucci

Bug: 770408, 828154
Change-Id: I74478cac9988e21a1fadfb2c9d23dac1697aaa46
Reviewed-on: https://chromium-review.googlesource.com/991093Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@chromium.org>
Reviewed-by: 's avatarSean McCullough <seanmccullough@chromium.org>
Commit-Queue: Aaron Gable <agable@chromium.org>
parent 81b26429
...@@ -1513,17 +1513,14 @@ def load_files(options, args): ...@@ -1513,17 +1513,14 @@ def load_files(options, args):
return change_class, files return change_class, files
class NonexistantCannedCheckFilter(Exception):
pass
@contextlib.contextmanager @contextlib.contextmanager
def canned_check_filter(method_names): def canned_check_filter(method_names):
filtered = {} filtered = {}
try: try:
for method_name in method_names: for method_name in method_names:
if not hasattr(presubmit_canned_checks, method_name): if not hasattr(presubmit_canned_checks, method_name):
raise NonexistantCannedCheckFilter(method_name) logging.warn('Skipping unknown "canned" check %s' % method_name)
continue
filtered[method_name] = getattr(presubmit_canned_checks, method_name) filtered[method_name] = getattr(presubmit_canned_checks, method_name)
setattr(presubmit_canned_checks, method_name, lambda *_a, **_kw: []) setattr(presubmit_canned_checks, method_name, lambda *_a, **_kw: [])
yield yield
...@@ -1692,10 +1689,6 @@ def main(argv=None): ...@@ -1692,10 +1689,6 @@ def main(argv=None):
gerrit_obj, gerrit_obj,
options.dry_run) options.dry_run)
return not results.should_continue() return not results.should_continue()
except NonexistantCannedCheckFilter, e:
print >> sys.stderr, (
'Attempted to skip nonexistent canned presubmit check: %s' % e.message)
return 2
except PresubmitFailure, e: except PresubmitFailure, e:
print >> sys.stderr, e print >> sys.stderr, e
print >> sys.stderr, 'Maybe your depot_tools is out of date?' print >> sys.stderr, 'Maybe your depot_tools is out of date?'
......
...@@ -175,7 +175,7 @@ class PresubmitUnittest(PresubmitTestsBase): ...@@ -175,7 +175,7 @@ class PresubmitUnittest(PresubmitTestsBase):
'AffectedFile', 'Change', 'DoPostUploadExecuter', 'DoPresubmitChecks', 'AffectedFile', 'Change', 'DoPostUploadExecuter', 'DoPresubmitChecks',
'GetPostUploadExecuter', 'GitAffectedFile', 'CallCommand', 'CommandData', 'GetPostUploadExecuter', 'GitAffectedFile', 'CallCommand', 'CommandData',
'GitChange', 'InputApi', 'ListRelevantPresubmitFiles', 'main', 'GitChange', 'InputApi', 'ListRelevantPresubmitFiles', 'main',
'NonexistantCannedCheckFilter', 'OutputApi', 'ParseFiles', 'OutputApi', 'ParseFiles',
'PresubmitFailure', 'PresubmitExecuter', 'PresubmitOutput', 'ScanSubDirs', 'PresubmitFailure', 'PresubmitExecuter', 'PresubmitOutput', 'ScanSubDirs',
'ast', 'auth', 'cPickle', 'cpplint', 'cStringIO', 'contextlib', 'ast', 'auth', 'cPickle', 'cpplint', 'cStringIO', 'contextlib',
'canned_check_filter', 'fix_encoding', 'fnmatch', 'gclient_utils', 'canned_check_filter', 'fix_encoding', 'fnmatch', 'gclient_utils',
...@@ -198,15 +198,6 @@ class PresubmitUnittest(PresubmitTestsBase): ...@@ -198,15 +198,6 @@ class PresubmitUnittest(PresubmitTestsBase):
self.assertEqual(canned.CheckOwners(None, None), []) self.assertEqual(canned.CheckOwners(None, None), [])
self.assertEqual(canned.CheckOwners, orig) self.assertEqual(canned.CheckOwners, orig)
def testCannedCheckFilterFail(self):
canned = presubmit.presubmit_canned_checks
orig = canned.CheckOwners
def failAttempt():
with presubmit.canned_check_filter(['CheckOwners', 'Spazfleem']):
pass
self.assertRaises(presubmit.NonexistantCannedCheckFilter, failAttempt)
self.assertEqual(canned.CheckOwners, orig)
def testListRelevantPresubmitFiles(self): def testListRelevantPresubmitFiles(self):
files = [ files = [
'blat.cc', 'blat.cc',
......
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