Commit 8a4a2bc6 authored by iannucci@chromium.org's avatar iannucci@chromium.org

Add skip_canned option to presubmit_support.

This will replace the hack in commit-queue/verification/presubmit_shim, and will
be used on the presubmit trybot.

R=maruel@chromium.org
BUG=

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@186922 0039d316-1c4b-4281-b951-d872f2087c98
parent 4433ad0e
...@@ -14,6 +14,7 @@ __version__ = '1.6.1' ...@@ -14,6 +14,7 @@ __version__ = '1.6.1'
import cPickle # Exposed through the API. import cPickle # Exposed through the API.
import cStringIO # Exposed through the API. import cStringIO # Exposed through the API.
import contextlib
import fnmatch import fnmatch
import glob import glob
import inspect import inspect
...@@ -1198,6 +1199,25 @@ def load_files(options, args): ...@@ -1198,6 +1199,25 @@ def load_files(options, args):
return change_class, files return change_class, files
class NonexistantCannedCheckFilter(Exception):
pass
@contextlib.contextmanager
def canned_check_filter(method_names):
filtered = {}
try:
for method_name in method_names:
if not hasattr(presubmit_canned_checks, method_name):
raise NonexistantCannedCheckFilter(method_name)
filtered[method_name] = getattr(presubmit_canned_checks, method_name)
setattr(presubmit_canned_checks, method_name, lambda *_a, **_kw: [])
yield
finally:
for name, method in filtered.iteritems():
setattr(presubmit_canned_checks, name, method)
def Main(argv): def Main(argv):
parser = optparse.OptionParser(usage="%prog [options] <files...>", parser = optparse.OptionParser(usage="%prog [options] <files...>",
version="%prog " + str(__version__)) version="%prog " + str(__version__))
...@@ -1221,6 +1241,10 @@ def Main(argv): ...@@ -1221,6 +1241,10 @@ def Main(argv):
"system directories will also be searched.") "system directories will also be searched.")
parser.add_option("--default_presubmit") parser.add_option("--default_presubmit")
parser.add_option("--may_prompt", action='store_true', default=False) parser.add_option("--may_prompt", action='store_true', default=False)
parser.add_option("--skip_canned", action='append', default=[],
help="A list of checks to skip which appear in "
"presubmit_canned_checks. Can be provided multiple times "
"to skip multiple canned checks.")
parser.add_option("--rietveld_url", help=optparse.SUPPRESS_HELP) parser.add_option("--rietveld_url", help=optparse.SUPPRESS_HELP)
parser.add_option("--rietveld_email", help=optparse.SUPPRESS_HELP) parser.add_option("--rietveld_email", help=optparse.SUPPRESS_HELP)
parser.add_option("--rietveld_password", help=optparse.SUPPRESS_HELP) parser.add_option("--rietveld_password", help=optparse.SUPPRESS_HELP)
...@@ -1242,22 +1266,27 @@ def Main(argv): ...@@ -1242,22 +1266,27 @@ def Main(argv):
options.rietveld_email, options.rietveld_email,
options.rietveld_password) options.rietveld_password)
try: try:
results = DoPresubmitChecks( with canned_check_filter(options.skip_canned):
change_class(options.name, results = DoPresubmitChecks(
options.description, change_class(options.name,
options.root, options.description,
files, options.root,
options.issue, files,
options.patchset, options.issue,
options.author), options.patchset,
options.commit, options.author),
options.verbose, options.commit,
sys.stdout, options.verbose,
sys.stdin, sys.stdout,
options.default_presubmit, sys.stdin,
options.may_prompt, options.default_presubmit,
rietveld_obj) options.may_prompt,
rietveld_obj)
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?'
......
...@@ -159,11 +159,11 @@ class PresubmitUnittest(PresubmitTestsBase): ...@@ -159,11 +159,11 @@ class PresubmitUnittest(PresubmitTestsBase):
'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks', 'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks',
'GetTrySlavesExecuter', 'GitAffectedFile', 'GetTrySlavesExecuter', 'GitAffectedFile',
'GitChange', 'InputApi', 'ListRelevantPresubmitFiles', 'Main', 'GitChange', 'InputApi', 'ListRelevantPresubmitFiles', 'Main',
'OutputApi', 'ParseFiles', 'PresubmitFailure', 'NonexistantCannedCheckFilter', 'OutputApi', 'ParseFiles',
'PresubmitExecuter', 'PresubmitOutput', 'ScanSubDirs', 'PresubmitFailure', 'PresubmitExecuter', 'PresubmitOutput', 'ScanSubDirs',
'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO', 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO', 'contextlib',
'fix_encoding', 'fnmatch', 'gclient_utils', 'glob', 'inspect', 'json', 'canned_check_filter', 'fix_encoding', 'fnmatch', 'gclient_utils', 'glob',
'load_files', 'inspect', 'json', 'load_files',
'logging', 'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle', 'logging', 'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle',
'presubmit_canned_checks', 'random', 're', 'rietveld', 'scm', 'presubmit_canned_checks', 'random', 're', 'rietveld', 'scm',
'subprocess', 'subprocess',
...@@ -173,6 +173,23 @@ class PresubmitUnittest(PresubmitTestsBase): ...@@ -173,6 +173,23 @@ class PresubmitUnittest(PresubmitTestsBase):
# If this test fails, you should add the relevant test. # If this test fails, you should add the relevant test.
self.compareMembers(presubmit, members) self.compareMembers(presubmit, members)
def testCannedCheckFilter(self):
canned = presubmit.presubmit_canned_checks
orig = canned.CheckOwners
with presubmit.canned_check_filter(['CheckOwners']):
self.assertNotEqual(canned.CheckOwners, orig)
self.assertEqual(canned.CheckOwners(None, None), [])
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):
join = presubmit.os.path.join join = presubmit.os.path.join
files = [ files = [
......
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