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
experimental/szager/collated-output
maruel@chromium.org 16 years ago
parent b7d469083f
commit b0dfd35742

@ -728,7 +728,7 @@ def GenerateDiff(files, root=None):
def OptionallyDoPresubmitChecks(change_info, committing, args): def OptionallyDoPresubmitChecks(change_info, committing, args):
if FilterFlag(args, "--no_presubmit") or FilterFlag(args, "--force"): if FilterFlag(args, "--no_presubmit") or FilterFlag(args, "--force"):
return True return True
return DoPresubmitChecks(change_info, committing=committing) return DoPresubmitChecks(change_info, committing, True)
def UploadCL(change_info, args): def UploadCL(change_info, args):
@ -831,10 +831,10 @@ def PresubmitCL(change_info):
return return
print "*** Presubmit checks for UPLOAD would report: ***" 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: ***" print "\n*** Presubmit checks for COMMIT would report: ***"
DoPresubmitChecks(change_info, committing=True) DoPresubmitChecks(change_info, True, False)
def TryChange(change_info, args, swallow_exception): def TryChange(change_info, args, swallow_exception):
@ -1028,17 +1028,18 @@ def Lint(change_info, args):
os.chdir(previous_cwd) os.chdir(previous_cwd)
def DoPresubmitChecks(change_info, committing): def DoPresubmitChecks(change_info, committing, may_prompt):
"""Imports presubmit, then calls presubmit.DoPresubmitChecks.""" """Imports presubmit, then calls presubmit.DoPresubmitChecks."""
# Need to import here to avoid circular dependency. # Need to import here to avoid circular dependency.
import presubmit_support import presubmit_support
root_presubmit = GetCachedFile('PRESUBMIT.py', use_root=True) root_presubmit = GetCachedFile('PRESUBMIT.py', use_root=True)
result = presubmit_support.DoPresubmitChecks(change_info, result = presubmit_support.DoPresubmitChecks(change_info=change_info,
committing, committing=committing,
verbose=False, verbose=False,
output_stream=sys.stdout, output_stream=sys.stdout,
input_stream=sys.stdin, input_stream=sys.stdin,
default_presubmit=root_presubmit) default_presubmit=root_presubmit,
may_prompt=may_prompt)
if not result: if not result:
print "\nPresubmit errors, can't continue (use --no_presubmit to bypass)" print "\nPresubmit errors, can't continue (use --no_presubmit to bypass)"
return result return result

@ -91,7 +91,7 @@ class OutputApi(object):
for item in self._items: for item in self._items:
output_stream.write(' %s\n' % item) output_stream.write(' %s\n' % item)
if self._long_text: if self._long_text:
output_stream.write('\n***************\n%s\n***************\n\n' % output_stream.write('\n***************\n%s\n***************\n' %
self._long_text) self._long_text)
if self.ShouldPrompt() and may_prompt: if self.ShouldPrompt() and may_prompt:
@ -696,7 +696,8 @@ def DoPresubmitChecks(change_info,
verbose, verbose,
output_stream, output_stream,
input_stream, input_stream,
default_presubmit): default_presubmit,
may_prompt):
"""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
@ -713,6 +714,7 @@ def DoPresubmitChecks(change_info,
output_stream: A stream to write output from presubmit tests to. output_stream: A stream to write output from presubmit tests to.
input_stream: A stream to read input from the user. input_stream: A stream to read input from the user.
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.
Return: Return:
True if execution can continue, False if not. True if execution can continue, False if not.
@ -753,7 +755,7 @@ def DoPresubmitChecks(change_info,
('Warnings', warnings), ('Warnings', warnings),
('ERRORS', errors)): ('ERRORS', errors)):
if items: if items:
output_stream.write('\n** Presubmit %s **\n\n' % name) output_stream.write('** Presubmit %s **\n' % name)
for item in items: for item in items:
if not item._Handle(output_stream, input_stream, if not item._Handle(output_stream, input_stream,
may_prompt=False): may_prompt=False):
@ -807,7 +809,8 @@ def Main(argv):
options.verbose, options.verbose,
sys.stdout, sys.stdout,
sys.stdin, sys.stdin,
default_presubmit=None) None,
False)
if __name__ == '__main__': if __name__ == '__main__':

@ -184,7 +184,7 @@ class UploadCLUnittest(GclTestsBase):
self.mox.StubOutWithMock(change_info, 'Save') self.mox.StubOutWithMock(change_info, 'Save')
args = ['--foo=bar'] args = ['--foo=bar']
change_info.Save() 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.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server')
gcl.os.getcwd().AndReturn('somewhere') gcl.os.getcwd().AndReturn('somewhere')
gcl.os.chdir(gcl.GetRepositoryRoot().AndReturn(None)) gcl.os.chdir(gcl.GetRepositoryRoot().AndReturn(None))
@ -205,7 +205,7 @@ class UploadCLUnittest(GclTestsBase):
change_info.Save = self.mox.CreateMockAnything() change_info.Save = self.mox.CreateMockAnything()
args = ['--server=a'] args = ['--server=a']
change_info.Save() 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.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server')
gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile')) gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile'))
gcl.os.write(42, change_info.description) gcl.os.write(42, change_info.description)
@ -229,7 +229,7 @@ class UploadCLUnittest(GclTestsBase):
change_info.Save = self.mox.CreateMockAnything() change_info.Save = self.mox.CreateMockAnything()
args = ['--no-try'] args = ['--no-try']
change_info.Save() 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.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server')
gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile')) gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile'))
gcl.os.write(42, change_info.description) gcl.os.write(42, change_info.description)
@ -253,7 +253,7 @@ class UploadCLUnittest(GclTestsBase):
self.mox.StubOutWithMock(change_info, 'Save') self.mox.StubOutWithMock(change_info, 'Save')
args = [] args = []
change_info.Save() 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.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('my_server')
gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile')) gcl.tempfile.mkstemp(text=True).AndReturn((42, 'descfile'))
gcl.os.write(42, change_info.description) gcl.os.write(42, change_info.description)

@ -350,7 +350,7 @@ class PresubmitUnittest(PresubmitTestsBase):
input = StringIO.StringIO('y\n') input = StringIO.StringIO('y\n')
self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input,
None)) None, False))
self.assertEqual(output.getvalue().count('!!'), 2) self.assertEqual(output.getvalue().count('!!'), 2)
def testDoPresubmitChecksPromptsAfterWarnings(self): def testDoPresubmitChecksPromptsAfterWarnings(self):
@ -379,7 +379,7 @@ class PresubmitUnittest(PresubmitTestsBase):
output = StringIO.StringIO() output = StringIO.StringIO()
input = StringIO.StringIO('n\n') # say no to the warning input = StringIO.StringIO('n\n') # say no to the warning
self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input,
None)) None, False))
self.assertEqual(output.getvalue().count('??'), 2) self.assertEqual(output.getvalue().count('??'), 2)
output = StringIO.StringIO() output = StringIO.StringIO()
@ -389,7 +389,8 @@ class PresubmitUnittest(PresubmitTestsBase):
True, True,
output, output,
input, input,
None)) None,
False))
self.assertEquals(output.getvalue().count('??'), 2) self.assertEquals(output.getvalue().count('??'), 2)
def testDoPresubmitChecksNoWarningPromptIfErrors(self): def testDoPresubmitChecksNoWarningPromptIfErrors(self):
@ -417,7 +418,7 @@ class PresubmitUnittest(PresubmitTestsBase):
output = StringIO.StringIO() output = StringIO.StringIO()
input = StringIO.StringIO() # should be unused input = StringIO.StringIO() # should be unused
self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input,
None)) None, False))
self.assertEqual(output.getvalue().count('??'), 2) self.assertEqual(output.getvalue().count('??'), 2)
self.assertEqual(output.getvalue().count('XX!!XX'), 2) self.assertEqual(output.getvalue().count('XX!!XX'), 2)
self.assertEqual(output.getvalue().count('(y/N)'), 0) self.assertEqual(output.getvalue().count('(y/N)'), 0)
@ -452,7 +453,7 @@ def CheckChangeOnCommit(input_api, output_api):
input = StringIO.StringIO('y\n') input = StringIO.StringIO('y\n')
# Always fail. # Always fail.
self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input, self.failIf(presubmit.DoPresubmitChecks(ci, False, True, output, input,
DEFAULT_SCRIPT)) DEFAULT_SCRIPT, False))
self.assertEquals(output.getvalue().count('!!'), 1) self.assertEquals(output.getvalue().count('!!'), 1)
def testDirectoryHandling(self): def testDirectoryHandling(self):
@ -512,11 +513,11 @@ def CheckChangeOnCommit(input_api, output_api):
output = StringIO.StringIO() output = StringIO.StringIO()
input = StringIO.StringIO('y\n') input = StringIO.StringIO('y\n')
self.failUnless(presubmit.DoPresubmitChecks(change, False, True, output, self.failUnless(presubmit.DoPresubmitChecks(change, False, True, output,
input, DEFAULT_SCRIPT)) input, DEFAULT_SCRIPT, False))
self.assertEquals(output.getvalue(), self.assertEquals(output.getvalue(),
('Warning, no presubmit.py found.\n' ('Warning, no presubmit.py found.\n'
'Running default presubmit script.\n\n' 'Running default presubmit script.\n'
'** Presubmit Messages **\n\n' '** Presubmit Messages **\n'
'http://tracker.com/42\n\n')) 'http://tracker.com/42\n\n'))

Loading…
Cancel
Save