Add --dry_run to presubmit_support.

Also, implement skipping of CheckOwners presumbit canned check. To be used by run_presubmit recipe in build repo in 
https://codereview.chromium.org/1931633002

R=sergiyb@chromium.org,phajdan.jr@chromium.org,machenbach@chromium.org
BUG=594127

Review-Url: https://codereview.chromium.org/1923623004

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@300262 0039d316-1c4b-4281-b951-d872f2087c98
changes/60/343160/1
tandrii@chromium.org 9 years ago
parent 2b6ed98e7d
commit 57bafac9aa

@ -859,9 +859,12 @@ def CheckOwners(input_api, output_api, source_file_filter=None):
return [output_api.PresubmitNotifyResult( return [output_api.PresubmitNotifyResult(
'--tbr was specified, skipping OWNERS check')] '--tbr was specified, skipping OWNERS check')]
if input_api.change.issue: if input_api.change.issue:
if _GetRietveldIssueProps(input_api, None).get('cq_dry_run', False): if (input_api.dry_run or
# TODO(tandrii): clean below once CQ && run_presubmit.py recipe specify
# dry_run property. http://crbug.com/605563.
_GetRietveldIssueProps(input_api, None).get('cq_dry_run', False)):
return [output_api.PresubmitNotifyResult( return [output_api.PresubmitNotifyResult(
'This is a CQ dry run, skipping OWNERS check')] 'This is a dry run, skipping OWNERS check')]
else: else:
return [output_api.PresubmitError("OWNERS check failed: this change has " return [output_api.PresubmitError("OWNERS check failed: this change has "
"no Rietveld issue number, so we can't check it for approvals.")] "no Rietveld issue number, so we can't check it for approvals.")]
@ -875,6 +878,7 @@ def CheckOwners(input_api, output_api, source_file_filter=None):
input_api.change.AffectedFiles(file_filter=source_file_filter)]) input_api.change.AffectedFiles(file_filter=source_file_filter)])
owners_db = input_api.owners_db owners_db = input_api.owners_db
# TODO(tandrii): this will always return None, set() in case of Gerrit.
owner_email, reviewers = _RietveldOwnerAndReviewers( owner_email, reviewers = _RietveldOwnerAndReviewers(
input_api, input_api,
owners_db.email_regexp, owners_db.email_regexp,

@ -265,7 +265,7 @@ class InputApi(object):
) )
def __init__(self, change, presubmit_path, is_committing, def __init__(self, change, presubmit_path, is_committing,
rietveld_obj, verbose): rietveld_obj, verbose, dry_run=None):
"""Builds an InputApi object. """Builds an InputApi object.
Args: Args:
@ -279,6 +279,7 @@ class InputApi(object):
self.change = change self.change = change
self.is_committing = is_committing self.is_committing = is_committing
self.rietveld = rietveld_obj self.rietveld = rietveld_obj
self.dry_run = dry_run
# TBD # TBD
self.host_url = 'http://codereview.chromium.org' self.host_url = 'http://codereview.chromium.org'
if self.rietveld: if self.rietveld:
@ -1347,7 +1348,8 @@ def DoPostUploadExecuter(change,
class PresubmitExecuter(object): class PresubmitExecuter(object):
def __init__(self, change, committing, rietveld_obj, verbose): def __init__(self, change, committing, rietveld_obj, verbose,
dry_run=None):
""" """
Args: Args:
change: The Change object. change: The Change object.
@ -1358,6 +1360,7 @@ class PresubmitExecuter(object):
self.committing = committing self.committing = committing
self.rietveld = rietveld_obj self.rietveld = rietveld_obj
self.verbose = verbose self.verbose = verbose
self.dry_run = dry_run
def ExecPresubmitScript(self, script_text, presubmit_path): def ExecPresubmitScript(self, script_text, presubmit_path):
"""Executes a single presubmit script. """Executes a single presubmit script.
@ -1377,7 +1380,8 @@ class PresubmitExecuter(object):
# Load the presubmit script into context. # Load the presubmit script into context.
input_api = InputApi(self.change, presubmit_path, self.committing, input_api = InputApi(self.change, presubmit_path, self.committing,
self.rietveld, self.verbose) self.rietveld, self.verbose,
dry_run=self.dry_run)
context = {} context = {}
try: try:
exec script_text in context exec script_text in context
@ -1419,7 +1423,8 @@ def DoPresubmitChecks(change,
input_stream, input_stream,
default_presubmit, default_presubmit,
may_prompt, may_prompt,
rietveld_obj): rietveld_obj,
dry_run=None):
"""Runs all presubmit checks that apply to the files in the change. """Runs all presubmit checks that apply to the files in the change.
This finds all PRESUBMIT.py files in directories enclosing the files in the This finds all PRESUBMIT.py files in directories enclosing the files in the
@ -1438,6 +1443,7 @@ def DoPresubmitChecks(change,
default_presubmit: A default presubmit script to execute in any case. default_presubmit: A default presubmit script to execute in any case.
may_prompt: Enable (y/n) questions on warning or error. may_prompt: Enable (y/n) questions on warning or error.
rietveld_obj: rietveld.Rietveld object. rietveld_obj: rietveld.Rietveld object.
dry_run: if true, some Checks will be skipped.
Warning: Warning:
If may_prompt is true, output_stream SHOULD be sys.stdout and input_stream If may_prompt is true, output_stream SHOULD be sys.stdout and input_stream
@ -1464,7 +1470,8 @@ def DoPresubmitChecks(change,
if not presubmit_files and verbose: if not presubmit_files and verbose:
output.write("Warning, no PRESUBMIT.py found.\n") output.write("Warning, no PRESUBMIT.py found.\n")
results = [] results = []
executer = PresubmitExecuter(change, committing, rietveld_obj, verbose) executer = PresubmitExecuter(change, committing, rietveld_obj, verbose,
dry_run=dry_run)
if default_presubmit: if default_presubmit:
if verbose: if verbose:
output.write("Running default presubmit script.\n") output.write("Running default presubmit script.\n")
@ -1644,8 +1651,11 @@ def main(argv=None):
help="A list of checks to skip which appear in " help="A list of checks to skip which appear in "
"presubmit_canned_checks. Can be provided multiple times " "presubmit_canned_checks. Can be provided multiple times "
"to skip multiple canned checks.") "to skip multiple canned checks.")
parser.add_option("--dry_run", action='store_true',
help=optparse.SUPPRESS_HELP)
parser.add_option("--gerrit_url", help=optparse.SUPPRESS_HELP) parser.add_option("--gerrit_url", help=optparse.SUPPRESS_HELP)
parser.add_option("--gerrit_fetch", help=optparse.SUPPRESS_HELP) parser.add_option("--gerrit_fetch", action='store_true',
help=optparse.SUPPRESS_HELP)
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_fetch", action='store_true', default=False, parser.add_option("--rietveld_fetch", action='store_true', default=False,
@ -1730,20 +1740,21 @@ def main(argv=None):
with canned_check_filter(options.skip_canned): with canned_check_filter(options.skip_canned):
results = DoPresubmitChecks( results = DoPresubmitChecks(
change_class(options.name, change_class(options.name,
options.description, options.description,
options.root, options.root,
files, files,
options.issue, options.issue,
options.patchset, options.patchset,
options.author, options.author,
upstream=options.upstream), upstream=options.upstream),
options.commit, options.commit,
options.verbose, options.verbose,
sys.stdout, sys.stdout,
sys.stdin, sys.stdin,
options.default_presubmit, options.default_presubmit,
options.may_prompt, options.may_prompt,
rietveld_obj) rietveld_obj,
options.dry_run)
return not results.should_continue() return not results.should_continue()
except NonexistantCannedCheckFilter, e: except NonexistantCannedCheckFilter, e:
print >> sys.stderr, ( print >> sys.stderr, (

@ -1153,7 +1153,7 @@ def CheckChangeOnCommit(input_api, output_api):
presubmit.DoPresubmitChecks(mox.IgnoreArg(), False, False, presubmit.DoPresubmitChecks(mox.IgnoreArg(), False, False,
mox.IgnoreArg(), mox.IgnoreArg(),
mox.IgnoreArg(), mox.IgnoreArg(),
None, False, None).AndReturn(output) None, False, None, None).AndReturn(output)
self.mox.ReplayAll() self.mox.ReplayAll()
self.assertEquals( self.assertEquals(
@ -1197,6 +1197,7 @@ class InputApiUnittest(PresubmitTestsBase):
'os_walk', 'os_path', 'os_stat', 'owners_db', 'pickle', 'platform', 'os_walk', 'os_path', 'os_stat', 'owners_db', 'pickle', 'platform',
'python_executable', 're', 'rietveld', 'subprocess', 'tbr', 'tempfile', 'python_executable', 're', 'rietveld', 'subprocess', 'tbr', 'tempfile',
'time', 'traceback', 'unittest', 'urllib2', 'version', 'verbose', 'time', 'traceback', 'unittest', 'urllib2', 'version', 'verbose',
'dry_run',
] ]
# If this test fails, you should add the relevant test. # If this test fails, you should add the relevant test.
self.compareMembers( self.compareMembers(
@ -1853,6 +1854,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
input_api.host_url = 'http://localhost' input_api.host_url = 'http://localhost'
input_api.is_committing = committing input_api.is_committing = committing
input_api.tbr = False input_api.tbr = False
input_api.dry_run = None
input_api.python_executable = 'pyyyyython' input_api.python_executable = 'pyyyyython'
input_api.platform = sys.platform input_api.platform = sys.platform
input_api.cpu_count = 2 input_api.cpu_count = 2
@ -2642,7 +2644,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
cq_dry_run=True, cq_dry_run=True,
rietveld_response=response, rietveld_response=response,
reviewers=set(["ben@example.com"]), reviewers=set(["ben@example.com"]),
expected_output='This is a CQ dry run, skipping OWNERS check\n') expected_output='This is a dry run, skipping OWNERS check\n')
self.AssertOwnersWorks(approvers=set(['ben@example.com']), self.AssertOwnersWorks(approvers=set(['ben@example.com']),
is_committing=False, is_committing=False,

Loading…
Cancel
Save