Commit dca14bc4 authored by Bruce Dawson's avatar Bruce Dawson Committed by LUCI CQ

Show PresubmitResult call stacks in verbose mode

When a presubmit message, warning, or error strikes it is sometimes due
to a bug or weakness in the presubmit. Examining the presubmit or fixing
it can be important. However it can be hard to find the relevant code
(hint: many presubmits are in depot_tools/presubmit_canned_checks.py).

With this change you can just run the presubmits with -v -v (double
verbose) and a call stack will be recorded when each presubmit result
object is created. For instance:

  >git cl presubmit --force --files ash/public/cpp/app_list/vector_icons/google_black.icon -v -v

  ** Presubmit Messages: 1 **
  Trademarked images should not be added to the public repo. See crbug.com/944754
        ash/public/cpp/app_list/vector_icons/google_black.icon

  ***************
  Presubmit result call stack is:
    File "depot_tools/presubmit_support.py", line 2098, in <module>
      sys.exit(main())
    File "depot_tools/presubmit_support.py", line 2074, in main
      return DoPresubmitChecks(
    File "depot_tools/presubmit_support.py", line 1771, in DoPresubmitChecks
      results += executer.ExecPresubmitScript(presubmit_script, filename)
    File "depot_tools/presubmit_support.py", line 1612, in ExecPresubmitScript
      self._run_check_function(function_name, context, sink,
    File "depot_tools/presubmit_support.py", line 1653, in _run_check_function
      result = eval(function_name + '(*__args)', context)
    File "<string>", line 1, in <module>
    File "chromium/src/PRESUBMIT.py", line 2225, in CheckNoProductIconsAddedToPublicRepo
      message_type(
    File "depot_tools/presubmit_support.py", line 352, in __init__
      self._long_text += ' '.join(traceback.format_stack(None, 8))

This changes tracking down presubmits from a dark art to a trivial operation.

Bug: 1309977
Change-Id: Ia0a6adfbbab04041f97c56cd2064a1627e252561
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3896076Reviewed-by: 's avatarDmitrii Kuragin <kuragin@chromium.org>
Commit-Queue: Dmitrii Kuragin <kuragin@chromium.org>
parent ecfab096
......@@ -65,6 +65,11 @@ else:
# Ask for feedback only once in program lifetime.
_ASKED_FOR_FEEDBACK = False
# Set if super-verbose mode is requested, for tracking where presubmit messages
# are coming from.
_SHOW_CALLSTACKS = False
def time_time():
# Use this so that it can be mocked in tests without interfering with python
# system machinery.
......@@ -342,6 +347,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:
self._long_text += 'Presubmit result call stack is:\n'
self._long_text += ''.join(traceback.format_stack(None, 8))
@staticmethod
def _ensure_str(val):
......@@ -2047,6 +2055,12 @@ def main(argv=None):
'%(filename)s] %(message)s')
logging.basicConfig(format=log_format, level=log_level)
# Print call stacks when _PresubmitResult objects are created with -v -v is
# specified. This helps track down where presubmit messages are coming from.
if options.verbose >= 2:
global _SHOW_CALLSTACKS
_SHOW_CALLSTACKS = True
if options.description_file:
options.description = gclient_utils.FileRead(options.description_file)
gerrit_obj = _parse_gerrit_options(parser, options)
......
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