Commit b0dfd357 authored by maruel@chromium.org's avatar maruel@chromium.org

Make the presubmit output much more compact.

Disable prompting when using gcl presubmit xxx.

TEST=none
BUG=none

Review URL: http://codereview.chromium.org/118498

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@18054 0039d316-1c4b-4281-b951-d872f2087c98
parent b7d46908
......@@ -728,7 +728,7 @@ def GenerateDiff(files, root=None):
def OptionallyDoPresubmitChecks(change_info, committing, args):
if FilterFlag(args, "--no_presubmit") or FilterFlag(args, "--force"):
return True
return DoPresubmitChecks(change_info, committing=committing)
return DoPresubmitChecks(change_info, committing, True)
def UploadCL(change_info, args):
......@@ -831,10 +831,10 @@ def PresubmitCL(change_info):
return
print "*** Presubmit checks for UPLOAD would report: ***"
DoPresubmitChecks(change_info, committing=False)
DoPresubmitChecks(change_info, False, False)
print "\n\n*** Presubmit checks for COMMIT would report: ***"
DoPresubmitChecks(change_info, committing=True)
print "\n*** Presubmit checks for COMMIT would report: ***"
DoPresubmitChecks(change_info, True, False)
def TryChange(change_info, args, swallow_exception):
......@@ -1028,17 +1028,18 @@ def Lint(change_info, args):
os.chdir(previous_cwd)
def DoPresubmitChecks(change_info, committing):
def DoPresubmitChecks(change_info, committing, may_prompt):
"""Imports presubmit, then calls presubmit.DoPresubmitChecks."""
# Need to import here to avoid circular dependency.
import presubmit_support
root_presubmit = GetCachedFile('PRESUBMIT.py', use_root=True)
result = presubmit_support.DoPresubmitChecks(change_info,
committing,
result = presubmit_support.DoPresubmitChecks(change_info=change_info,
committing=committing,
verbose=False,
output_stream=sys.stdout,
input_stream=sys.stdin,
default_presubmit=root_presubmit)
default_presubmit=root_presubmit,
may_prompt=may_prompt)
if not result:
print "\nPresubmit errors, can't continue (use --no_presubmit to bypass)"
return result
......
......@@ -91,7 +91,7 @@ class OutputApi(object):
for item in self._items:
output_stream.write(' %s\n' % item)
if self._long_text:
output_stream.write('\n***************\n%s\n***************\n\n' %
output_stream.write('\n***************\n%s\n***************\n' %
self._long_text)
if self.ShouldPrompt() and may_prompt:
......@@ -696,7 +696,8 @@ def DoPresubmitChecks(change_info,
verbose,
output_stream,
input_stream,
default_presubmit):
default_presubmit,
may_prompt):
"""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
......@@ -713,6 +714,7 @@ def DoPresubmitChecks(change_info,
output_stream: A stream to write output from presubmit tests to.
input_stream: A stream to read input from the user.
default_presubmit: A default presubmit script to execute in any case.
may_prompt: Enable (y/n) questions on warning or error.
Return:
True if execution can continue, False if not.
......@@ -753,7 +755,7 @@ def DoPresubmitChecks(change_info,
('Warnings', warnings),
('ERRORS', errors)):
if items:
output_stream.write('\n** Presubmit %s **\n\n' % name)
output_stream.write('** Presubmit %s **\n' % name)
for item in items:
if not item._Handle(output_stream, input_stream,
may_prompt=False):
......@@ -807,7 +809,8 @@ def Main(argv):
options.verbose,
sys.stdout,
sys.stdin,
default_presubmit=None)
None,
False)
if __name__ == '__main__':
......
......@@ -184,7 +184,7 @@ class UploadCLUnittest(GclTestsBase):
self.mox.StubOutWithMock(change_info, 'Save')
args = ['--foo=bar']
change_info.Save()
gcl.DoPresubmitChecks(change_info, committing=False).AndReturn(True)
gcl.DoPresubmitChecks(change_info, False, True).AndReturn(True)
gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server')
gcl.os.getcwd().AndReturn('somewhere')
gcl.os.chdir(gcl.GetRepositoryRoot().AndReturn(None))
......@@ -205,7 +205,7 @@ class UploadCLUnittest(GclTestsBase):
change_info.Save = self.mox.CreateMockAnything()
args = ['--server=a']
change_info.Save()
gcl.DoPresubmitChecks(change_info, committing=False).AndReturn(True)
gcl.DoPresubmitChecks(change_info, False, True).AndReturn(True)
gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server')
gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile'))
gcl.os.write(42, change_info.description)
......@@ -229,7 +229,7 @@ class UploadCLUnittest(GclTestsBase):
change_info.Save = self.mox.CreateMockAnything()
args = ['--no-try']
change_info.Save()
gcl.DoPresubmitChecks(change_info, committing=False).AndReturn(True)
gcl.DoPresubmitChecks(change_info, False, True).AndReturn(True)
gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server')
gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile'))
gcl.os.write(42, change_info.description)
......@@ -253,7 +253,7 @@ class UploadCLUnittest(GclTestsBase):
self.mox.StubOutWithMock(change_info, 'Save')
args = []
change_info.Save()
gcl.DoPresubmitChecks(change_info, committing=False).AndReturn(True)
gcl.DoPresubmitChecks(change_info, False, True).AndReturn(True)
gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server')
gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile'))
gcl.os.write(42, change_info.description)
......
......@@ -350,7 +350,7 @@ class PresubmitUnittest(PresubmitTestsBase):
input = StringIO.StringIO('y\n')
self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input,
None))
None, False))
self.assertEqual(output.getvalue().count('!!'), 2)
def testDoPresubmitChecksPromptsAfterWarnings(self):
......@@ -379,7 +379,7 @@ class PresubmitUnittest(PresubmitTestsBase):
output = StringIO.StringIO()
input = StringIO.StringIO('n\n') # say no to the warning
self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input,
None))
None, False))
self.assertEqual(output.getvalue().count('??'), 2)
output = StringIO.StringIO()
......@@ -389,7 +389,8 @@ class PresubmitUnittest(PresubmitTestsBase):
True,
output,
input,
None))
None,
False))
self.assertEquals(output.getvalue().count('??'), 2)
def testDoPresubmitChecksNoWarningPromptIfErrors(self):
......@@ -417,7 +418,7 @@ class PresubmitUnittest(PresubmitTestsBase):
output = StringIO.StringIO()
input = StringIO.StringIO() # should be unused
self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input,
None))
None, False))
self.assertEqual(output.getvalue().count('??'), 2)
self.assertEqual(output.getvalue().count('XX!!XX'), 2)
self.assertEqual(output.getvalue().count('(y/N)'), 0)
......@@ -452,7 +453,7 @@ def CheckChangeOnCommit(input_api, output_api):
input = StringIO.StringIO('y\n')
# Always fail.
self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input,
DEFAULT_SCRIPT))
DEFAULT_SCRIPT, False))
self.assertEquals(output.getvalue().count('!!'), 1)
def testDirectoryHandling(self):
......@@ -512,11 +513,11 @@ def CheckChangeOnCommit(input_api, output_api):
output = StringIO.StringIO()
input = StringIO.StringIO('y\n')
self.failUnless(presubmit.DoPresubmitChecks(change, False, True, output,
input, DEFAULT_SCRIPT))
input, DEFAULT_SCRIPT, False))
self.assertEquals(output.getvalue(),
('Warning, no presubmit.py found.\n'
'Running default presubmit script.\n\n'
'** Presubmit Messages **\n\n'
'Running default presubmit script.\n'
'** Presubmit Messages **\n'
'http://tracker.com/42\n\n'))
......
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