From a4b871ebd9d9f96b49c69aabae97080ffb4a55e1 Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Thu, 18 May 2023 14:27:56 +0000 Subject: [PATCH] Disable showing callstacks when running async jobs When using async jobs, information about presubmit is not present in callstack and it's just noise. Change-Id: Ib95af92f9e83f1fb8b8d68c7aece6bbb4b03e61c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4505697 Auto-Submit: Josip Sokcevic Commit-Queue: Gavin Mak Reviewed-by: Gavin Mak --- presubmit_support.py | 24 ++++++++++++++---------- tests/presubmit_unittest.py | 5 ++--- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/presubmit_support.py b/presubmit_support.py index ec246ed26..9061025f1 100755 --- a/presubmit_support.py +++ b/presubmit_support.py @@ -219,7 +219,7 @@ class ThreadPool(object): stdout = 'Process timed out after %ss\n%s' % (self.timeout, stdout) return p.returncode, stdout - def CallCommand(self, test): + def CallCommand(self, test, show_callstack=None): """Runs an external program. This function converts invocation of .py files and invocations of 'python' @@ -233,16 +233,18 @@ class ThreadPool(object): except Exception: duration = time_time() - start return test.message( - '%s\n%s exec failure (%4.2fs)\n%s' % ( - test.name, ' '.join(cmd), duration, traceback.format_exc())) + '%s\n%s exec failure (%4.2fs)\n%s' % + (test.name, ' '.join(cmd), duration, traceback.format_exc()), + show_callstack=show_callstack) if returncode != 0: - return test.message( - '%s\n%s (%4.2fs) failed\n%s' % ( - test.name, ' '.join(cmd), duration, stdout)) + return test.message('%s\n%s (%4.2fs) failed\n%s' % + (test.name, ' '.join(cmd), duration, stdout), + show_callstack=show_callstack) if test.info: - return test.info('%s\n%s (%4.2fs)' % (test.name, ' '.join(cmd), duration)) + return test.info('%s\n%s (%4.2fs)' % (test.name, ' '.join(cmd), duration), + show_callstack=show_callstack) def AddTests(self, tests, parallel=True): if parallel: @@ -260,7 +262,7 @@ class ThreadPool(object): if not self._tests: break test = self._tests.pop() - result = self.CallCommand(test) + result = self.CallCommand(test, show_callstack=False) if result: with self._messages_lock: self._messages.append(result) @@ -317,7 +319,7 @@ class _PresubmitResult(object): fatal = False should_prompt = False - def __init__(self, message, items=None, long_text=''): + def __init__(self, message, items=None, long_text='', show_callstack=None): """ message: A short one-line message to indicate errors. items: A list of short strings to indicate where errors occurred. @@ -326,7 +328,9 @@ class _PresubmitResult(object): self._message = _PresubmitResult._ensure_str(message) self._items = items or [] self._long_text = _PresubmitResult._ensure_str(long_text.rstrip()) - if _SHOW_CALLSTACKS: + if show_callstack is None: + show_callstack = _SHOW_CALLSTACKS + if show_callstack: self._long_text += 'Presubmit result call stack is:\n' self._long_text += ''.join(traceback.format_stack(None, 8)) diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index 8615bc8ef..5f6763623 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -3241,9 +3241,8 @@ class ThreadPoolTest(unittest.TestCase): name=str(i), cmd=[str(i)], kwargs={}, - message=lambda x: x, - ) - for i in range(10) + message=lambda x, **kwargs: x, + ) for i in range(10) ] t = presubmit.ThreadPool(1)