diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 56d2714fd..e63b798a3 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -859,9 +859,12 @@ def CheckOwners(input_api, output_api, source_file_filter=None): return [output_api.PresubmitNotifyResult( '--tbr was specified, skipping OWNERS check')] 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( - 'This is a CQ dry run, skipping OWNERS check')] + 'This is a dry run, skipping OWNERS check')] else: return [output_api.PresubmitError("OWNERS check failed: this change has " "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)]) owners_db = input_api.owners_db + # TODO(tandrii): this will always return None, set() in case of Gerrit. owner_email, reviewers = _RietveldOwnerAndReviewers( input_api, owners_db.email_regexp, diff --git a/presubmit_support.py b/presubmit_support.py index 5d80cc551..07cf7b24b 100755 --- a/presubmit_support.py +++ b/presubmit_support.py @@ -265,7 +265,7 @@ class InputApi(object): ) def __init__(self, change, presubmit_path, is_committing, - rietveld_obj, verbose): + rietveld_obj, verbose, dry_run=None): """Builds an InputApi object. Args: @@ -279,6 +279,7 @@ class InputApi(object): self.change = change self.is_committing = is_committing self.rietveld = rietveld_obj + self.dry_run = dry_run # TBD self.host_url = 'http://codereview.chromium.org' if self.rietveld: @@ -1347,7 +1348,8 @@ def DoPostUploadExecuter(change, class PresubmitExecuter(object): - def __init__(self, change, committing, rietveld_obj, verbose): + def __init__(self, change, committing, rietveld_obj, verbose, + dry_run=None): """ Args: change: The Change object. @@ -1358,6 +1360,7 @@ class PresubmitExecuter(object): self.committing = committing self.rietveld = rietveld_obj self.verbose = verbose + self.dry_run = dry_run def ExecPresubmitScript(self, script_text, presubmit_path): """Executes a single presubmit script. @@ -1377,7 +1380,8 @@ class PresubmitExecuter(object): # Load the presubmit script into context. input_api = InputApi(self.change, presubmit_path, self.committing, - self.rietveld, self.verbose) + self.rietveld, self.verbose, + dry_run=self.dry_run) context = {} try: exec script_text in context @@ -1419,7 +1423,8 @@ def DoPresubmitChecks(change, input_stream, default_presubmit, may_prompt, - rietveld_obj): + rietveld_obj, + dry_run=None): """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 @@ -1438,6 +1443,7 @@ def DoPresubmitChecks(change, default_presubmit: A default presubmit script to execute in any case. may_prompt: Enable (y/n) questions on warning or error. rietveld_obj: rietveld.Rietveld object. + dry_run: if true, some Checks will be skipped. Warning: 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: output.write("Warning, no PRESUBMIT.py found.\n") results = [] - executer = PresubmitExecuter(change, committing, rietveld_obj, verbose) + executer = PresubmitExecuter(change, committing, rietveld_obj, verbose, + dry_run=dry_run) if default_presubmit: if verbose: 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 " "presubmit_canned_checks. Can be provided multiple times " "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_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_email", help=optparse.SUPPRESS_HELP) 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): results = DoPresubmitChecks( change_class(options.name, - options.description, - options.root, - files, - options.issue, - options.patchset, - options.author, - upstream=options.upstream), + options.description, + options.root, + files, + options.issue, + options.patchset, + options.author, + upstream=options.upstream), options.commit, options.verbose, sys.stdout, sys.stdin, options.default_presubmit, options.may_prompt, - rietveld_obj) + rietveld_obj, + options.dry_run) return not results.should_continue() except NonexistantCannedCheckFilter, e: print >> sys.stderr, ( diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index 09aeb72ae..ed57ffa05 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -1153,7 +1153,7 @@ def CheckChangeOnCommit(input_api, output_api): presubmit.DoPresubmitChecks(mox.IgnoreArg(), False, False, mox.IgnoreArg(), mox.IgnoreArg(), - None, False, None).AndReturn(output) + None, False, None, None).AndReturn(output) self.mox.ReplayAll() self.assertEquals( @@ -1197,6 +1197,7 @@ class InputApiUnittest(PresubmitTestsBase): 'os_walk', 'os_path', 'os_stat', 'owners_db', 'pickle', 'platform', 'python_executable', 're', 'rietveld', 'subprocess', 'tbr', 'tempfile', 'time', 'traceback', 'unittest', 'urllib2', 'version', 'verbose', + 'dry_run', ] # If this test fails, you should add the relevant test. self.compareMembers( @@ -1853,6 +1854,7 @@ class CannedChecksUnittest(PresubmitTestsBase): input_api.host_url = 'http://localhost' input_api.is_committing = committing input_api.tbr = False + input_api.dry_run = None input_api.python_executable = 'pyyyyython' input_api.platform = sys.platform input_api.cpu_count = 2 @@ -2642,7 +2644,7 @@ class CannedChecksUnittest(PresubmitTestsBase): cq_dry_run=True, rietveld_response=response, 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']), is_committing=False,